Skip to content

Commit

Permalink
okx: implement QueryDepositHistory method
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 23, 2025
1 parent b60fc3a commit cf154aa
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/exchange/okex/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,71 @@ func toGlobalMarginRepay(record okexapi.MarginHistoryEntry) types.MarginRepay {
IsolatedSymbol: "",
}
}

// DepositRecord.state represents the deposit state
/*
Status of deposit
0: Waiting for confirmation
1: Deposit credited
2: Deposit successful
8: Pending due to temporary deposit suspension on this crypto currency
11: Match the address blacklist
12: Account or deposit is frozen
13: Sub-account deposit interception
14: KYC limit
*/
func toDepositStatusMessage(state types.StrInt64) string {
switch state {
case 0:
return "Waiting for confirmation"
case 1:
return "Deposit credited"
case 2:
return "Deposit successful"
case 8:
return "Pending due to temporary deposit suspension on this crypto currency"
case 11:
return "Match the address blacklist"
case 12:
return "Account or deposit is frozen"
case 13:
return "Sub-account deposit interception"
case 14:
return "KYC limit"
}

return ""
}

func toGlobalDepositStatus(state types.StrInt64) types.DepositStatus {
switch state {
case 0:
return types.DepositPending
case 1:
return types.DepositCredited
case 2:
return types.DepositSuccess
case 8:
return types.DepositPending
default:
return types.DepositRejected
}
}

func toGlobalDeposit(record okexapi.DepositRecord) types.Deposit {
return types.Deposit{
Exchange: types.ExchangeOKEx,
Time: types.Time(record.Ts),
Amount: record.Amount,
Asset: record.Currency,
Address: record.From,
AddressTag: "",
TransactionID: record.DepId,
Status: toGlobalDepositStatus(record.State),
RawStatus: record.State.String(),
UnlockConfirm: 0,
Confirmation: record.ActualDepBlkConfirm.String(),
Network: strings.ToUpper(record.Chain),
}

}
22 changes: 22 additions & 0 deletions pkg/exchange/okex/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,28 @@ func (e *Exchange) QueryInterestHistory(ctx context.Context, asset string, start
return nil, nil
}

func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, startTime, endTime *time.Time) ([]types.Deposit, error) {
req := e.client.NewGetAssetDepositHistoryRequest().Currency(asset)
if endTime != nil {
req.Before(*endTime)
}
if startTime != nil {
req.After(*startTime)
}

resp, err := req.Do(ctx)
if err != nil {
return nil, err
}

var records []types.Deposit
for _, r := range resp {
records = append(records, toGlobalDeposit(r))
}

return records, nil
}

/*
QueryTrades can query trades in last 3 months, there are no time interval limitations, as long as end_time >= start_time.
okx does not provide an API to query by trade ID, so we use the bill ID to do it. The trades result is ordered by timestamp.
Expand Down
46 changes: 46 additions & 0 deletions pkg/exchange/okex/okexapi/get_asset_deposit_history_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package okexapi

import (
"time"

"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)

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

type DepositRecord struct {
ActualDepBlkConfirm types.StrInt64 `json:"actualDepBlkConfirm"`
Amount fixedpoint.Value `json:"amt"`
AreaCodeFrom string `json:"areaCodeFrom"`
Currency string `json:"ccy"`
Chain string `json:"chain"`
DepId string `json:"depId"`
From string `json:"from"`
FromWdId string `json:"fromWdId"`
State types.StrInt64 `json:"state"`
To string `json:"to"`

Ts types.MillisecondTimestamp `json:"ts"`

TxId string `json:"txId"`
}

//go:generate GetRequest -url "/api/v5/asset/deposit-history" -type GetAssetDepositHistoryRequest -responseDataType []DepositRecord
type GetAssetDepositHistoryRequest struct {
client requestgen.AuthenticatedAPIClient

currency *string `param:"ccy"`
after *time.Time `param:"after,milliseconds"`
before *time.Time `param:"before,milliseconds"`
limit *uint64 `param:"limit" defaultValue:"100"`
}

func (c *RestClient) NewGetAssetDepositHistoryRequest() *GetAssetDepositHistoryRequest {
return &GetAssetDepositHistoryRequest{
client: c,
}
}

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

0 comments on commit cf154aa

Please sign in to comment.