mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
maxapi: add deposit request tests and withdrawal request tests
This commit is contained in:
parent
f3eafd5cd8
commit
72ea9f7e24
|
@ -794,7 +794,7 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
|
||||||
allDeposits = append(allDeposits, types.Deposit{
|
allDeposits = append(allDeposits, types.Deposit{
|
||||||
Exchange: types.ExchangeMax,
|
Exchange: types.ExchangeMax,
|
||||||
Time: types.Time(time.Unix(d.CreatedAt, 0)),
|
Time: types.Time(time.Unix(d.CreatedAt, 0)),
|
||||||
Amount: fixedpoint.MustNewFromString(d.Amount),
|
Amount: d.Amount,
|
||||||
Asset: toGlobalCurrency(d.Currency),
|
Asset: toGlobalCurrency(d.Currency),
|
||||||
Address: "", // not supported
|
Address: "", // not supported
|
||||||
AddressTag: "", // not supported
|
AddressTag: "", // not supported
|
||||||
|
|
|
@ -113,26 +113,26 @@ func (s *AccountService) NewGetMeRequest() *GetMeRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deposit struct {
|
type Deposit struct {
|
||||||
Currency string `json:"currency"`
|
Currency string `json:"currency"`
|
||||||
CurrencyVersion string `json:"currency_version"` // "eth"
|
CurrencyVersion string `json:"currency_version"` // "eth"
|
||||||
Amount string `json:"amount"`
|
Amount fixedpoint.Value `json:"amount"`
|
||||||
Fee string `json:"fee"`
|
Fee fixedpoint.Value `json:"fee"`
|
||||||
TxID string `json:"txid"`
|
TxID string `json:"txid"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Confirmations int64 `json:"confirmations"`
|
Confirmations int64 `json:"confirmations"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate GetRequest -url "v2/deposits" -type GetDepositHistoryRequest -responseType []Deposit
|
//go:generate GetRequest -url "v2/deposits" -type GetDepositHistoryRequest -responseType []Deposit
|
||||||
type GetDepositHistoryRequest struct {
|
type GetDepositHistoryRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.AuthenticatedAPIClient
|
||||||
|
|
||||||
currency string `param:"currency"`
|
currency string `param:"currency"`
|
||||||
from int64 `param:"from"` // seconds
|
from *int64 `param:"from"` // seconds
|
||||||
to int64 `param:"to"` // seconds
|
to *int64 `param:"to"` // seconds
|
||||||
state string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
|
state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
|
||||||
limit int `param:"limit"`
|
limit *int `param:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountService) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {
|
func (s *AccountService) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {
|
||||||
|
|
|
@ -90,3 +90,24 @@ func TestAccountService_GetWithdrawHistoryRequest(t *testing.T) {
|
||||||
assert.NotEmpty(t, withdraws)
|
assert.NotEmpty(t, withdraws)
|
||||||
t.Logf("withdraws: %+v", 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,22 @@ func (g *GetDepositHistoryRequest) Currency(currency string) *GetDepositHistoryR
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GetDepositHistoryRequest) From(from int64) *GetDepositHistoryRequest {
|
func (g *GetDepositHistoryRequest) From(from int64) *GetDepositHistoryRequest {
|
||||||
g.from = from
|
g.from = &from
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GetDepositHistoryRequest) To(to int64) *GetDepositHistoryRequest {
|
func (g *GetDepositHistoryRequest) To(to int64) *GetDepositHistoryRequest {
|
||||||
g.to = to
|
g.to = &to
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GetDepositHistoryRequest) State(state string) *GetDepositHistoryRequest {
|
func (g *GetDepositHistoryRequest) State(state string) *GetDepositHistoryRequest {
|
||||||
g.state = state
|
g.state = &state
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GetDepositHistoryRequest) Limit(limit int) *GetDepositHistoryRequest {
|
func (g *GetDepositHistoryRequest) Limit(limit int) *GetDepositHistoryRequest {
|
||||||
g.limit = limit
|
g.limit = &limit
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,25 +57,37 @@ func (g *GetDepositHistoryRequest) GetParameters() (map[string]interface{}, erro
|
||||||
// assign parameter of currency
|
// assign parameter of currency
|
||||||
params["currency"] = currency
|
params["currency"] = currency
|
||||||
// check from field -> json key from
|
// check from field -> json key from
|
||||||
from := g.from
|
if g.from != nil {
|
||||||
|
from := *g.from
|
||||||
|
|
||||||
// assign parameter of from
|
// assign parameter of from
|
||||||
params["from"] = from
|
params["from"] = from
|
||||||
|
} else {
|
||||||
|
}
|
||||||
// check to field -> json key to
|
// check to field -> json key to
|
||||||
to := g.to
|
if g.to != nil {
|
||||||
|
to := *g.to
|
||||||
|
|
||||||
// assign parameter of to
|
// assign parameter of to
|
||||||
params["to"] = to
|
params["to"] = to
|
||||||
|
} else {
|
||||||
|
}
|
||||||
// check state field -> json key state
|
// check state field -> json key state
|
||||||
state := g.state
|
if g.state != nil {
|
||||||
|
state := *g.state
|
||||||
|
|
||||||
// assign parameter of state
|
// assign parameter of state
|
||||||
params["state"] = state
|
params["state"] = state
|
||||||
|
} else {
|
||||||
|
}
|
||||||
// check limit field -> json key limit
|
// check limit field -> json key limit
|
||||||
limit := g.limit
|
if g.limit != nil {
|
||||||
|
limit := *g.limit
|
||||||
|
|
||||||
// assign parameter of limit
|
// assign parameter of limit
|
||||||
params["limit"] = limit
|
params["limit"] = limit
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,16 @@ func TestOrderService_GetOrdersRequest(t *testing.T) {
|
||||||
// req3.State([]OrderState{OrderStateDone})
|
// req3.State([]OrderState{OrderStateDone})
|
||||||
req3.Market("btcusdt")
|
req3.Market("btcusdt")
|
||||||
orders, err := req3.Do(ctx)
|
orders, err := req3.Do(ctx)
|
||||||
assert.NoError(t, err)
|
if assert.NoError(t, err) {
|
||||||
assert.NotNil(t, orders)
|
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) {
|
func TestOrderService_GetOrdersRequest_SingleState(t *testing.T) {
|
||||||
|
@ -84,7 +92,6 @@ func TestOrderService_GetOrderHistoryRequest(t *testing.T) {
|
||||||
assert.NotNil(t, orders)
|
assert.NotNil(t, orders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestOrderService(t *testing.T) {
|
func TestOrderService(t *testing.T) {
|
||||||
key, secret, ok := integrationTestConfigured(t, "MAX")
|
key, secret, ok := integrationTestConfigured(t, "MAX")
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user