okex

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/*
	  http headers
	*/
	OK_ACCESS_KEY        = "OK-ACCESS-KEY"
	OK_ACCESS_SIGN       = "OK-ACCESS-SIGN"
	OK_ACCESS_TIMESTAMP  = "OK-ACCESS-TIMESTAMP"
	OK_ACCESS_PASSPHRASE = "OK-ACCESS-PASSPHRASE"

	/**
	  paging params
	*/
	OK_FROM  = "OK-FROM"
	OK_TO    = "OK-TO"
	OK_LIMIT = "OK-LIMIT"

	CONTENT_TYPE = "Content-Type"
	ACCEPT       = "Accept"
	COOKIE       = "Cookie"
	LOCALE       = "locale="

	APPLICATION_JSON      = "application/json"
	APPLICATION_JSON_UTF8 = "application/json; charset=UTF-8"

	/**
	 *
	 * i18n: internationalization
	 *
	 **/
	ENGLISH            = "en_US"
	SIMPLIFIED_CHINESE = "zh_CN"
	//zh_TW || zh_HK
	TRADITIONAL_CHINESE = "zh_HK"

	/*
	  http methods
	*/
	GET    = "GET"
	POST   = "POST"
	DELETE = "DELETE"

	/*
	 others
	*/
	ResultDataJsonString = "resultDataJsonString"
	ResultPageJsonString = "resultPageJsonString"

	BTC_USD_SWAP = "BTC-USD-SWAP"
	LTC_USD_SWAP = "LTC-USD-SWAP"
	ETH_USD_SWAP = "ETH-USD-SWAP"
	ETC_USD_SWAP = "ETC-USD-SWAP"
	BCH_USD_SWAP = "BCH-USD-SWAP"
	BSV_USD_SWAP = "BSV-USD-SWAP"
	EOS_USD_SWAP = "EOS-USD-SWAP"
	XRP_USD_SWAP = "XRP-USD-SWAP"

	/*Rest Endpoint*/
	ENDPOINT              = "https://www.okx.com"
	GET_ACCOUNTS          = "/api/swap/v3/accounts"
	PLACE_ORDER           = "/api/swap/v3/order"
	CANCEL_ORDER          = "/api/swap/v3/cancel_order/%s/%s"
	GET_ORDER             = "/api/swap/v3/orders/%s/%s"
	GET_POSITION          = "/api/swap/v3/%s/position"
	GET_DEPTH             = "/api/swap/v3/instruments/%s/depth?size=%d"
	GET_TICKER            = "/api/swap/v3/instruments/%s/ticker"
	GET_UNFINISHED_ORDERS = "/api/swap/v3/orders/%s?status=%d&from=%d&limit=%d"
)
View Source
const (
	SUB_ACCOUNT = iota //子账户
	SPOT               // 币币交易

	FUTURE      //交割合约
	C2C         //法币
	SPOT_MARGIN //币币杠杆交易
	WALLET      // 资金账户

	TIPS //余币宝
	SWAP //永续合约

	OPTION //期权
)
View Source
const (
	WITHDRAWAL_OKCOIN int = 2 //提币到okcoin国际站
	WITHDRAWAL_OKEx       = 3 //提币到okex,站内提币
	WITHDRAWAL_COIN       = 4 //提币到数字货币地址,跨平台提币或者提到自己钱包
)

Variables

This section is empty.

Functions

func GetDueTimestamp

func GetDueTimestamp(timestamp int64) (flag int, dueTimestamp map[string]int64)

func GetRealContractTypeBoard

func GetRealContractTypeBoard() map[string][]string

Types

type DepositAddress

type DepositAddress struct {
	Address     string `json:"address"`
	Tag         string `json:"tag"`
	PaymentId   string `json:"payment_id"`
	Currency    string `json:"currency"`
	CanDeposit  int    `json:"can_deposit"`
	CanWithdraw int    `json:"can_withdraw"`
	Memo        string `json:"memo"` //eos need
}

type DepositWithDrawHistory

type DepositWithDrawHistory struct {
	WithdrawalId string    `json:"withdrawal_id,omitempty"`
	Currency     string    `json:"currency"`
	Txid         string    `json:"txid"`
	Amount       float64   `json:"amount,string"`
	From         string    `json:"from,omitempty"`
	To           string    `json:"to"`
	Memo         string    `json:"memo,omitempty"`
	Fee          string    `json:"fee"`
	Status       int       `json:"status,string"`
	Timestamp    time.Time `json:"timestamp"`
}

type Future

type Future struct {
	*OKEx
	Contracts FutureContracts

	Locker sync.Locker
	// contains filtered or unexported fields
}

func (*Future) CancelOrder

