bbgo_origin/pkg/exchange/max/maxapi/account.go

189 lines
4.6 KiB
Go
Raw Normal View History

2020-10-02 02:10:59 +00:00
package max
import "context"
2020-10-02 02:10:59 +00:00
type AccountService struct {
client *RestClient
}
// Account is for max rest api v2, Balance and Type will be conflict with types.PrivateBalanceUpdate
type Account struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Locked string `json:"locked"`
Type string `json:"type"`
}
// Balance is for kingfisher
type Balance struct {
Currency string
Available int64
Locked int64
Total int64
}
type UserBank struct {
Branch string `json:"branch"`
Name string `json:"name"`
Account string `json:"account"`
State string `json:"state"`
}
type UserInfo struct {
Sn string `json:"sn"`
Name string `json:"name"`
Type string `json:"member_type"`
Level int `json:"level"`
Email string `json:"email"`
Accounts []Account `json:"accounts"`
Bank *UserBank `json:"bank,omitempty"`
IsFrozen bool `json:"is_frozen"`
IsActivated bool `json:"is_activated"`
KycApproved bool `json:"kyc_approved"`
KycState string `json:"kyc_state"`
PhoneSet bool `json:"phone_set"`
PhoneNumber string `json:"phone_number"`
ProfileVerified bool `json:"profile_verified"`
CountryCode string `json:"country_code"`
IdentityNumber string `json:"identity_number"`
WithDrawable bool `json:"withdrawable"`
ReferralCode string `json:"referral_code"`
}
func (s *AccountService) Account(currency string) (*Account, error) {
req, err := s.client.newAuthenticatedRequest("GET", "v2/members/accounts/"+currency, nil)
if err != nil {
return nil, err
}
response, err := s.client.sendRequest(req)
if err != nil {
return nil, err
}
var account Account
err = response.DecodeJSON(&account)
if err != nil {
return nil, err
}
return &account, nil
}
func (s *AccountService) Accounts() ([]Account, error) {
req, err := s.client.newAuthenticatedRequest("GET", "v2/members/accounts", nil)
if err != nil {
return nil, err
}
response, err := s.client.sendRequest(req)
if err != nil {
return nil, err
}
var accounts []Account
err = response.DecodeJSON(&accounts)
if err != nil {
return nil, err
}
return accounts, nil
}
// Me returns the current user info by the current used MAX key and secret
func (s *AccountService) Me() (*UserInfo, error) {
req, err := s.client.newAuthenticatedRequest("GET", "v2/members/me", nil)
if err != nil {
return nil, err
}
response, err := s.client.sendRequest(req)
if err != nil {
return nil, err
}
var m = UserInfo{}
err = response.DecodeJSON(&m)
if err != nil {
return nil, err
}
return &m, nil
}
type Deposit struct {
Currency string `json:"currency"`
CurrencyVersion string `json:"currency_version"` // "eth"
Amount string `json:"amount"`
Fee string `json:"fee"`
TxID string `json:"txid"`
State string `json:"state"`
Confirmations int `json:"confirmations"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
type GetDepositHistoryRequestParams struct {
*PrivateRequestParams
Currency string `json:"currency"`
From int64 `json:"from,omitempty"` // seconds
To int64 `json:"to,omitempty"` // seconds
State string `json:"state,omitempty"` // submitting, submitted, rejected, accepted, checking, refunded, cancelled, suspect
Limit int `json:"limit,omitempty"`
}
type GetDepositHistoryRequest struct {
client *RestClient
params GetDepositHistoryRequestParams
}
func (r *GetDepositHistoryRequest) State(state string) *GetDepositHistoryRequest {
r.params.State = state
return r
}
func (r *GetDepositHistoryRequest) Currency(currency string) *GetDepositHistoryRequest {
r.params.Currency = currency
return r
}
func (r *GetDepositHistoryRequest) Limit(limit int) *GetDepositHistoryRequest {
r.params.Limit = limit
return r
}
func (r *GetDepositHistoryRequest) From(from int64) *GetDepositHistoryRequest {
r.params.From = from
return r
}
func (r *GetDepositHistoryRequest) To(to int64) *GetDepositHistoryRequest {
r.params.To = to
return r
}
func (r *GetDepositHistoryRequest) Do(ctx context.Context) (deposits []Deposit, err error) {
req, err := r.client.newAuthenticatedRequest("GET", "v2/deposits", &r.params)
if err != nil {
return deposits, err
}
response, err := r.client.sendRequest(req)
if err != nil {
return deposits, err
}
if err := response.DecodeJSON(&deposits); err != nil {
return deposits, err
}
return deposits, err
}
func (s *AccountService) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {
return &GetDepositHistoryRequest{
client: s.client,
}
}