1
This commit is contained in:
@ -415,6 +415,48 @@ func CheckKlineType(kLineType string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (e FutRestApi) OrderPlaceLoop(db *gorm.DB, params FutOrderPlace, retryCount int) error {
|
||||
var err error
|
||||
err = e.OrderPlace(db, params)
|
||||
if err != nil {
|
||||
//数量不正确
|
||||
if strings.Contains(err.Error(), "LOT_SIZE") {
|
||||
return err
|
||||
}
|
||||
|
||||
for x := 1; x <= retryCount; x++ {
|
||||
err = e.OrderPlace(db, params)
|
||||
if err == nil || strings.Contains(err.Error(), "LOT_SIZE") {
|
||||
break
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 循环平仓
|
||||
func (e FutRestApi) ClosePositionLoop(symbol string, orderSn string, quantity decimal.Decimal, side string, positionSide string,
|
||||
apiUserInfo DbModels.LineApiUser, orderType string, rate string, price decimal.Decimal, retryCount int) error {
|
||||
var err error
|
||||
err = e.ClosePosition(symbol, orderSn, quantity, side, positionSide, apiUserInfo, orderType, rate, price)
|
||||
if err != nil {
|
||||
//数量不正确
|
||||
if strings.Contains(err.Error(), "LOT_SIZE") {
|
||||
return err
|
||||
}
|
||||
|
||||
for x := 1; x <= retryCount; x++ {
|
||||
err = e.ClosePosition(symbol, orderSn, quantity, side, positionSide, apiUserInfo, orderType, rate, price)
|
||||
if err == nil || strings.Contains(err.Error(), "LOT_SIZE") {
|
||||
break
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// OrderPlace 合约下单
|
||||
func (e FutRestApi) OrderPlace(orm *gorm.DB, params FutOrderPlace) error {
|
||||
if orm == nil {
|
||||
@ -447,7 +489,7 @@ func (e FutRestApi) OrderPlace(orm *gorm.DB, params FutOrderPlace) error {
|
||||
paramsMaps["timeInForce"] = "GTC"
|
||||
paramsMaps["price"] = params.Price.String()
|
||||
paramsMaps["stopprice"] = params.Profit.String()
|
||||
paramsMaps["workingType"] = "MARK_PRICE"
|
||||
// paramsMaps["workingType"] = "MARK_PRICE"
|
||||
}
|
||||
|
||||
if strings.ToUpper(params.OrderType) == "STOP_MARKET" {
|
||||
@ -872,13 +914,25 @@ func (e FutRestApi) CoverAccountA(apiUserInfo DbModels.LineApiUser, symbol strin
|
||||
|
||||
// GetFutSymbolLastPrice 获取现货交易对最新价格
|
||||
func (e FutRestApi) GetFutSymbolLastPrice(targetSymbol string) (lastPrice decimal.Decimal) {
|
||||
tickerSymbol := helper.DefaultRedis.Get(rediskey.FutSymbolTicker).Val()
|
||||
tickerSymbolMaps := make([]dto.Ticker, 0)
|
||||
sonic.Unmarshal([]byte(tickerSymbol), &tickerSymbolMaps)
|
||||
for _, symbolMap := range tickerSymbolMaps {
|
||||
if symbolMap.Symbol == strings.ToUpper(targetSymbol) {
|
||||
lastPrice = utility.StringToDecimal(symbolMap.Price)
|
||||
key := fmt.Sprintf(global.TICKER_FUTURES, global.EXCHANGE_BINANCE, targetSymbol)
|
||||
tickerSymbol, _ := helper.DefaultRedis.GetString(key)
|
||||
|
||||
if tickerSymbol != "" {
|
||||
tradeSet := models.TradeSet{}
|
||||
|
||||
sonic.Unmarshal([]byte(tickerSymbol), &tradeSet)
|
||||
|
||||
if tradeSet.LastPrice != "" {
|
||||
lastPrice = utility.StrToDecimal(tradeSet.LastPrice).Truncate(int32(tradeSet.PriceDigit))
|
||||
}
|
||||
}
|
||||
// tickerSymbol := helper.DefaultRedis.Get(rediskey.FutSymbolTicker).Val()
|
||||
// tickerSymbolMaps := make([]dto.Ticker, 0)
|
||||
// sonic.Unmarshal([]byte(tickerSymbol), &tickerSymbolMaps)
|
||||
// for _, symbolMap := range tickerSymbolMaps {
|
||||
// if symbolMap.Symbol == strings.ToUpper(targetSymbol) {
|
||||
// lastPrice = utility.StringToDecimal(symbolMap.Price)
|
||||
// }
|
||||
// }
|
||||
return lastPrice
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user