func (future *Future) CancelOrder(order *FutureOrder) ([]byte, error)

func (*Future) GetAccount

func (future *Future) GetAccount() (*FutureAccount, []byte, error)

func (*Future) GetContract

func (future *Future) GetContract(pair Pair, contractType string) (*FutureContract, error)

func (*Future) GetDepth

func (future *Future) GetDepth(
	pair Pair,
	contractType string,
	size int,
) (*FutureDepth, []byte, error)

func (*Future) GetExchangeName

func (future *Future) GetExchangeName() string

func (*Future) GetIndex

func (future *Future) GetIndex(pair Pair) (float64, []byte, error)

func (*Future) GetInstrumentId

func (future *Future) GetInstrumentId(pair Pair, contractAlias string) string

获取instrument_id

func (*Future) GetKlineRecords

func (future *Future) GetKlineRecords(
	contractType string,
	pair Pair,
	period,
	size,
	since int,
) ([]*FutureKline, []byte, error)

*

  • since : 单位毫秒,开始时间

*

func (*Future) GetLimit

func (future *Future) GetLimit(pair Pair, contractType string) (float64, float64, error)

func (*Future) GetMark

func (future *Future) GetMark(pair Pair, contractType string) (float64, []byte, error)

func (*Future) GetOrder

func (future *Future) GetOrder(order *FutureOrder) ([]byte, error)

func (*Future) GetOrders

func (future *Future) GetOrders(
	pair Pair,
	contractType string,
) ([]*FutureOrder, []byte, error)

func (*Future) GetPairFlow

func (future *Future) GetPairFlow(pair Pair) ([]*FutureAccountItem, []byte, error)

func (*Future) GetTicker

func (future *Future) GetTicker(pair Pair, contractType string) (*FutureTicker, []byte, error)

func (*Future) GetTrades

func (future *Future) GetTrades(pair Pair, contractType string) ([]*Trade, []byte, error)

func (*Future) KeepAlive

func (future *Future) KeepAlive()

func (*Future) PlaceOrder

func (future *Future) PlaceOrder(order *FutureOrder) ([]byte, error)

type Margin

type Margin struct {
	*OKEx
}

func (*Margin) CancelOrder

func (margin *Margin) CancelOrder(order *Order) ([]byte, error)

func (*Margin) GetAccount

func (margin *Margin) GetAccount(pair Pair) (*MarginAccount, []byte, error)

private api

func (*Margin) GetDepth

func (margin *Margin) GetDepth(pair Pair, size int) (*Depth, []byte, error)

func (*Margin) GetExchangeRule

func (margin *Margin) GetExchangeRule(pair Pair) (*Rule, []byte, error)

func (*Margin) GetKlineRecords

func (margin *Margin) GetKlineRecords(pair Pair, period, size, since int) ([]*Kline, []byte, error)

func (*Margin) GetLoan

func (margin *Margin) GetLoan(loan *Loan) ([]byte, error)

func (*Margin) GetOrder

func (margin *Margin) GetOrder(order *Order) ([]byte, error)

func (*Margin) GetOrders

func (margin *Margin) GetOrders(pair Pair) ([]*Order, error)

func (*Margin) GetTicker

func (margin *Margin) GetTicker(pair Pair) (*Ticker, []byte, error)

public api

func (*Margin) GetUnFinishOrders

func (margin *Margin) GetUnFinishOrders(pair Pair) ([]*Order, []byte, error)

func (*Margin) KeepAlive

func (margin *Margin) KeepAlive()

util api

func (*Margin) PlaceLoan

func (margin *Margin) PlaceLoan(loan *Loan) ([]byte, error)

func (*Margin) PlaceOrder

func (margin *Margin) PlaceOrder(order *Order) ([]byte, error)

func (*Margin) ReturnLoan

func (margin *Margin) ReturnLoan(loan *Loan) ([]byte, error)

type OKEx

type OKEx struct {
	Spot   *Spot
	Margin *Margin
	Swap   *Swap
	Future *Future
	Wallet *Wallet
	// contains filtered or unexported fields
}

func New

func New(config *APIConfig) *OKEx

func (*OKEx) BuildRequestBody

func (ok *OKEx) BuildRequestBody(params interface{}) (string, *bytes.Reader, error)

Get a http request body is a json string and a byte array.

func (*OKEx) ContractTimestamp

func (ok *OKEx) ContractTimestamp(
	timestamp int64,
	contractType string,
) (
	startTimestamp int64,
	swapTimestamp int64,
	dueTimestamp int64,
)

func (*OKEx) DoRequest

func (ok *OKEx) DoRequest(
	httpMethod,
	uri,
	reqBody string,
	response interface{},
) ([]byte, error)

