2020-10-02 02:10:59 +00:00
|
|
|
package max
|
|
|
|
|
2022-04-19 04:10:15 +00:00
|
|
|
//go:generate -command GetRequest requestgen -method GET
|
|
|
|
//go:generate -command PostRequest requestgen -method POST
|
2022-05-24 10:00:52 +00:00
|
|
|
//go:generate -command DeleteRequest requestgen -method DELETE
|
2022-04-19 04:10:15 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-11 10:52:23 +00:00
|
|
|
"time"
|
|
|
|
|
2022-04-19 04:10:15 +00:00
|
|
|
"github.com/c9s/requestgen"
|
2022-04-20 05:28:39 +00:00
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
2023-04-11 10:46:29 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
2022-04-19 04:10:15 +00:00
|
|
|
)
|
2020-10-11 09:35:59 +00:00
|
|
|
|
2020-10-02 02:10:59 +00:00
|
|
|
type AccountService struct {
|
2022-08-10 07:22:04 +00:00
|
|
|
client requestgen.AuthenticatedAPIClient
|
2020-10-02 02:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Account is for max rest api v2, Balance and Type will be conflict with types.PrivateBalanceUpdate
|
|
|
|
type Account struct {
|
2022-05-28 08:47:41 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
Balance fixedpoint.Value `json:"balance"`
|
|
|
|
Locked fixedpoint.Value `json:"locked"`
|
|
|
|
|
|
|
|
// v3 fields for M wallet
|
2022-07-08 09:28:07 +00:00
|
|
|
Principal fixedpoint.Value `json:"principal"`
|
|
|
|
Interest fixedpoint.Value `json:"interest"`
|
2022-05-28 08:47:41 +00:00
|
|
|
|
|
|
|
// v2 fields
|
2022-04-20 05:28:39 +00:00
|
|
|
FiatCurrency string `json:"fiat_currency"`
|
|
|
|
FiatBalance fixedpoint.Value `json:"fiat_balance"`
|
2020-10-02 02:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
2021-03-18 09:52:23 +00:00
|
|
|
VipLevel int `json:"vip_level"`
|
2020-10-02 02:10:59 +00:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-03-18 09:57:52 +00:00
|
|
|
type VipLevelSettings struct {
|
|
|
|
Level int `json:"level"`
|
|
|
|
MinimumTradingVolume float64 `json:"minimum_trading_volume"`
|
|
|
|
MinimumStakingVolume float64 `json:"minimum_staking_volume"`
|
|
|
|
MakerFee float64 `json:"maker_fee"`
|
|
|
|
TakerFee float64 `json:"taker_fee"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type VipLevel struct {
|
|
|
|
Current VipLevelSettings `json:"current_vip_level"`
|
|
|
|
Next VipLevelSettings `json:"next_vip_level"`
|
|
|
|
}
|
|
|
|
|
2022-04-20 05:35:17 +00:00
|
|
|
//go:generate GetRequest -url "v2/members/vip_level" -type GetVipLevelRequest -responseType .VipLevel
|
|
|
|
type GetVipLevelRequest struct {
|
|
|
|
client requestgen.AuthenticatedAPIClient
|
|
|
|
}
|
|
|
|
|
2023-04-11 10:33:51 +00:00
|
|
|
func (c *RestClient) NewGetVipLevelRequest() *GetVipLevelRequest {
|
|
|
|
return &GetVipLevelRequest{client: c}
|
2021-03-18 09:57:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 05:20:54 +00:00
|
|
|
//go:generate GetRequest -url "v2/members/accounts/:currency" -type GetAccountRequest -responseType .Account
|
|
|
|
type GetAccountRequest struct {
|
|
|
|
client requestgen.AuthenticatedAPIClient
|
2020-10-02 02:10:59 +00:00
|
|
|
|
2022-04-20 05:20:54 +00:00
|
|
|
currency string `param:"currency,slug"`
|
2020-10-02 02:10:59 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:33:51 +00:00
|
|
|
func (c *RestClient) NewGetAccountRequest() *GetAccountRequest {
|
|
|
|
return &GetAccountRequest{client: c}
|
2022-04-20 05:28:39 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 05:20:54 +00:00
|
|
|
//go:generate GetRequest -url "v2/members/accounts" -type GetAccountsRequest -responseType []Account
|
2022-04-19 04:10:15 +00:00
|
|
|
type GetAccountsRequest struct {
|
|
|
|
client requestgen.AuthenticatedAPIClient
|
|
|
|
}
|
|
|
|
|
2023-04-11 10:36:10 +00:00
|
|
|
func (c *RestClient) NewGetAccountsRequest() *GetAccountsRequest {
|
|
|
|
return &GetAccountsRequest{client: c}
|
2022-04-19 04:10:15 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 12:51:09 +00:00
|
|
|
type DepositState string
|
|
|
|
|
|
|
|
const (
|
|
|
|
DepositStateSubmitting DepositState = "submitting"
|
|
|
|
DepositStateCancelled DepositState = "cancelled"
|
|
|
|
DepositStateSubmitted DepositState = "submitted"
|
|
|
|
DepositStatePending DepositState = "pending"
|
|
|
|
DepositStateSuspect DepositState = "suspect"
|
|
|
|
DepositStateRejected DepositState = "rejected"
|
|
|
|
DepositStateSuspended DepositState = "suspended"
|
|
|
|
DepositStateAccepted DepositState = "accepted"
|
|
|
|
DepositStateChecking DepositState = "checking"
|
2024-09-04 03:17:56 +00:00
|
|
|
|
|
|
|
// v3 states
|
|
|
|
DepositStateProcessing DepositState = "processing"
|
|
|
|
DepositStateDone DepositState = "done"
|
2023-08-08 12:51:09 +00:00
|
|
|
)
|
|
|
|
|
2020-10-11 09:35:59 +00:00
|
|
|
type Deposit struct {
|
2023-08-08 12:51:09 +00:00
|
|
|
Currency string `json:"currency"` // "eth"
|
2023-04-12 05:09:31 +00:00
|
|
|
CurrencyVersion string `json:"currency_version"` // "eth"
|
2023-08-08 12:51:09 +00:00
|
|
|
NetworkProtocol string `json:"network_protocol"` // "ethereum-erc20"
|
2023-04-12 05:09:31 +00:00
|
|
|
Amount fixedpoint.Value `json:"amount"`
|
|
|
|
Fee fixedpoint.Value `json:"fee"`
|
|
|
|
TxID string `json:"txid"`
|
2023-08-08 12:51:09 +00:00
|
|
|
State DepositState `json:"state"`
|
|
|
|
Status string `json:"status"`
|
2023-04-12 05:09:31 +00:00
|
|
|
Confirmations int64 `json:"confirmations"`
|
2023-08-08 12:51:09 +00:00
|
|
|
Address string `json:"to_address"` // 0x5c7d23d516f120d322fc7b116386b7e491739138
|
2023-04-12 05:09:31 +00:00
|
|
|
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
|
|
|
UpdatedAt types.MillisecondTimestamp `json:"updated_at"`
|
2020-10-11 09:35:59 +00:00
|
|
|
}
|
|
|
|
|
2024-08-16 05:40:26 +00:00
|
|
|
//go:generate GetRequest -url "v3/deposits" -type GetDepositHistoryRequest -responseType []Deposit
|
2020-10-11 09:35:59 +00:00
|
|
|
type GetDepositHistoryRequest struct {
|
2022-04-20 05:20:54 +00:00
|
|
|
client requestgen.AuthenticatedAPIClient
|
2020-10-11 09:35:59 +00:00
|
|
|
|
2024-08-16 05:40:26 +00:00
|
|
|
currency *string `param:"currency"`
|
|
|
|
timestamp *time.Time `param:"timestamp,milliseconds"` // seconds
|
|
|
|
state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
|
|
|
|
|
|
|
|
order *string `param:"order"`
|
|
|
|
|
|
|
|
limit *int `param:"limit"`
|
2020-10-11 09:35:59 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:36:10 +00:00
|
|
|
func (c *RestClient) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {
|
2020-10-11 09:35:59 +00:00
|
|
|
return &GetDepositHistoryRequest{
|
2023-04-11 10:36:10 +00:00
|
|
|
client: c,
|
2020-10-11 09:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-11 12:08:54 +00:00
|
|
|
|
2023-08-08 12:51:09 +00:00
|
|
|
// submitted -> accepted -> processing -> sent -> confirmed
|
|
|
|
type WithdrawState string
|
|
|
|
|
|
|
|
const (
|
|
|
|
WithdrawStateSubmitting WithdrawState = "submitting"
|
2024-07-31 08:43:56 +00:00
|
|
|
WithdrawStateSubmitted WithdrawState = "submitted"
|
2023-08-08 12:51:09 +00:00
|
|
|
WithdrawStateConfirmed WithdrawState = "confirmed"
|
2024-07-31 08:43:56 +00:00
|
|
|
WithdrawStatePending WithdrawState = "pending"
|
|
|
|
WithdrawStateProcessing WithdrawState = "processing"
|
|
|
|
WithdrawStateCanceled WithdrawState = "canceled"
|
|
|
|
WithdrawStateFailed WithdrawState = "failed"
|
|
|
|
WithdrawStateSent WithdrawState = "sent"
|
|
|
|
WithdrawStateRejected WithdrawState = "rejected"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WithdrawStatus string
|
|
|
|
|
|
|
|
const (
|
|
|
|
WithdrawStatusPending WithdrawStatus = "pending"
|
|
|
|
WithdrawStatusCancelled WithdrawStatus = "cancelled"
|
|
|
|
WithdrawStatusFailed WithdrawStatus = "failed"
|
|
|
|
WithdrawStatusOK WithdrawStatus = "ok"
|
2023-08-08 12:51:09 +00:00
|
|
|
)
|
|
|
|
|
2020-10-11 12:08:54 +00:00
|
|
|
type Withdraw struct {
|
2022-04-20 05:47:12 +00:00
|
|
|
UUID string `json:"uuid"`
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
CurrencyVersion string `json:"currency_version"` // "eth"
|
|
|
|
Amount fixedpoint.Value `json:"amount"`
|
|
|
|
Fee fixedpoint.Value `json:"fee"`
|
|
|
|
FeeCurrency string `json:"fee_currency"`
|
|
|
|
TxID string `json:"txid"`
|
2020-10-11 12:08:54 +00:00
|
|
|
|
2024-07-31 08:43:56 +00:00
|
|
|
NetworkProtocol string `json:"network_protocol"`
|
|
|
|
Address string `json:"to_address"`
|
|
|
|
|
2020-10-11 12:08:54 +00:00
|
|
|
// State can be "submitting", "submitted",
|
|
|
|
// "rejected", "accepted", "suspect", "approved", "delisted_processing",
|
|
|
|
// "processing", "retryable", "sent", "canceled",
|
|
|
|
// "failed", "pending", "confirmed",
|
|
|
|
// "kgi_manually_processing", "kgi_manually_confirmed", "kgi_possible_failed",
|
|
|
|
// "sygna_verifying"
|
2024-07-31 08:43:56 +00:00
|
|
|
State WithdrawState `json:"state"`
|
|
|
|
|
2024-08-07 09:12:55 +00:00
|
|
|
// Status WithdrawStatus `json:"status,omitempty"`
|
2024-07-31 08:43:56 +00:00
|
|
|
|
|
|
|
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
|
|
|
UpdatedAt types.MillisecondTimestamp `json:"updated_at"`
|
|
|
|
Notes string `json:"notes"`
|
2020-10-11 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-02 07:20:28 +00:00
|
|
|
//go:generate GetRequest -url "v3/withdrawals" -type GetWithdrawHistoryRequest -responseType []Withdraw
|
2020-10-11 12:08:54 +00:00
|
|
|
type GetWithdrawHistoryRequest struct {
|
2022-04-20 05:20:54 +00:00
|
|
|
client requestgen.AuthenticatedAPIClient
|
2020-10-11 12:08:54 +00:00
|
|
|
|
2024-08-16 05:27:14 +00:00
|
|
|
currency *string `param:"currency"`
|
|
|
|
state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect
|
|
|
|
timestamp *time.Time `param:"timestamp,milliseconds"` // milli-seconds
|
|
|
|
|
|
|
|
// order could be desc or asc
|
|
|
|
order *string `param:"order"`
|
|
|
|
|
|
|
|
// limit's default = 50
|
|
|
|
limit *int `param:"limit"`
|
2022-04-20 05:47:12 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:36:10 +00:00
|
|
|
func (c *RestClient) NewGetWithdrawalHistoryRequest() *GetWithdrawHistoryRequest {
|
2022-04-20 05:47:12 +00:00
|
|
|
return &GetWithdrawHistoryRequest{
|
2023-04-11 10:36:10 +00:00
|
|
|
client: c,
|
2022-04-20 05:47:12 +00:00
|
|
|
}
|
2020-10-11 12:08:54 +00:00
|
|
|
}
|