maxapi

package
v1.64.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 14 Imported by: 3 modules, 12 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	All = iota
	Active
	Closed
)
View Source
const (
	OrderStateDone = OrderState("done")

	OrderStateCancel     = OrderState("cancel")
	OrderStateWait       = OrderState("wait")
	OrderStateConvert    = OrderState("convert")
	OrderStateFinalizing = OrderState("finalizing")
	OrderStateFailed     = OrderState("failed")
)
View Source
const (
	OrderTypeMarket     = OrderType("market")
	OrderTypeLimit      = OrderType("limit")
	OrderTypePostOnly   = OrderType("post_only")
	OrderTypeStopLimit  = OrderType("stop_limit")
	OrderTypeStopMarket = OrderType("stop_market")
	OrderTypeIOCLimit   = OrderType("ioc_limit")
)

Order types that the API can return.

View Source
const (
	Buy  = 1
	Sell = -1
)
View Source
const (
	BookEventSnapshot string = "snapshot"
	BookEventUpdate   string = "update"
)

Variables

View Source
var ErrIncorrectBookEntryElementLength = errors.New("incorrect book entry element length")
View Source
var ErrMessageTypeNotSupported = errors.New("message type currently not supported")
View Source
var WebSocketURL = "wss://max-stream.maicoin.com/ws"

Functions

func IsFilledOrderState added in v1.58.0

func IsFilledOrderState(state OrderState) bool

func ParseMessage

func ParseMessage(payload []byte) (interface{}, error)

ParseMessage accepts the raw messages from max public websocket channels and parses them into market data Return types: *BookEvent, *PublicTradeEvent, *SubscriptionEvent, *ErrorEvent

func ParseUserEvent

func ParseUserEvent(v *fastjson.Value) (interface{}, error)

func SignPayload added in v1.64.0

func SignPayload(payload string, secret string) string

Types

type ADRatio added in v1.33.0

type ADRatio struct {
	ADRatio     fixedpoint.Value `json:"ad"`
	AssetInUSDT fixedpoint.Value `json:"as"`
	DebtInUSDT  fixedpoint.Value `json:"db"`
	IndexPrices []struct {
		Market string           `json:"M"`
		Price  fixedpoint.Value `json:"p"`
	} `json:"idxp"`
	TU types.MillisecondTimestamp `json:"TU"`
}

func (*ADRatio) String added in v1.33.0

func (r *ADRatio) String() string

type ADRatioEvent added in v1.33.0

type ADRatioEvent struct {
	ADRatio ADRatio `json:"ad"`
}

type Account

type Account struct {
	Type     string           `json:"type"`
	Currency string           `json:"currency"`
	Balance  fixedpoint.Value `json:"balance"`
	Locked   fixedpoint.Value `json:"locked"`

	// v3 fields for M wallet
	Principal fixedpoint.Value `json:"principal"`
	Interest  fixedpoint.Value `json:"interest"`

	// v2 fields
	FiatCurrency string           `json:"fiat_currency"`
	FiatBalance  fixedpoint.Value `json:"fiat_balance"`
}

Account is for max rest api v2, Balance and Type will be conflict with types.PrivateBalanceUpdate

type AccountSnapshotEvent

type AccountSnapshotEvent struct {
	BaseEvent
	Balances []BalanceMessage `json:"B"`
}

type AccountUpdateEvent

type AccountUpdateEvent struct {
	BaseEvent
	Balances []BalanceMessage `json:"B"`
}

type AuthEvent

type AuthEvent struct {
	Event     string
	ID        string
	Timestamp int64
}

type AuthMessage

type AuthMessage struct {
	Action    string   `json:"action,omitempty"`
	APIKey    string   `json:"apiKey,omitempty"`
	Nonce     int64    `json:"nonce,omitempty"`
	Signature string   `json:"signature,omitempty"`
	ID        string   `json:"id,omitempty"`
	Filters   []string `json:"filters,omitempty"`

	// SubAccount is the SN of the sub-account to access, this is only for master account.
	SubAccount string `json:"subAccount,omitempty"`
}

type BalanceMessage

type BalanceMessage struct {
	Currency  string           `json:"cu"`
	Available fixedpoint.Value `json:"av"`
	Locked    fixedpoint.Value `json:"l"`

	SubAccount string `json:"sa,omitempty"`
}

func (*BalanceMessage) Balance

func (m *BalanceMessage) Balance() (*types.Balance, error)

type BaseEvent

type BaseEvent struct {
	Event     string `json:"e"`
	Timestamp int64  `json:"T"`
}

type BookEvent

