Skip to content

Commit

Permalink
pkg/exchange: add 3 day transaction history api
Browse files Browse the repository at this point in the history
  • Loading branch information
bailantaotao committed Mar 14, 2024
1 parent 747b75f commit 5cb7593
Show file tree
Hide file tree
Showing 7 changed files with 489 additions and 13 deletions.
30 changes: 30 additions & 0 deletions pkg/exchange/okex/okexapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,36 @@ func TestClient_TransactionHistoryWithTime(t *testing.T) {
}
}

func TestClient_ThreeDaysTransactionHistoryWithTime(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()

beforeId := int64(0)
startTime := time.Now().Add(-3 * 24 * time.Hour)
end := time.Now()

for {
// [{"side":"sell","fillSz":"1","fillPx":"46446.4","fillPxVol":"","fillFwdPx":"","fee":"-46.4464","fillPnl":"0","ordId":"665951654130348158","feeRate":"-0.001","instType":"SPOT","fillPxUsd":"","instId":"BTC-USDT","clOrdId":"","posSide":"net","billId":"665951654138736652","fillMarkVol":"","tag":"","fillTime":"1705047247128","execType":"T","fillIdxPx":"","tradeId":"724072849","fillMarkPx":"","feeCcy":"USDT","ts":"1705047247130"}]
// [{"side":"sell","fillSz":"11.053006","fillPx":"54.17","fillPxVol":"","fillFwdPx":"","fee":"-0.59874133502","fillPnl":"0","ordId":"665951812901531754","feeRate":"-0.001","instType":"SPOT","fillPxUsd":"","instId":"OKB-USDT","clOrdId":"","posSide":"net","billId":"665951812905726068","fillMarkVol":"","tag":"","fillTime":"1705047284982","execType":"T","fillIdxPx":"","tradeId":"589438381","fillMarkPx":"","feeCcy":"USDT","ts":"1705047284983"}]
// [{"side":"sell","fillSz":"88.946994","filollPx":"54.16","fillPxVol":"","fillFwdPx":"","fee":"-4.81736919504","fillPnl":"0","ordId":"665951812901531754","feeRate":"-0.001","instType":"SPOT","fillPxUsd":"","instId":"OKB-USDT","clOrdId":"","posSide":"net","billId":"665951812905726084","fillMarkVol":"","tag":"","fillTime":"1705047284982","execType":"T","fillIdxPx":"","tradeId":"589438382","fillMarkPx":"","feeCcy":"USDT","ts":"1705047284983"}]
c := client.NewGetThreeDaysTransactionHistoryRequest().
StartTime(types.NewMillisecondTimestampFromInt(startTime.UnixMilli()).Time()).
EndTime(types.NewMillisecondTimestampFromInt(end.UnixMilli()).Time()).
Limit(1)
if beforeId != 0 {
c.Before(strconv.FormatInt(beforeId, 10))
}
res, err := c.Do(ctx)
assert.NoError(t, err)

if len(res) != 1 {
break
}
t.Log(res[0].FillTime, res[0].Timestamp, res[0].BillId, res)
beforeId = int64(res[0].BillId)
}
}

func TestClient_BatchCancelOrderRequest(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package okexapi

import (
"time"

"github.com/c9s/requestgen"
)

//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data

//go:generate GetRequest -url "/api/v5/trade/fills" -type GetThreeDaysTransactionHistoryRequest -responseDataType []Trade -rateLimiter 1+60/2s
type GetThreeDaysTransactionHistoryRequest struct {
client requestgen.AuthenticatedAPIClient

instrumentType InstrumentType `param:"instType,query"`
instrumentID *string `param:"instId,query"`
orderID *string `param:"ordId,query"`

underlying *string `param:"uly,query"`
instrumentFamily *string `param:"instFamily,query"`

after *string `param:"after,query"`
before *string `param:"before,query"`
startTime *time.Time `param:"begin,query,milliseconds"`

// endTime for each request, startTime and endTime can be any interval, but should be in last 3 months
endTime *time.Time `param:"end,query,milliseconds"`

// limit for data size per page. Default: 100
limit *uint64 `param:"limit,query"`
}

func (c *RestClient) NewGetThreeDaysTransactionHistoryRequest() *GetThreeDaysTransactionHistoryRequest {
return &GetThreeDaysTransactionHistoryRequest{
client: c,
instrumentType: InstrumentTypeSpot,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5cb7593

Please sign in to comment.