mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
binance: refactor and update QueryOrderTrades implementation
This commit is contained in:
parent
bc71c95608
commit
901272f153
|
@ -745,6 +745,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
|
||||||
return nil, errors.New("binance: symbol parameter is a mandatory parameter for querying order trades")
|
return nil, errors.New("binance: symbol parameter is a mandatory parameter for querying order trades")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var remoteTrades []binance.TradeV3
|
||||||
var trades []types.Trade
|
var trades []types.Trade
|
||||||
|
|
||||||
if e.IsMargin {
|
if e.IsMargin {
|
||||||
|
@ -755,10 +756,20 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
|
||||||
req.IsIsolated(true)
|
req.IsIsolated(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTrades, err := req.Do(ctx)
|
remoteTrades, err = req.Do(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
req := e.client2.NewGetMyTradesRequest()
|
||||||
|
req.Symbol(q.Symbol).
|
||||||
|
OrderID(uint64(orderID))
|
||||||
|
|
||||||
|
remoteTrades, err = req.Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, t := range remoteTrades {
|
for _, t := range remoteTrades {
|
||||||
localTrade, err := toGlobalTrade(t, e.IsMargin)
|
localTrade, err := toGlobalTrade(t, e.IsMargin)
|
||||||
|
@ -770,25 +781,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
|
||||||
trades = append(trades, *localTrade)
|
trades = append(trades, *localTrade)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
return types.SortTradesAscending(trades), nil
|
||||||
remoteTrades, err := e.client.NewListTradesService().Symbol(q.Symbol).OrderId(orderID).Do(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range remoteTrades {
|
|
||||||
localTrade, err := toGlobalTrade(*t, e.IsMargin)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Errorf("binance: unable to convert trade: %+v", t)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
trades = append(trades, *localTrade)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trades = types.SortTradesAscending(trades)
|
|
||||||
return trades, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) {
|
func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user