type BookEvent struct {
	Event         string `json:"e"`
	Market        string `json:"M"`
	Channel       string `json:"c"`
	Timestamp     int64  `json:"t"` // Millisecond timestamp
	Bids          types.PriceVolumeSlice
	Asks          types.PriceVolumeSlice
	FirstUpdateID int64 `json:"fi"`
	LastUpdateID  int64 `json:"li"`
	Version       int64 `json:"v"`
}

func (*BookEvent) OrderBook

func (e *BookEvent) OrderBook() (snapshot types.SliceOrderBook, err error)

func (*BookEvent) Time

func (e *BookEvent) Time() time.Time

type Debt added in v1.33.0

type Debt struct {
	Currency      string                     `json:"cu"`
	DebtPrincipal fixedpoint.Value           `json:"dbp"`
	DebtInterest  fixedpoint.Value           `json:"dbi"`
	TU            types.MillisecondTimestamp `json:"TU"`
}

func (*Debt) String added in v1.33.0

func (d *Debt) String() string

type DebtEvent added in v1.33.0

type DebtEvent struct {
	Debts []Debt `json:"db"`
}

type ErrorEvent

type ErrorEvent struct {
	Timestamp int64
	Errors    []string
	CommandID string
}

func (ErrorEvent) Time

func (e ErrorEvent) Time() time.Time

type ErrorField

type ErrorField struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	*requestgen.Response
	Err ErrorField `json:"error"`
}

ErrorResponse is the custom error type that is returned if the API returns an error.

func ToErrorResponse added in v1.17.0

func ToErrorResponse(response *requestgen.Response) (errorResponse *ErrorResponse, err error)

ToErrorResponse tries to convert/parse the server response to the standard Error interface object

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type KLine

type KLine struct {
	Symbol                 string
	Interval               string
	StartTime, EndTime     time.Time
	Open, High, Low, Close fixedpoint.Value
	Volume                 fixedpoint.Value
	Closed                 bool
}

func (KLine) KLine

func (k KLine) KLine() types.KLine

type KLineEvent

type KLineEvent struct {
	Event     string `json:"e"`
	Market    string `json:"M"`
	Channel   string `json:"c"`
	KLine     KLine  `json:"k"`
	Timestamp int64  `json:"T"`
}

type KLinePayload

type KLinePayload struct {
	StartTime   int64  `json:"ST"`
	EndTime     int64  `json:"ET"`
	Market      string `json:"M"`
	Resolution  string `json:"R"`
	Open        string `json:"O"`
	High        string `json:"H"`
	Low         string `json:"L"`
	Close       string `json:"C"`
	Volume      string `json:"v"`
	LastTradeID int    `json:"ti"`
	Closed      bool   `json:"x"`
}
{
  "c": "kline",
  "M": "btcusdt",
  "e": "update",
  "T": 1602999650179,
  "k": {
    "ST": 1602999900000,
    "ET": 1602999900000,
    "M": "btcusdt",
    "R": "5m",
    "O": "11417.21",
    "H": "11417.21",
    "L": "11417.21",
    "C": "11417.21",
    "v": "0",
    "ti": 0,
    "x": false
  }
}

func (KLinePayload) KLine

func (k KLinePayload) KLine() types.KLine

type Order

type Order struct {
	ID              uint64                     `json:"id,omitempty"`
	WalletType      WalletType                 `json:"wallet_type,omitempty"`
	Side            string                     `json:"side"`
	OrderType       OrderType                  `json:"ord_type"`
	Price           fixedpoint.Value           `json:"price,omitempty"`
	StopPrice       fixedpoint.Value           `json:"stop_price,omitempty"`
	AveragePrice    fixedpoint.Value           `json:"avg_price,omitempty"`
	State           OrderState                 `json:"state,omitempty"`
	Market          string                     `json:"market,omitempty"`
	Volume          fixedpoint.Value           `json:"volume"`
	RemainingVolume fixedpoint.Value           `json:"remaining_volume,omitempty"`
	ExecutedVolume  fixedpoint.Value           `json:"executed_volume,omitempty"`
	TradesCount     int64                      `json:"trades_count,omitempty"`
	GroupID         uint32                     `json:"group_id,omitempty"`
	ClientOID       string                     `json:"client_oid,omitempty"`
	CreatedAt       types.MillisecondTimestamp `json:"created_at"`
	UpdatedAt       types.MillisecondTimestamp `json:"updated_at"`
}

Order represents one returned order (POST order/GET order/GET orders) on the max platform.

type OrderByType added in v1.55.0

type OrderByType string
const (
	OrderByAsc           OrderByType = "asc"
	OrderByDesc          OrderByType = "desc"
	OrderByAscUpdatedAt  OrderByType = "asc_updated_at"
	OrderByDescUpdatedAt OrderByType = "desc_updated_at"
)

type OrderSnapshotEvent

type OrderSnapshotEvent struct {
	BaseEvent

	Orders []OrderUpdate `json:"o"`
}

type OrderState