func (*OKEx) DoRequestMarket

func (ok *OKEx) DoRequestMarket(
	httpMethod,
	uri,
	reqBody string,
	response interface{},
) ([]byte, error)

func (*OKEx) GetExchangeName

func (ok *OKEx) GetExchangeName() string

func (*OKEx) IsoTime

func (ok *OKEx) IsoTime() string

Get a iso time

eg: 2018-03-16T18:02:48.284Z

type OKexFutureWebsocket

type OKexFutureWebsocket struct {
	// contains filtered or unexported fields
}

func (*OKexFutureWebsocket) Close

func (this *OKexFutureWebsocket) Close()

func (*OKexFutureWebsocket) Init

func (this *OKexFutureWebsocket) Init()

func (*OKexFutureWebsocket) Login

func (this *OKexFutureWebsocket) Login(config *APIConfig) error

func (*OKexFutureWebsocket) Start

func (this *OKexFutureWebsocket) Start()

func (*OKexFutureWebsocket) Subscribe

func (this *OKexFutureWebsocket) Subscribe(channel string) error

func (*OKexFutureWebsocket) Unsubscribe

func (this *OKexFutureWebsocket) Unsubscribe(channel string) error

type OrderResponse

type OrderResponse struct {
	ClientOid      string  `json:"client_oid"`
	OrderId        string  `json:"order_id"`
	Price          float64 `json:"price,string"`
	Size           float64 `json:"size,string"`
	Notional       string  `json:"notional"`
	Side           string  `json:"side"`
	Type           string  `json:"type"`
	FilledSize     string  `json:"filled_size"`
	FilledNotional string  `json:"filled_notional"`
	PriceAvg       string  `json:"price_avg"`
	State          int     `json:"state,string"`
	OrderType      int     `json:"order_type,string"`
	Timestamp      string  `json:"timestamp"`
}

type PlaceOrderParam

type PlaceOrderParam struct {
	ClientOid     string  `json:"client_oid"`
	Type          string  `json:"type"`
	Side          string  `json:"side"`
	InstrumentId  string  `json:"instrument_id"`
	OrderType     int     `json:"order_type"`
	Price         float64 `json:"price"`
	Size          float64 `json:"size"`
	Notional      float64 `json:"notional"`
	MarginTrading string  `json:"margin_trading,omitempty"`
}

type Spot

type Spot struct {
	*OKEx
}

func (*Spot) CancelOrder

func (spot *Spot) CancelOrder(order *Order) ([]byte, error)

orderId can set client oid or orderId

func (*Spot) GetAccount

func (spot *Spot) GetAccount() (*Account, []byte, error)

private api

func (*Spot) GetDepth

func (spot *Spot) GetDepth(pair Pair, size int) (*Depth, []byte, error)

func (*Spot) GetExchangeRule

func (spot *Spot) GetExchangeRule(pair Pair) (*Rule, []byte, error)

func (*Spot) GetKlineRecords

func (spot *Spot) GetKlineRecords(pair Pair, period, size, since int) ([]*Kline, []byte, error)

func (*Spot) GetOHLCs

func (spot *Spot) GetOHLCs(symbol string, period, size, since int) ([]*OHLC, []byte, error)

func (*Spot) GetOrder

func (spot *Spot) GetOrder(order *Order) ([]byte, error)

orderId can set client oid or orderId

func (*Spot) GetOrders

func (spot *Spot) GetOrders(pair Pair) ([]*Order, error)

func (*Spot) GetTicker

func (spot *Spot) GetTicker(pair Pair) (*Ticker, []byte, error)

public api

func (*Spot) GetTrades

func (spot *Spot) GetTrades(pair Pair, since int64) ([]*Trade, error)

非个人,整个交易所的交易记录

func (*Spot) GetUnFinishOrders

func (spot *Spot) GetUnFinishOrders(pair Pair) ([]*Order, []byte, error)

func (*Spot) KeepAlive

func (spot *Spot) KeepAlive()

util api

func (*Spot) PlaceOrder

func (spot *Spot) PlaceOrder(order *Order) ([]byte, error)

type Swap

type Swap struct {
	*OKEx
	sync.Locker
	// contains filtered or unexported fields
}

func (*Swap) AddMargin

func (swap *Swap) AddMargin(pair Pair, openType FutureType, marginAmount float64) ([]byte, error)

func (*Swap) CancelOrder

func (swap *Swap) CancelOrder(order *SwapOrder) ([]byte, error)

func (*Swap) GetAccount

func (swap *Swap) GetAccount() (*SwapAccount, []byte, error)

func (*Swap) GetAccountFlow

func (swap *Swap) GetAccountFlow() ([]*SwapAccountItem, []byte, error)

