max

package module
v0.0.0-...-ec27bc9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

License GoDoc Go Report Card

max-exchange-api-go

MAX (Maicoin Assets eXchange) Go SDK

Examples

See the examples directory.

Documentation for API Endpoints

Notes

Private APIs require authentication. Pass your API tokens by AuthToken() or WSAuthToken() before using them.

RESTful APIs

All URIs are relative to https://max-api.maicoin.com

Class Go Method HTTP request Description
Public Currencies GET /api/v2/currencies
Public Depth GET /api/v2/depth
Public K GET /api/v2/k
Public Markets GET /api/v2/markets
Public OrderBook GET /api/v2/order_book
Public Tickers GET /api/v2/tickers
Public Ticker GET /api/v2/tickers/{market}
Public Timestamp GET /api/v2/timestamp
Public Trades GET /api/v2/trades
Class Go Method HTTP request Description
Private Deposit GET /api/v2/deposit
Private DepositAddress GET /api/v2/deposit_address Deprecated
Private CreateDepositAddresses POST /api/v2/deposit_addresses create deposit addresses
Private DepositAddresses GET /api/v2/deposit_addresses where to deposit
Private Deposits GET /api/v2/deposits
Private Me GET /api/v2/members/me
Private Order GET /api/v2/order
Private Orders GET /api/v2/orders
Private MyTrades GET /api/v2/trades/my
Private Withdrawal GET /api/v2/withdrawal
Private Withdrawals GET /api/v2/withdrawals
Private CancelOrder POST /api/v2/order/delete
Private CancelOrders POST /api/v2/orders/clear
Private CreateOrder POST /api/v2/orders
Private CreateOrders POST /api/v2/orders/multi create multiple sell/buy orders
Websocket APIs (Beta)
Class Go Method Description
Public SubscribeTicker Subscribe the realtime price information
Public SubscribeOrderBook Subscribe the realtime changes on order books
Public SubscribeTrade Subscribe the realtime trades information
Class Go Method Description
Private SubscribeAccount Subscribe the accounts changes for an user

API Reference

See MAX RESTful API List and MAX Websocket API List (Beta).

Documentation

Index

Constants

View Source
const (
	HeaderAccessKey  = "X-MAX-ACCESSKEY"
	HeaderPayloadKey = "X-MAX-PAYLOAD"
	HeaderSignature  = "X-MAX-SIGNATURE"
)

Variables

View Source
var (
	DepositStateSubmitting      types.DepositState = "submitting"
	DepositStateCancelled       types.DepositState = "cancelled"
	DepositStateSubmitted       types.DepositState = "submitted"
	DepositStateSuspended       types.DepositState = "suspended"
	DepositStateRejected        types.DepositState = "rejected"
	DepositStateAccepted        types.DepositState = "accepted"
	DepositStateRefunded        types.DepositState = "refunded"
	DepositStateSuspect         types.DepositState = "suspect"
	DepositStateRefundCancelled types.DepositState = "refund_cancelled"
)
View Source
var (
	WithdrawalStateSubmitting types.WithdrawalState = "submitting"
	WithdrawalStateSubmitted  types.WithdrawalState = "submitted"
	WithdrawalStateRejected   types.WithdrawalState = "rejected"
	WithdrawalStateAccepted   types.WithdrawalState = "accepted"
	WithdrawalStateSuspect    types.WithdrawalState = "suspect"
	WithdrawalStateApproved   types.WithdrawalState = "approved"
	WithdrawalStateProcessing types.WithdrawalState = "processing"
	WithdrawalStateRetryable  types.WithdrawalState = "retryable"
	WithdrawalStateSent       types.WithdrawalState = "sent"
	WithdrawalStateCancelled  types.WithdrawalState = "cancelled"
	WithdrawalStateFailed     types.WithdrawalState = "failed"
	WithdrawalStatePending    types.WithdrawalState = "pending"
	WithdrawalStateConfirmed  types.WithdrawalState = "confirmed"
)
View Source
var (
	OrderTypeLimit      types.OrderType = "limit"
	OrderTypeMarket     types.OrderType = "market"
	OrderTypeStopLimit  types.OrderType = "stop_limit"
	OrderTypeStopMarket types.OrderType = "stop_market"
)
View Source
var (
	OrderSideSell types.OrderSide = "sell"
	OrderSideBuy  types.OrderSide = "buy"
)
View Source
var (
	OrderStateWait    types.OrderState = "wait"
	OrderStateDone    types.OrderState = "done"
	OrderStateConvert types.OrderState = "convert"
	OrderStateCancel  types.OrderState = "cancel"
)

Functions

func NewClient

func NewClient(opts ...ClientOption) *client

func NewWSClient

func NewWSClient(opts ...WebsocketClientOption) (*wsClient, error)

NewWSClient returns a websocket client.

Types

type API

type API interface {
	PublicAPI
	PrivateAPI
}

API provides an interface to the MAX APIs

type AccountSubscription

type AccountSubscription interface {
	Chan() <-chan models.AccountEvent
	Close()
}

type CallOption

type CallOption func(opt map[string]interface{})

CallOption represents the API parameters

func AsksLimit

func AsksLimit(limit int32) CallOption

AsksLimit represents the asks_limit parameter

func BidsLimit

func BidsLimit(limit int32) CallOption

BidsLimit represents the bids_limit parameter

func Currency

func Currency(currency string) CallOption

Currency represents the currency parameter

func DepositState

func DepositState(state types.DepositState) CallOption

DepositState represents the state parameter for deposit

func From

func From(from int32) CallOption

From represents the from parameter

func FromTime

func FromTime(from time.Time) CallOption

FromTime represents the from parameter in Go time.Time format

func Limit

func Limit(limit int32) CallOption

Limit represents the limit parameter

func Market

func Market(market string) CallOption

Market represents the market parameter

func Offset

func Offset(offset int32) CallOption

Offset represents the offset parameter

func OrderAsc

func OrderAsc() CallOption

OrderAsc represents the order_by=asc parameter

func OrderDesc

func OrderDesc() CallOption

OrderDesc represents the order_by=desc parameter

func OrderSide

func OrderSide(t types.OrderSide) CallOption

OrderSide represents the side parameter

func OrderType

func OrderType(t types.OrderType) CallOption

OrderType represents the ord_type parameter

func OrderTypes

func OrderTypes(t []types.OrderType) CallOption

OrderTypes represents the orders[ord_type] parameter

func Page

func Page(page int32) CallOption

Page represents the page parameter

func Pagination

func Pagination(pagination bool) CallOption

Pagination represents the pagination parameter

func Period

func Period(period int32) CallOption

Period represents the period parameter

func PeriodDuration

func PeriodDuration(period time.Duration) CallOption

PeriodDuration represents the period parameter in Go time.Duration format

func Price

func Price(price types.Price) CallOption

Price represents the price parameter

func Prices

func Prices(prices []types.Price) CallOption

Prices represents the orders[price] parameter

func StopPrice

func StopPrice(price types.Price) CallOption

StopPrice represents the stop_price parameter

func StopPrices

func StopPrices(prices []types.Price) CallOption

StopPrices represents the orders[stop_price] parameter

func Time

func Time(t time.Time) CallOption

Time represents the timestamp parameter in Go time.Time format

func Timestamp

func Timestamp(timestamp int32) CallOption

Timestamp represents the timestamp parameter

func To

func To(to int32) CallOption

To represents the to parameter

func ToTime

func ToTime(to time.Time) CallOption

ToTime represents the to parameter

func WithdrawalState

func WithdrawalState(state types.WithdrawalState) CallOption

WithdrawalState represents the state parameter for withdrawal

type ClientOption

type ClientOption func(*client)

func AuthToken

func AuthToken(accessKey, secretKey string) ClientOption

AuthToken passess the access key and secret key to the API client.

func BasePath

func BasePath(path string) ClientOption

BasePath sets base path of the API endpoint

func Logging

func Logging(logger *log.Logger) ClientOption

Logging enables HTTP request logging

func Timeout

func Timeout(t time.Duration) ClientOption

Timeout sets the HTTP request timeout

func UserAgent

func UserAgent(agent string) ClientOption

UserAgent sets the User-Agent in HTTP header.

type Options

type Options map[string]interface{}

type OrderBookSubscription

type OrderBookSubscription interface {
	Chan() <-chan *models.OrderBookEvent
	Close()
}

type PrivateAPI

