maxapi: add deposit request tests and withdrawal request tests

This commit is contained in:
c9s 2022-04-20 14:01:18 +08:00
parent f3eafd5cd8
commit 72ea9f7e24
5 changed files with 74 additions and 34 deletions

View File

@ -794,7 +794,7 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
allDeposits = append(allDeposits, types.Deposit{
Exchange: types.ExchangeMax,
Time: types.Time(time.Unix(d.CreatedAt, 0)),
Amount: fixedpoint.MustNewFromString(d.Amount),
Amount: d.Amount,
Asset: toGlobalCurrency(d.Currency),
Address: "", // not supported
AddressTag: "", // not supported

View File

@ -115,8 +115,8 @@ func (s *AccountService) NewGetMeRequest() *GetMeRequest {
type Deposit struct {
Currency string `json:"currency"`
CurrencyVersion string `json:"currency_version"` // "eth"
Amount string `json:"amount"`
Fee string `json:"fee"`
Amount fixedpoint.Value `json:"amount"`
Fee fixedpoint.Value `json:"fee"`
TxID string `json:"txid"`
State string `json:"state"`
Confirmations int64 `json:"confirmations"`
@ -129,10 +129,10 @@ type GetDepositHistoryRequest struct {
client requestgen.AuthenticatedAPIClient
currency string `param:"currency"`
from int64 `param:"from"` // seconds
to int64 `param:"to"` // seconds
state string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
limit int `param:"limit"`
from *int64 `param:"from"` // seconds
to *int64 `param:"to"` // seconds
state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
limit *int `param:"limit"`
}
func (s *AccountService) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {

View File

@ -90,3 +90,24 @@ func TestAccountService_GetWithdrawHistoryRequest(t *testing.T) {
assert.NotEmpty(t, withdraws)
t.Logf("withdraws: %+v", withdraws)
}
func TestAccountService_NewGetDepositHistoryRequest(t *testing.T) {
key, secret, ok := integrationTestConfigured(t, "MAX")
if !ok {
t.SkipNow()
}
ctx := context.Background()
client := NewRestClient(ProductionAPIURL)
client.Auth(key, secret)
req := client.AccountService.NewGetDepositHistoryRequest()
req.Currency("usdt")
deposits, err := req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, deposits)
assert.NotEmpty(t, deposits)
t.Logf("deposits: %+v", deposits)
}

View File

@ -17,22 +17,22 @@ func (g *GetDepositHistoryRequest) Currency(currency string) *GetDepositHistoryR
}
func (g *GetDepositHistoryRequest) From(from int64) *GetDepositHistoryRequest {
g.from = from
g.from = &from
return g
}
func (g *GetDepositHistoryRequest) To(to int64) *GetDepositHistoryRequest {
g.to = to
g.to = &to
return g
}
func (g *GetDepositHistoryRequest) State(state string) *GetDepositHistoryRequest {
g.state = state
g.state = &state
return g
}
func (g *GetDepositHistoryRequest) Limit(limit int) *GetDepositHistoryRequest {
g.limit = limit
g.limit = &limit
return g
}
@ -57,25 +57,37 @@ func (g *GetDepositHistoryRequest) GetParameters() (map[string]interface{}, erro
// assign parameter of currency
params["currency"] = currency
// check from field -> json key from
from := g.from
if g.from != nil {
from := *g.from
// assign parameter of from
params["from"] = from
} else {
}
// check to field -> json key to
to := g.to
if g.to != nil {
to := *g.to
// assign parameter of to
params["to"] = to
} else {
}
// check state field -> json key state
state := g.state
if g.state != nil {
state := *g.state
// assign parameter of state
params["state"] = state
} else {
}
// check limit field -> json key limit
limit := g.limit
if g.limit != nil {
limit := *g.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
return params, nil
}

View File

@ -42,8 +42,16 @@ func TestOrderService_GetOrdersRequest(t *testing.T) {
// req3.State([]OrderState{OrderStateDone})
req3.Market("btcusdt")
orders, err := req3.Do(ctx)
assert.NoError(t, err)
if assert.NoError(t, err) {
t.Logf("orders: %+v", orders)
assert.NotNil(t, orders)
if assert.NotEmptyf(t, orders, "got %d orders", len(orders)) {
for _, order := range orders {
assert.Contains(t, []OrderState{OrderStateDone, OrderStateFinalizing}, order.State)
}
}
}
}
func TestOrderService_GetOrdersRequest_SingleState(t *testing.T) {
@ -84,7 +92,6 @@ func TestOrderService_GetOrderHistoryRequest(t *testing.T) {
assert.NotNil(t, orders)
}
func TestOrderService(t *testing.T) {
key, secret, ok := integrationTestConfigured(t, "MAX")
if !ok {