func (*Swap) GetContract

func (swap *Swap) GetContract(pair Pair) *SwapContract

func (*Swap) GetDepth

func (swap *Swap) GetDepth(pair Pair, size int) (*SwapDepth, []byte, error)

func (*Swap) GetFundingFee

func (swap *Swap) GetFundingFee(pair Pair) (float64, error)

func (*Swap) GetFundingFees

func (swap *Swap) GetFundingFees(pair Pair) ([][]interface{}, []byte, error)

func (*Swap) GetKline

func (swap *Swap) GetKline(pair Pair, period, size, since int) ([]*SwapKline, []byte, error)

func (*Swap) GetLimit

func (swap *Swap) GetLimit(pair Pair) (float64, float64, error)

func (*Swap) GetOpenAmount

func (swap *Swap) GetOpenAmount(pair Pair) (float64, int64, []byte, error)

func (*Swap) GetOrder

func (swap *Swap) GetOrder(order *SwapOrder) ([]byte, error)

func (*Swap) GetOrders

func (swap *Swap) GetOrders(pair Pair) ([]*SwapOrder, []byte, error)

func (*Swap) GetPairFlow

func (swap *Swap) GetPairFlow(pair Pair) ([]*SwapAccountItem, []byte, error)

func (*Swap) GetPosition

func (swap *Swap) GetPosition(pair Pair, openType FutureType) (*SwapPosition, []byte, error)

func (*Swap) GetTicker

func (swap *Swap) GetTicker(pair Pair) (*SwapTicker, []byte, error)

func (*Swap) GetUnFinishOrders

func (swap *Swap) GetUnFinishOrders(pair Pair) ([]*SwapOrder, []byte, error)

func (*Swap) KeepAlive

func (swap *Swap) KeepAlive()

func (*Swap) PlaceOrder

func (swap *Swap) PlaceOrder(order *SwapOrder) ([]byte, error)

func (*Swap) ReduceMargin

func (swap *Swap) ReduceMargin(pair Pair, openType FutureType, marginAmount float64) ([]byte, error)

type TransferParameter

type TransferParameter struct {
	Currency       string  `json:"currency"`
	From           int     `json:"from"`
	To             int     `json:"to"`
	Amount         float64 `json:"amount"`
	SubAccount     string  `json:"sub_account"`
	InstrumentId   string  `json:"instrument_id"`
	ToInstrumentId string  `json:"to_instrument_id"`
}

type Wallet

type Wallet struct {
	*OKEx
}

func (*Wallet) GetAccount

func (ok *Wallet) GetAccount() (*Account, []byte, error)

func (*Wallet) GetDepositAddress

func (ok *Wallet) GetDepositAddress(currency Currency) ([]DepositAddress, []byte, error)

func (*Wallet) GetDepositHistory

func (ok *Wallet) GetDepositHistory(currency *Currency) ([]DepositWithDrawHistory, []byte, error)

func (*Wallet) GetWithDrawalFee

func (ok *Wallet) GetWithDrawalFee(currency *Currency) ([]WithdrawFee, []byte, error)

func (*Wallet) GetWithDrawalHistory

func (ok *Wallet) GetWithDrawalHistory(currency *Currency) ([]DepositWithDrawHistory, []byte, error)

func (*Wallet) Transfer

func (ok *Wallet) Transfer(param TransferParameter) error
解释说明

from或to指定为0时,sub_account为必填项。 当from为0时,to只能填6,即子账户的资金账户只能转到母账户的资金账户。 当from指定为6,to指定为1-9,且sub_account填写子账户名时,可从母账户直接划转至子账户对应的币币、合约等账户。 from或to指定为5时,instrument_id为必填项。

func (*Wallet) Withdrawal

func (ok *Wallet) Withdrawal(param WithdrawParameter) (withdrawId string, resp []byte, err error)

认证过的数字货币地址、邮箱或手机号。某些数字货币地址格式为:地址+标签,例:"ARDOR-7JF3-8F2E-QUWZ-CAN7F:123456"

type WithdrawFee

type WithdrawFee struct {
	Currency string `json:"currency"`
	MaxFee   string `json:"max_fee"`
	MinFee   string `json:"min_fee"`
}

type WithdrawParameter

type WithdrawParameter struct {
	Currency    string  `json:"currency"`
	Amount      float64 `json:"amount,string"`
	Destination int     `json:"destination"` //提币到(2:OKCoin国际 3:OKEx 4:数字货币地址)
	ToAddress   string  `json:"to_address"`
	TradePwd    string  `json:"trade_pwd"`
	Fee         string  `json:"fee"`
}

Jump to

Keyboard shortcuts

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