mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1326 from bailantaotao/ediwn/fix-bybit-query-trades
FIX: [bybit] fix bybit query trades
This commit is contained in:
commit
d37682e22c
|
@ -429,35 +429,32 @@ If options.StartTime is not specified, you can only query for records in the las
|
|||
If you want to query for records older than 7 days, options.StartTime is required.
|
||||
It supports to query records up to 180 days.
|
||||
|
||||
If the orderId is null, fromTradeId is passed, and toTradeId is null, then the result is sorted by
|
||||
ticketId in ascend. Otherwise, the result is sorted by ticketId in descend.
|
||||
|
||||
** Here includes MakerRebate. If needed, let's discuss how to modify it to return in trade. **
|
||||
** StartTime and EndTime are inclusive. **
|
||||
** StartTime and EndTime cannot exceed 180 days. **
|
||||
** StartTime, EndTime, FromTradeId can be used together. **
|
||||
** If the `FromTradeId` is passed, and `ToTradeId` is null, then the result is sorted by tradeId in `ascend`.
|
||||
Otherwise, the result is sorted by tradeId in `descend`. **
|
||||
*/
|
||||
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error) {
|
||||
if options.StartTime != nil && options.EndTime != nil && options.EndTime.Sub(*options.StartTime) > halfYearDuration {
|
||||
return nil, fmt.Errorf("StartTime and EndTime cannot exceed 180 days, startTime: %v, endTime: %v, diff: %v",
|
||||
options.StartTime.String(),
|
||||
options.EndTime.String(),
|
||||
options.EndTime.Sub(*options.StartTime)/24)
|
||||
}
|
||||
|
||||
// using v3 client, since the v5 API does not support feeCurrency.
|
||||
req := e.v3client.NewGetTradesRequest()
|
||||
req.Symbol(symbol)
|
||||
|
||||
if options.StartTime != nil || options.EndTime != nil {
|
||||
// If `lastTradeId` is given and greater than 0, the query will use it as a condition and the retrieved result will be
|
||||
// in `ascending` order. We can use `lastTradeId` to retrieve all the data. So we hack it to '1' if `lastTradeID` is '0'.
|
||||
// If 0 is given, it will not be used as a condition and the result will be in `descending` order. The FromTradeId
|
||||
// option cannot be used to retrieve more data.
|
||||
req.FromTradeId(strconv.FormatUint(options.LastTradeID, 10))
|
||||
if options.LastTradeID == 0 {
|
||||
req.FromTradeId("1")
|
||||
}
|
||||
if options.StartTime != nil {
|
||||
req.StartTime(options.StartTime.UTC())
|
||||
}
|
||||
if options.EndTime != nil {
|
||||
req.EndTime(options.EndTime.UTC())
|
||||
}
|
||||
} else {
|
||||
req.FromTradeId(strconv.FormatUint(options.LastTradeID, 10))
|
||||
}
|
||||
|
||||
limit := uint64(options.Limit)
|
||||
if limit > defaultQueryLimit || limit <= 0 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user