type OrderState string

type OrderStateToQuery

type OrderStateToQuery int

type OrderType

type OrderType string

type OrderUpdate

type OrderUpdate struct {
	Event     string    `json:"e"`
	ID        uint64    `json:"i"`
	Side      string    `json:"sd"`
	OrderType OrderType `json:"ot"`

	Price     fixedpoint.Value `json:"p"`
	StopPrice fixedpoint.Value `json:"sp"`

	Volume       fixedpoint.Value `json:"v"`
	AveragePrice fixedpoint.Value `json:"ap"`
	State        OrderState       `json:"S"`
	Market       string           `json:"M"`

	RemainingVolume fixedpoint.Value `json:"rv"`
	ExecutedVolume  fixedpoint.Value `json:"ev"`

	TradesCount int64 `json:"tc"`

	GroupID     uint32 `json:"gi"`
	ClientOID   string `json:"ci"`
	CreatedAtMs int64  `json:"T"`
	UpdateTime  int64  `json:"TU"`
}

type OrderUpdateEvent

type OrderUpdateEvent struct {
	BaseEvent

	Orders []OrderUpdate `json:"o"`
}

type PublicTradeEvent

type PublicTradeEvent struct {
	Event     string       `json:"e"`
	Market    string       `json:"M"`
	Channel   string       `json:"c"`
	Trades    []TradeEntry `json:"t"`
	Timestamp int64        `json:"T"`
}

func (*PublicTradeEvent) Time

func (e *PublicTradeEvent) Time() time.Time

type SubscribeOptions added in v1.13.0

type SubscribeOptions struct {
	Depth      int    `json:"depth,omitempty"`
	Resolution string `json:"resolution,omitempty"`
}

type Subscription

type Subscription struct {
	Channel    string `json:"channel"`
	Market     string `json:"market"`
	Depth      int    `json:"depth,omitempty"`
	Resolution string `json:"resolution,omitempty"`
}

Subscription is used for presenting the subscription metadata. This is used for sending subscribe and unsubscribe requests

type SubscriptionEvent

type SubscriptionEvent struct {
	Event         string         `json:"e"`
	Timestamp     int64          `json:"T"`
	CommandID     string         `json:"i"`
	Subscriptions []Subscription `json:"s"`
}

func (SubscriptionEvent) Time

func (e SubscriptionEvent) Time() time.Time

type TradeEntry

type TradeEntry struct {
	Trend     string `json:"tr"`
	Price     string `json:"p"`
	Volume    string `json:"v"`
	Timestamp int64  `json:"T"`
}

func (TradeEntry) Time

func (e TradeEntry) Time() time.Time

type TradeSnapshotEvent

type TradeSnapshotEvent struct {
	BaseEvent
	Trades []TradeUpdate `json:"t"`
}

type TradeUpdate

type TradeUpdate struct {
	ID     uint64           `json:"i"`
	Side   string           `json:"sd"`
	Price  fixedpoint.Value `json:"p"`
	Volume fixedpoint.Value `json:"v"`
	Funds  fixedpoint.Value `json:"fn"`
	Market string           `json:"M"`

	Fee           fixedpoint.Value `json:"f"`
	FeeCurrency   string           `json:"fc"`
	FeeDiscounted bool             `json:"fd"`

	Timestamp  types.MillisecondTimestamp `json:"T"`
	UpdateTime types.MillisecondTimestamp `json:"TU"`

	OrderID uint64 `json:"oi"`

	Maker bool `json:"m"`
}

type TradeUpdateEvent

type TradeUpdateEvent struct {
	BaseEvent
	Trades []TradeUpdate `json:"t"`
}

type UserBank

type UserBank struct {
	Branch  string `json:"branch"`
	Name    string `json:"name"`
	Account string `json:"account"`
	State   string `json:"state"`
}

type UserInfo

type UserInfo struct {
	Email          string           `json:"email"`
	Level          int              `json:"level"`
	MWalletEnabled bool             `json:"m_wallet_enabled"`
	Current        VipLevelSettings `json:"current_vip_level"`
	Next           VipLevelSettings `json:"next_vip_level"`
}

type VipLevel added in v1.14.1

type VipLevel struct {
	Current VipLevelSettings `json:"current_vip_level"`
	Next    VipLevelSettings `json:"next_vip_level"`
}

type VipLevelSettings added in v1.14.1

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 WalletType added in v1.33.0

type WalletType string
const (
	WalletTypeSpot   WalletType = "spot"
	WalletTypeMargin WalletType = "m"
)

type WebsocketCommand

type WebsocketCommand struct {
	// Action is used for specify the action of the websocket session.
	// Valid values are "subscribe", "unsubscribe" and "auth"
	Action        string         `json:"action"`
	Subscriptions []Subscription `json:"subscriptions,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL