@@ -780,6 +780,17 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
780
780
return allDeposits , err
781
781
}
782
782
783
+ // QueryTrades
784
+ // For MAX API spec
785
+ // start_time and end_time need to be within 3 days
786
+ // without any parameters -> return trades within 24 hours
787
+ // give start_time or end_time -> ignore parameter from_id
788
+ // give start_time or from_id -> order by time asc
789
+ // give end_time -> order by time desc
790
+ // limit should b1 1~1000
791
+ // For this QueryTrades spec (to be compatible with batch.TradeBatchQuery)
792
+ // give LastTradeID -> ignore start_time (but still can filter the end_time)
793
+ // without any parameters -> return trades within 24 hours
783
794
func (e * Exchange ) QueryTrades (ctx context.Context , symbol string , options * types.TradeQueryOptions ) (trades []types.Trade , err error ) {
784
795
if err := tradeQueryLimiter .Wait (ctx ); err != nil {
785
796
return nil , err
@@ -800,10 +811,28 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
800
811
req .Limit (1000 )
801
812
}
802
813
803
- // MAX uses exclusive last trade ID
804
- // the timestamp parameter is used for reverse order, we can't use it.
814
+ // If we use start_time as parameter, MAX will ignore from_id.
815
+ // However, we want to use from_id as main parameter for batch.TradeBatchQuery
805
816
if options .LastTradeID > 0 {
817
+ // MAX uses inclusive last trade ID
806
818
req .From (options .LastTradeID )
819
+ } else {
820
+ // option's start_time and end_time need to be within 3 days
821
+ // so if the start_time and end_time is over 3 days, we make end_time down to start_time + 3 days
822
+ if options .StartTime != nil && options .EndTime != nil {
823
+ endTime := * options .EndTime
824
+ startTime := * options .StartTime
825
+ if endTime .Sub (startTime ) > 72 * time .Hour {
826
+ startTime := * options .StartTime
827
+ endTime = startTime .Add (72 * time .Hour )
828
+ }
829
+ req .StartTime (startTime )
830
+ req .EndTime (endTime )
831
+ } else if options .StartTime != nil {
832
+ req .StartTime (* options .StartTime )
833
+ } else if options .EndTime != nil {
834
+ req .EndTime (* options .EndTime )
835
+ }
807
836
}
808
837
809
838
maxTrades , err := req .Do (ctx )
0 commit comments