Merge pull request #1326 from bailantaotao/ediwn/fix-bybit-query-trades

FIX: [bybit] fix bybit query trades
This commit is contained in:
bailantaotao 2023-09-27 15:28:34 +08:00 committed by GitHub
commit d37682e22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -429,34 +429,31 @@ 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. If you want to query for records older than 7 days, options.StartTime is required.
It supports to query records up to 180 days. 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. ** ** Here includes MakerRebate. If needed, let's discuss how to modify it to return in trade. **
** StartTime and EndTime are inclusive. ** ** StartTime and EndTime are inclusive. **
** StartTime and EndTime cannot exceed 180 days. ** ** 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) { 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. // using v3 client, since the v5 API does not support feeCurrency.
req := e.v3client.NewGetTradesRequest() req := e.v3client.NewGetTradesRequest()
req.Symbol(symbol) 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
if options.StartTime != nil { // in `ascending` order. We can use `lastTradeId` to retrieve all the data. So we hack it to '1' if `lastTradeID` is '0'.
req.StartTime(options.StartTime.UTC()) // 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.
if options.EndTime != nil { req.FromTradeId(strconv.FormatUint(options.LastTradeID, 10))
req.EndTime(options.EndTime.UTC()) if options.LastTradeID == 0 {
} req.FromTradeId("1")
} else { }
req.FromTradeId(strconv.FormatUint(options.LastTradeID, 10)) if options.StartTime != nil {
req.StartTime(options.StartTime.UTC())
}
if options.EndTime != nil {
req.EndTime(options.EndTime.UTC())
} }
limit := uint64(options.Limit) limit := uint64(options.Limit)