code
This commit is contained in:
@ -156,16 +156,16 @@ func (t CancelOrderByTime) Exec(arg interface{}) error {
|
||||
}
|
||||
limitOrderTimeoutDuration := utility.StringAsInt64(resp.ConfigValue)
|
||||
orders := make([]models.LinePreOrder, 0)
|
||||
err := db.Model(&models.LinePreOrder{}).Where("status = '5' AND main_order_type = 'LIMIT' AND updated_at < ?", time.Now().Add(-time.Duration(limitOrderTimeoutDuration)*time.Second)).Find(&orders).Error
|
||||
err := db.Model(&models.LinePreOrder{}).Where("status = '5' AND main_order_type = 'LIMIT' AND order_type in ('0','4') AND order_category = 3 AND updated_at < ?", time.Now().Add(-time.Duration(limitOrderTimeoutDuration)*time.Second)).Find(&orders).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
spotApi := binanceservice.SpotRestApi{}
|
||||
for _, order := range orders {
|
||||
//现货
|
||||
if order.SymbolType == global.SYMBOL_SPOT {
|
||||
var apiUserinfo models.LineApiUser
|
||||
db.Model(&models.LineApiUser{}).Where("id = ?", order.ApiId).Find(&apiUserinfo)
|
||||
//现货
|
||||
if order.SymbolType == global.SYMBOL_SPOT {
|
||||
if order.ExchangeType == global.EXCHANGE_BINANCE {
|
||||
for i := 0; i < 3; i++ {
|
||||
err := spotApi.CancelOpenOrderByOrderSn(apiUserinfo, order.Symbol, order.OrderSn)
|
||||
@ -177,12 +177,10 @@ func (t CancelOrderByTime) Exec(arg interface{}) error {
|
||||
logger.Error(fmt.Sprintf("取消现货委托失败:order_sn:%s err:%+v", order.OrderSn, err))
|
||||
continue
|
||||
} else {
|
||||
|
||||
newClientOrderId := snowflakehelper.GetOrderId()
|
||||
|
||||
var newOrder models.LinePreOrder
|
||||
copier.Copy(&newOrder, order)
|
||||
|
||||
newOrder.Id = 0
|
||||
newOrder.OrderSn = utility.Int64ToString(newClientOrderId)
|
||||
newOrder.CreatedAt = time.Now()
|
||||
@ -192,7 +190,7 @@ func (t CancelOrderByTime) Exec(arg interface{}) error {
|
||||
logger.Error(fmt.Sprintf("生成新市价单失败 err:%+v", err))
|
||||
continue
|
||||
}
|
||||
err = spotApi.OrderPlace(db, binanceservice.OrderPlacementService{
|
||||
params := binanceservice.OrderPlacementService{
|
||||
ApiId: order.ApiId,
|
||||
Symbol: order.Symbol,
|
||||
Side: order.Site,
|
||||
@ -201,13 +199,18 @@ func (t CancelOrderByTime) Exec(arg interface{}) error {
|
||||
Price: utility.StringToDecimal(order.Price),
|
||||
Quantity: utility.StringToDecimal(order.Num),
|
||||
NewClientOrderId: utility.Int64ToString(newClientOrderId),
|
||||
})
|
||||
if err != nil {
|
||||
}
|
||||
if err := spotApi.OrderPlace(db, params); err != nil {
|
||||
logger.Error(fmt.Sprintf("重新下市价单失败 err:%+v", err))
|
||||
err := db.Model(&models.LinePreOrder{}).Where("id = ? AND status = 0", newOrder.Id).Updates(map[string]interface{}{"status": "2", "desc": err.Error()}).Error
|
||||
|
||||
if err != nil {
|
||||
logger.Error("下单失败后修改订单失败")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -204,11 +204,11 @@ func TestFutOrderPlace(t *testing.T) {
|
||||
Symbol: "ADAUSDT",
|
||||
Side: "SELL",
|
||||
Quantity: decimal.NewFromFloat(8),
|
||||
Price: decimal.NewFromFloat(0.697),
|
||||
Price: decimal.NewFromFloat(0.7012),
|
||||
SideType: "LIMIT",
|
||||
OpenOrder: 0,
|
||||
Profit: decimal.NewFromFloat(0.698),
|
||||
StopPrice: decimal.NewFromFloat(0.698),
|
||||
Profit: decimal.NewFromFloat(0.7017),
|
||||
StopPrice: decimal.NewFromFloat(0.7017),
|
||||
OrderType: "STOP",
|
||||
NewClientOrderId: "5465465784222554477",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user