init code
This commit is contained in:
52
internal/services/controllers/market.go
Normal file
52
internal/services/controllers/market.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"me.thuanle/bbot/internal/configs/strategy"
|
||||
"me.thuanle/bbot/internal/data"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// GetTopPrices returns the top symbol, price and rate
|
||||
func GetTopPrices() ([]string, []float64, []float64) {
|
||||
n := len(strategy.TopPriceSymbols)
|
||||
topSym := make([]string, n)
|
||||
topPrice := make([]float64, n)
|
||||
topRate := make([]float64, n)
|
||||
|
||||
for i, sym := range strategy.TopPriceSymbols {
|
||||
price, rate, _, ok := data.Market.GetFuturePrice(sym)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
topSym[i] = sym
|
||||
topPrice[i] = price
|
||||
topRate[i] = rate
|
||||
|
||||
}
|
||||
return topSym, topPrice, topRate
|
||||
}
|
||||
|
||||
// GetTopFundingFee returns the top funding fee: symbol, rate and cd time
|
||||
func GetTopFundingFee() ([]string, []float64, []int64) {
|
||||
allRates, allCd := data.Market.GetAllFundRate()
|
||||
var resSym []string
|
||||
for sym, rate := range allRates {
|
||||
if strategy.FundRateBuyThreshold < rate && rate < strategy.FundRateSellThreshold {
|
||||
continue
|
||||
}
|
||||
|
||||
resSym = append(resSym, sym)
|
||||
}
|
||||
|
||||
sort.Slice(resSym, func(i, j int) bool {
|
||||
return allRates[resSym[i]] < allRates[resSym[j]]
|
||||
})
|
||||
|
||||
resRate := make([]float64, len(resSym))
|
||||
resCd := make([]int64, len(resSym))
|
||||
for i, sym := range resSym {
|
||||
resRate[i] = allRates[sym]
|
||||
resCd[i] = allCd[sym]
|
||||
}
|
||||
return resSym, resRate, resCd
|
||||
}
|
||||
Reference in New Issue
Block a user