1、订单增加策略模板
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go-admin/common/const/rediskey"
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/helper"
|
||||
"go-admin/config"
|
||||
@ -15,6 +16,7 @@ import (
|
||||
"go-admin/models"
|
||||
|
||||
log "github.com/go-admin-team/go-admin-core/logger"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"go.uber.org/zap"
|
||||
@ -133,7 +135,19 @@ func handleTickerAllMessage(msg []byte) {
|
||||
// log.Debug(symbol, "ticker@all ws处理失败", err)
|
||||
continue
|
||||
}
|
||||
tradeSet.LastPrice = utility.StringFloat64Cut(data["c"].(string), int32(tradeSet.PriceDigit))
|
||||
var utcTime int64
|
||||
var lastPrice decimal.Decimal
|
||||
lastPriceKey := fmt.Sprintf(rediskey.FutureTickerLastPrice, global.EXCHANGE_BINANCE, symbol)
|
||||
|
||||
if e, ok := data["E"]; ok {
|
||||
utcTime = utility.ToInt64(e)
|
||||
}
|
||||
|
||||
if e, ok := data["c"]; ok {
|
||||
lastPrice = utility.StrToDecimal(e.(string)).Truncate(int32(tradeSet.PriceDigit))
|
||||
}
|
||||
|
||||
tradeSet.LastPrice = lastPrice.String()
|
||||
tradeSet.OpenPrice = utility.StrToFloatCut(data["o"].(string), int32(tradeSet.PriceDigit))
|
||||
tradeSet.HighPrice = utility.StringFloat64Cut(data["h"].(string), int32(tradeSet.PriceDigit))
|
||||
tradeSet.LowPrice = utility.StringFloat64Cut(data["l"].(string), int32(tradeSet.PriceDigit))
|
||||
@ -147,6 +161,16 @@ func handleTickerAllMessage(msg []byte) {
|
||||
log.Error(symbol, "ticker@all ws处理失败", err)
|
||||
}
|
||||
}
|
||||
|
||||
//行情存储时间
|
||||
lastUtc := utcTime - 1000*60*60
|
||||
if _, err := helper.DefaultRedis.RemoveBeforeScore(lastPriceKey, float64(lastUtc)); err != nil {
|
||||
log.Errorf("移除 合约交易对:%s %d之前的最新成交价失败,err:%v", symbol, lastUtc, err)
|
||||
}
|
||||
|
||||
if err := helper.DefaultRedis.AddSortSet(lastPriceKey, float64(utcTime), lastPrice.String()); err != nil {
|
||||
log.Errorf("添加 合约交易对:%s %d之前的最新成交价失败,err:%v", symbol, lastUtc, err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(trades) > 0 {
|
||||
|
||||
@ -204,6 +204,7 @@ func handleTickerMessage(msg []byte) {
|
||||
}
|
||||
|
||||
key := fmt.Sprintf(global.TICKER_SPOT, global.EXCHANGE_BINANCE, symbolName)
|
||||
lastPriceKey := fmt.Sprintf(rediskey.SpotTickerLastPrice, global.EXCHANGE_BINANCE, symbolName)
|
||||
tcVal, _ := helper.DefaultRedis.GetString(key)
|
||||
tradeSet := models.TradeSet{}
|
||||
if err := sonic.UnmarshalString(tcVal, &tradeSet); err != nil {
|
||||
@ -212,7 +213,19 @@ func handleTickerMessage(msg []byte) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
tradeSet.LastPrice = utility.StringFloat64Cut(dataMap["c"].(string), int32(tradeSet.PriceDigit))
|
||||
|
||||
var utcTime int64
|
||||
var lastPrice decimal.Decimal
|
||||
|
||||
if e, ok := dataMap["E"]; ok {
|
||||
utcTime = utility.ToInt64(e)
|
||||
}
|
||||
|
||||
if e, ok := dataMap["c"]; ok {
|
||||
lastPrice = utility.StrToDecimal(e.(string)).Truncate(int32(tradeSet.PriceDigit))
|
||||
}
|
||||
|
||||
tradeSet.LastPrice = lastPrice.String()
|
||||
tradeSet.OpenPrice = utility.StrToFloatCut(dataMap["o"].(string), int32(tradeSet.PriceDigit))
|
||||
tradeSet.HighPrice = utility.StringFloat64Cut(dataMap["h"].(string), int32(tradeSet.PriceDigit))
|
||||
tradeSet.LowPrice = utility.StringFloat64Cut(dataMap["l"].(string), int32(tradeSet.PriceDigit))
|
||||
@ -236,6 +249,17 @@ func handleTickerMessage(msg []byte) {
|
||||
log.Error("redis保存交易对失败", tradeSet.Coin, tradeSet.Currency)
|
||||
}
|
||||
}
|
||||
|
||||
//行情存储时间
|
||||
lastUtc := utcTime - 1000*60*60
|
||||
|
||||
if _, err := helper.DefaultRedis.RemoveBeforeScore(lastPriceKey, float64(lastUtc)); err != nil {
|
||||
log.Errorf("移除 现货交易对:%s %d之前的最新成交价失败,err:%v", symbolName, lastUtc, err)
|
||||
}
|
||||
|
||||
if err := helper.DefaultRedis.AddSortSet(lastPriceKey, float64(utcTime), lastPrice.String()); err != nil {
|
||||
log.Errorf("添加 现货交易对:%s %d之前的最新成交价失败,err:%v", symbolName, lastUtc, err)
|
||||
}
|
||||
}
|
||||
|
||||
//判断触发现货下单
|
||||
|
||||
Reference in New Issue
Block a user