mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
refactor and clean up withdraw history query method
This commit is contained in:
parent
e5ca6504f5
commit
c0f5c1963e
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=TransferType
|
||||
// 1 for internal transfer, 0 for external transfer
|
||||
type TransferType int
|
||||
|
||||
|
@ -22,16 +23,17 @@ type WithdrawRecord struct {
|
|||
Amount fixedpoint.Value `json:"amount"`
|
||||
ApplyTime string `json:"applyTime"`
|
||||
Coin string `json:"coin"`
|
||||
WithdrawOrderId string `json:"withdrawOrderId"`
|
||||
WithdrawOrderID string `json:"withdrawOrderId"`
|
||||
Network string `json:"network"`
|
||||
TransferType TransferType `json:"transferType"`
|
||||
Status WithdrawStatus `json:"status"`
|
||||
TransactionFee fixedpoint.Value `json:"transactionFee"`
|
||||
ConfirmNo int `json:"confirmNo"`
|
||||
Info string `json:"info"`
|
||||
TxId string `json:"txId"`
|
||||
TxID string `json:"txId"`
|
||||
}
|
||||
|
||||
//go:generate stringer -type=WithdrawStatus
|
||||
type WithdrawStatus int
|
||||
|
||||
// WithdrawStatus: 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6:Completed)
|
||||
|
@ -45,7 +47,7 @@ const (
|
|||
WithdrawStatusCompleted
|
||||
)
|
||||
|
||||
//go:generate requestgen -method POST -url "/sapi/v1/capital/withdraw/history" -type GetWithdrawHistoryRequest -responseType .WithdrawRecord
|
||||
//go:generate requestgen -method POST -url "/sapi/v1/capital/withdraw/history" -type GetWithdrawHistoryRequest -responseType []WithdrawRecord
|
||||
type GetWithdrawHistoryRequest struct {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
coin string `param:"coin"`
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "requestgen -method POST -url /sapi/v1/capital/withdraw/history -type GetWithdrawHistoryRequest -responseType .WithdrawRecord"; DO NOT EDIT.
|
||||
// Code generated by "requestgen -method POST -url /sapi/v1/capital/withdraw/history -type GetWithdrawHistoryRequest -responseType []WithdrawRecord"; DO NOT EDIT.
|
||||
|
||||
package binanceapi
|
||||
|
||||
|
@ -212,7 +212,7 @@ func (g *GetWithdrawHistoryRequest) GetSlugsMap() (map[string]string, error) {
|
|||
return slugs, nil
|
||||
}
|
||||
|
||||
func (g *GetWithdrawHistoryRequest) Do(ctx context.Context) (*WithdrawRecord, error) {
|
||||
func (g *GetWithdrawHistoryRequest) Do(ctx context.Context) ([]WithdrawRecord, error) {
|
||||
|
||||
params, err := g.GetParameters()
|
||||
if err != nil {
|
||||
|
@ -232,9 +232,9 @@ func (g *GetWithdrawHistoryRequest) Do(ctx context.Context) (*WithdrawRecord, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var apiResponse WithdrawRecord
|
||||
var apiResponse []WithdrawRecord
|
||||
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &apiResponse, nil
|
||||
return apiResponse, nil
|
||||
}
|
||||
|
|
24
pkg/exchange/binance/binanceapi/transfertype_string.go
Normal file
24
pkg/exchange/binance/binanceapi/transfertype_string.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Code generated by "stringer -type=TransferType"; DO NOT EDIT.
|
||||
|
||||
package binanceapi
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[TransferTypeInternal-0]
|
||||
_ = x[TransferTypeExternal-0]
|
||||
}
|
||||
|
||||
const _TransferType_name = "TransferTypeInternal"
|
||||
|
||||
var _TransferType_index = [...]uint8{0, 20}
|
||||
|
||||
func (i TransferType) String() string {
|
||||
if i < 0 || i >= TransferType(len(_TransferType_index)-1) {
|
||||
return "TransferType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _TransferType_name[_TransferType_index[i]:_TransferType_index[i+1]]
|
||||
}
|
29
pkg/exchange/binance/binanceapi/withdrawstatus_string.go
Normal file
29
pkg/exchange/binance/binanceapi/withdrawstatus_string.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Code generated by "stringer -type=WithdrawStatus"; DO NOT EDIT.
|
||||
|
||||
package binanceapi
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[WithdrawStatusEmailSent-0]
|
||||
_ = x[WithdrawStatusCancelled-1]
|
||||
_ = x[WithdrawStatusAwaitingApproval-2]
|
||||
_ = x[WithdrawStatusRejected-3]
|
||||
_ = x[WithdrawStatusProcessing-4]
|
||||
_ = x[WithdrawStatusFailure-5]
|
||||
_ = x[WithdrawStatusCompleted-6]
|
||||
}
|
||||
|
||||
const _WithdrawStatus_name = "WithdrawStatusEmailSentWithdrawStatusCancelledWithdrawStatusAwaitingApprovalWithdrawStatusRejectedWithdrawStatusProcessingWithdrawStatusFailureWithdrawStatusCompleted"
|
||||
|
||||
var _WithdrawStatus_index = [...]uint8{0, 23, 46, 76, 98, 122, 143, 166}
|
||||
|
||||
func (i WithdrawStatus) String() string {
|
||||
if i < 0 || i >= WithdrawStatus(len(_WithdrawStatus_index)-1) {
|
||||
return "WithdrawStatus(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _WithdrawStatus_name[_WithdrawStatus_index[i]:_WithdrawStatus_index[i+1]]
|
||||
}
|
|
@ -426,12 +426,12 @@ func (e *Exchange) Withdrawal(ctx context.Context, asset string, amount fixedpoi
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (allWithdraws []types.Withdraw, err error) {
|
||||
func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (withdraws []types.Withdraw, err error) {
|
||||
var emptyTime = time.Time{}
|
||||
if since == emptyTime {
|
||||
since, err = getLaunchDate()
|
||||
if err != nil {
|
||||
return allWithdraws, err
|
||||
return withdraws, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,63 +441,43 @@ func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since
|
|||
until = since.Add(historyDayRangeLimit)
|
||||
}
|
||||
|
||||
req := e.client.NewListWithdrawsService()
|
||||
req := e.client2.NewGetWithdrawHistoryRequest()
|
||||
if len(asset) > 0 {
|
||||
req.Coin(asset)
|
||||
}
|
||||
|
||||
withdraws, err := req.
|
||||
StartTime(since.UnixMilli()).
|
||||
EndTime(until.UnixMilli()).
|
||||
records, err := req.
|
||||
StartTime(since).
|
||||
EndTime(until).
|
||||
Limit(1000).
|
||||
Do(ctx)
|
||||
|
||||
if err != nil {
|
||||
return allWithdraws, err
|
||||
return withdraws, err
|
||||
}
|
||||
|
||||
for _, d := range withdraws {
|
||||
status := ""
|
||||
switch d.Status {
|
||||
case 0:
|
||||
status = "email_sent"
|
||||
case 1:
|
||||
status = "cancelled"
|
||||
case 2:
|
||||
status = "awaiting_approval"
|
||||
case 3:
|
||||
status = "rejected"
|
||||
case 4:
|
||||
status = "processing"
|
||||
case 5:
|
||||
status = "failure"
|
||||
case 6:
|
||||
status = "completed"
|
||||
|
||||
default:
|
||||
status = fmt.Sprintf("unsupported code: %d", d.Status)
|
||||
}
|
||||
|
||||
// 2006-01-02 15:04:05
|
||||
for _, d := range records {
|
||||
// time format: 2006-01-02 15:04:05
|
||||
applyTime, err := time.Parse("2006-01-02 15:04:05", d.ApplyTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allWithdraws = append(allWithdraws, types.Withdraw{
|
||||
withdraws = append(withdraws, types.Withdraw{
|
||||
Exchange: types.ExchangeBinance,
|
||||
ApplyTime: types.Time(applyTime),
|
||||
Asset: d.Coin,
|
||||
Amount: fixedpoint.MustNewFromString(d.Amount),
|
||||
Amount: d.Amount,
|
||||
Address: d.Address,
|
||||
TransactionID: d.TxID,
|
||||
TransactionFee: fixedpoint.MustNewFromString(d.TransactionFee),
|
||||
TransactionFee: d.TransactionFee,
|
||||
WithdrawOrderID: d.WithdrawOrderID,
|
||||
Network: d.Network,
|
||||
Status: status,
|
||||
Status: d.Status.String(),
|
||||
})
|
||||
}
|
||||
|
||||
return allWithdraws, nil
|
||||
return withdraws, nil
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []types.Deposit, err error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user