type PrivateAPI interface {
	// Me returns user profile and accounts information
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Me(context.Context, ...CallOption) (*models.Member, error)

	// Deposit returns details of the deposit with specific transaction ID.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Deposit(context.Context, string, ...CallOption) (*models.Deposit, error)

	// Deposits returns the history of your deposits.
	//
	// Available `CallOption`:
	//    Currency(): unique currency id, use Currencies() for available currencies.
	//    From(): target period start (Epoch time in seconds)
	//    FromTime(): target period start
	//    To(): target period end (Epoch time in seconds)
	//    ToTime(): target period end
	//    State(): the state of deposit
	//    Pagination(): do pagination & return metadata in header (default false)
	//    Page(): page number, applied for pagination (default 1)
	//    Limit(): returned limit (1~1000, default 50)
	//    Offset(): records to skip, not applied for pagination (default 0)
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Deposits(context.Context, ...CallOption) ([]*models.Deposit, error)

	// Deprecated: Use DepositAddresses instead.
	//
	// DepositAddress returns the addresses which are able to deposit.
	//
	// Available `CallOption`:
	//    Currency(): unique currency id, use Currencies() for available currencies.
	//
	// The address could be empty when a new one is generating, try again later in that case.
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	DepositAddress(context.Context, ...CallOption) ([]*models.PaymentAddress, error)

	// DepositAddress returns the addresses that users are able to deposit.
	//
	// The address could be empty when a new one is generating, try again later in that case.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	DepositAddresses(context.Context, ...CallOption) ([]*models.PaymentAddress, error)

	// CreateDepositAddresses creates new addresses for deposit.
	//
	// Address creation is asynchronous, please call DepositAddresses later to get generated addresses
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	CreateDepositAddresses(context.Context, string, ...CallOption) ([]*models.PaymentAddress, error)

	// Withdrawal returns the details of specific withdrawal.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Withdrawal(context.Context, string, ...CallOption) (*models.Withdrawal, error)

	// Withdrawals returns the withdrawals history.
	//
	// Available `CallOption`:
	//     Currency(): unique currency id, check Currencies() for available currencies
	//     From(): target period start (Epoch time in seconds)
	//     FromTime(): target period start
	//     To(): target period end (Epoch time in seconds)
	//     ToTime(): target period end
	//     State(): the state of withdrawals
	//     Pagniation(): do pagination & return metadata in header (default false)
	//     Page(): page number, applied for pagination (default 1)
	//     Limit(): returned limit (1~1000, default 50)
	//     Offset(): records to skip, not applied for pagination (default 0)
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Withdrawals(context.Context, ...CallOption) ([]*models.Withdrawal, error)

	// CreateOrder creates a sell/buy order.
	//
	// markets: unique market id, check Markets() for available markets
	// side: 'sell' or 'buy'
	// volume: total amount to sell/buy, an order could be partially executed
	//
	// Available `CallOption`:
	//    Price(): price per unit
	//    StopPrice(): price per unit to trigger a stop order
	//    OrderType(): `OrderTypeLimit`, `OrderTypeMarket`, `OrderTypeStopLimit`, or `OrderTypeStopMarket`
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	CreateOrder(context.Context, string, string, types.Volume, ...CallOption) (*models.Order, error)

	// CreateOrders creates multiple sell/buy orders.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	CreateOrders(context.Context, string, []*models.OrderRequest, ...CallOption) ([]*models.Order, error)

	// CancelOrder cancels a sell/buy order.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	CancelOrder(context.Context, int32, ...CallOption) (*models.Order, error)

	// CancelOrders cancels a series of sell/buy orders.
	//
	// Available `CallOption`:
	//     OrderSide(): set tp cancel only sell (asks) or buy (bids) orders
	//     Market(): specify market like btctwd / ethbtc
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	CancelOrders(context.Context, ...CallOption) ([]*models.Order, error)

	// Order returns details of a specific order.
	//
	// Available `CallOption`:
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Order(context.Context, int32, ...CallOption) (*models.Order, error)

	// Orders returns your orders.
	//
	// Available `CallOption`:
	//     State(): filter by state, default to 'OrderStateWait'
	//     OrderDesc(): use descending order by created time
	//     OrderAsc(): use ascending order by created time, default value
	//     Pagination(): do pagination & return metadata in header (default true)
	//     Page(): page number, applied for pagination (default 1)
	//     Limit(): returned limit (1~1000, default 100)
	//     Offset(): records to skip, not applied for pagination (default 0)
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	Orders(context.Context, string, ...CallOption) ([]*models.Order, error)

	// MyTrades returns the executed trades which are sorted in reverse creation order.
	//
	// Available `CallOption`:
	//     Timestamp(): the seconds elapsed since Unix epoch, set to return trades executed before the time only
	//     Time(): the time in Go format, set to return trades executed before the time only
	//     From(): trade id, set ot return trades created after the trade
	//     To(): trade id, set to return trades created before the trade
	//     OrderDesc(): use descending order by created time, default value
	//     OrderAsc(): use ascending order by created time
	//     Pagination(): do pagination & return metadata in header (default true)
	//     Page(): page number, applied for pagination (default 1)
	//     Limit(): returned limit (1~1000, default 50)
	//     Offset(): records to skip, not applied for pagination (default 0)
	//
	// Note:
	//     Use AuthToken() to pass your auth tokens.
	MyTrades(context.Context, string, ...CallOption) ([]*models.Trade, error)
}

PrivateAPI provides an interface the private MAX APIs which has authtication requirements and rate limits.

type PublicAPI

type PublicAPI interface {
	// Markets returns available markets on MAX.
	//
	// Available `CallOption`:
	//
	Markets(context.Context, ...CallOption) ([]*models.Market, error)

	// Markets returns available currencies on MAX.
	//
	// Available `CallOption`:
	//
	Currencies(context.Context, ...CallOption) ([]*models.Currency, error)

	// Ticker returns a ticker of specific market.
	//
	// Available `CallOption`:
	//
	Ticker(context.Context, string, ...CallOption) (*models.Ticker, error)

	// Tickers returns tickers of all markets.
	//
	// Available `CallOption`:
	//
	Tickers(context.Context, ...CallOption) (models.Tickers, error)

	// OrderBook returns order books of specific market.
	//
	// Available `CallOption`:
	//     AsksLimit(): returned sell orders limit, default to 20
	//     BidsLimit(): returned buy orders limit, default to 20
	OrderBook(context.Context, string, ...CallOption) (*models.OrderBook, error)

	// Depth returns depth of specific market.
	//
	// Available `CallOption`:
	//     Limit(): returned price levels limit, default to 300
	Depth(context.Context, string, ...CallOption) (*models.Depth, error)

	// Trades returns recent trades on market.
	//
	// Available `CallOption`:
	//     Timestamp(): the seconds elapsed since Unix epoch, set to return trades executed before the time only
	//     Time(): the time in Go format, set to return trades executed before the time only
	//     From(): trade id, set ot return trades created after the trade
	//     To(): trade id, set to return trades created before the trade
	//     OrderDesc(): use descending order by created time, default value
	//     OrderAsc(): use ascending order by created time
	//     Pagination(): do pagination & return metadata in header (default true)
	//     Page(): page number, applied for pagination (default 1)
	//     Limit(): returned limit (1~1000, default 50)
	//     Offset(): records to skip, not applied for pagination (default 0)
	Trades(context.Context, string, ...CallOption) ([]*models.Trade, error)

	// K returns OHLC chart of specific market.
	//
	// Available `CallOption`:
	//     Timestamp(): the seconds elapsed since Unix epoch, set to return data after the timestamp only
	//     Time(): the time in Go format, set to return data after the time only
	//     Period(): time period of K line in minute, default to 1
	//     PeriodDuration(): time period of K line in time.Duration format, default to 1*time.Minute
	//     Limit(): returned data points limit, default to 30
	K(context.Context, string, ...CallOption) ([]*models.Candle, error)

	// Time returns current sever time.
	//
	// Available `CallOption`:
	//
	Time(context.Context, ...CallOption) (time.Time, error)
}

PublicAPI provides an interface to the public MAX APIs. Public APIs can be invoked without authentication and rate limits.

type TickerSubscription

type TickerSubscription interface {
	Chan() <-chan *models.TickerEvent
	Close()
}

type TradeSubscription

type TradeSubscription interface {
	Chan() <-chan *models.TradeEvent
	Close()
}

type WebsocketClientOption

type WebsocketClientOption func(*wsClient)

func WSAuthToken

func WSAuthToken(accessKey, secretKey string) WebsocketClientOption

WSAuthToken passes API tokens to the websocket client

func WSLogging

func WSLogging(logger *log.Logger) WebsocketClientOption

WSLogging sets logger of the websocket client

func WSURL

func WSURL(url string) WebsocketClientOption

WSURL sets the websocket URL to connect to

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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