okcoin

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FUTURE_API_BASE_URL    = "https://www.okex.com/api/v1/"
	FUTURE_TICKER_URI      = "future_ticker.do?symbol=%s&contract_type=%s"
	FUTURE_DEPTH_URI       = "future_depth.do?symbol=%s&contract_type=%s"
	FUTURE_INDEX_PRICE     = "future_index.do?symbol=%s"
	FUTURE_USERINFO_URI    = "future_userinfo.do"
	FUTURE_CANCEL_URI      = "future_cancel.do"
	FUTURE_ORDER_INFO_URI  = "future_order_info.do"
	FUTURE_ORDERS_INFO_URI = "future_orders_info.do"
	FUTURE_POSITION_URI    = "future_position.do"
	FUTURE_TRADE_URI       = "future_trade.do"
	TRADES_URI             = "future_trades.do"
	FUTURE_ESTIMATED_PRICE = "future_estimated_price.do?symbol=%s"
)
View Source
const (
	V3_FUTURE_HOST_URL        = "https://www.okex.com/"
	V3_FUTURE_API_BASE_URL    = "api/futures/v3/"
	V3_SWAP_API_BASE_URL      = "api/swap/v3/"
	V3_FUTRUR_INSTRUMENTS_URL = "instruments"
	V3_FUTURE_TICKER_URI      = "instruments/%s/ticker"
	V3_SWAP_DEPTH_URI         = "instruments/%s/depth" //wtf api
	V3_FUTURE_DEPTH_URI       = "instruments/%s/book"  //wtf api
	V3_FUTURE_ESTIMATED_PRICE = "instruments/%s/estimated_price"
	V3_FUTURE_INDEX_PRICE     = "instruments/%s/index"
	V3_FUTURE_USERINFOS_URI   = "accounts/%s"
	V3_FUTURE_CANCEL_URI      = "cancel_order/%s/%s"
	V3_FUTURE_ORDER_INFO_URI  = "orders/%s/%s"
	V3_FUTURE_ORDERS_INFO_URI = "orders/%s"
	V3_FUTURE_POSITION_URI    = "%s/position"
	V3_FUTURE_ORDER_URI       = "order"
	V3_FUTURE_TRADES_URI      = "instruments/%s/trades"
	V3_FUTURE_FILLS_URI       = "fills"
	V3_EXCHANGE_RATE_URI      = "instruments/%s/rate"
	V3_GET_KLINE_URI          = "instruments/%s/candles"
)
View Source
const (
	EXCHANGE_NAME_COM = "okcoin.com"
)

Variables

View Source
var (
	OKEX_MARGIN_MODE_CROSSED = "crossed"
	OKEX_MARGIN_MODE_FIXED   = "fixed"
)

long and short position should be separated, current FuturePosition struct should be redesigned.

View Source
var KlineTypeSecondsMap = map[int]int{
	KLINE_PERIOD_1MIN:  60,
	KLINE_PERIOD_3MIN:  180,
	KLINE_PERIOD_5MIN:  300,
	KLINE_PERIOD_15MIN: 900,
	KLINE_PERIOD_30MIN: 1800,
	KLINE_PERIOD_60MIN: 3600,
	KLINE_PERIOD_1H:    3600,
	KLINE_PERIOD_2H:    7200,
	KLINE_PERIOD_4H:    14400,
	KLINE_PERIOD_6H:    21600,
	KLINE_PERIOD_12H:   43200,
	KLINE_PERIOD_1DAY:  86400,
	KLINE_PERIOD_1WEEK: 604800,
}
View Source
var OKexOrderTypeMap = map[int]int{
	ORDER_TYPE_LIMIT:     0,
	ORDER_TYPE_POST_ONLY: 1,
	ORDER_TYPE_FOK:       2,
	ORDER_TYPE_FAK:       3,
}

Functions

This section is empty.

Types

type AddChannelData

type AddChannelData struct {
	Result  bool
	Channel string
}

type DepthData

type DepthData struct {
	Asks      [][]string `json:"asks""`
	Bids      [][]string `json:"bids"`
	Timestamp int64
}

type IContractIDProvider

type IContractIDProvider interface {
	GetContractID(CurrencyPair, string) (string, error)
	ParseContractID(string) (CurrencyPair, string, error)
}

type KlineData

type KlineData [][]string

type OKCoinCN_API

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

func NewOKCoinCn

func NewOKCoinCn(client *http.Client, api_key, secret_key string) *OKCoinCN_API

func (*OKCoinCN_API) CancelOrder

func (ctx *OKCoinCN_API) CancelOrder(orderId string, currency CurrencyPair) (bool, error)

func (*OKCoinCN_API) GetAccount

func (ctx *OKCoinCN_API) GetAccount() (*Account, error)

func (*OKCoinCN_API) GetDepth

func (ctx *OKCoinCN_API) GetDepth(size int, currency CurrencyPair) (*Depth, error)

func (*OKCoinCN_API) GetExchangeName

func (ctx *OKCoinCN_API) GetExchangeName() string

func (*OKCoinCN_API) GetKlineRecords

func (ctx *OKCoinCN_API) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error)

func (*OKCoinCN_API) GetOneOrder

func (ctx *OKCoinCN_API) GetOneOrder(orderId string, currency CurrencyPair) (*Order, error)

func (*OKCoinCN_API) GetOrderHistorys

func (ctx *OKCoinCN_API) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize int) ([]Order, error)

func (*OKCoinCN_API) GetTicker

func (ctx *OKCoinCN_API) GetTicker(currency CurrencyPair) (*Ticker, error)

func (*OKCoinCN_API) GetTrades

func (ok *OKCoinCN_API) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)

func (*OKCoinCN_API) GetUnfinishOrders

func (ctx *OKCoinCN_API) GetUnfinishOrders(currency CurrencyPair) ([]Order, error)

func (*OKCoinCN_API) LimitBuy

func (ctx *OKCoinCN_API) LimitBuy(amount, price string, currency CurrencyPair) (*Order, error)

func (*OKCoinCN_API) LimitSell

func (ctx *OKCoinCN_API) LimitSell(amount, price string, currency CurrencyPair) (*Order, error)

func (*OKCoinCN_API) MarketBuy

func (ctx *OKCoinCN_API) MarketBuy(amount, price string, currency CurrencyPair) (*Order, error)

func (*OKCoinCN_API) MarketSell

func (ctx *OKCoinCN_API) MarketSell(amount, price string, currency CurrencyPair) (*Order, error)

type OKCoinCOM_API

type OKCoinCOM_API struct {
	OKCoinCN_API
}

func NewCOM

func NewCOM(client *http.Client, api_key, secret_key string) *OKCoinCOM_API

func (*OKCoinCOM_API) GetAccount

func (ctx *OKCoinCOM_API) GetAccount() (*Account, error)

func (*OKCoinCOM_API) GetExchangeName

func (ctx *OKCoinCOM_API) GetExchangeName() string

type OKEx

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

func NewOKEx

func NewOKEx(client *http.Client, api_key, secret_key string) *OKEx

func (*OKEx) FutureCancelOrder

func (ok *OKEx) FutureCancelOrder(currencyPair CurrencyPair, contractType, orderId string) (bool, error)

func (*OKEx) GetContractValue

func (ok *OKEx) GetContractValue(currencyPair CurrencyPair) (float64, error)

*

  • BTC: 100美元一张合约
  • LTC/ETH/ETC/BCH: 10美元一张合约

func (*OKEx) GetDeliveryTime

func (ok *OKEx) GetDeliveryTime() (int, int, int, int)

func (*OKEx) GetExchangeName

func (ok *OKEx) GetExchangeName() string

func (*OKEx) GetExchangeRate

func (ok *OKEx) GetExchangeRate() (float64, error)

func (*OKEx) GetFee

func (ok *OKEx) GetFee() (float64, error)

func (*OKEx) GetFutureDepth

func (ok *OKEx) GetFutureDepth(currencyPair CurrencyPair, contractType string, size int) (*Depth, error)

func (*OKEx) GetFutureEstimatedPrice

func (ok *OKEx) GetFutureEstimatedPrice(currencyPair CurrencyPair) (float64, error)

func (*OKEx) GetFutureIndex

func (ok *OKEx) GetFutureIndex(currencyPair CurrencyPair) (float64, error)

func (*OKEx) GetFutureOrder

func (ok *OKEx) GetFutureOrder(orderId string, currencyPair CurrencyPair, contractType string) (*FutureOrder, error)

func (*OKEx) GetFutureOrders

func (ok *OKEx) GetFutureOrders(orderIds []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKEx) GetFuturePosition

func (ok *OKEx) GetFuturePosition(currencyPair CurrencyPair, contractType string) ([]FuturePosition, error)

func (*OKEx) GetFutureTicker

func (ok *OKEx) GetFutureTicker(currencyPair CurrencyPair, contractType string) (*Ticker, error)

func (*OKEx) GetFutureUserinfo

func (ok *OKEx) GetFutureUserinfo() (*FutureAccount, error)

func (*OKEx) GetKlineRecords

func (ok *OKEx) GetKlineRecords(contract_type string, currencyPair CurrencyPair, period, size, since int) ([]FutureKline, error)

func (*OKEx) GetTrades

func (okFuture *OKEx) GetTrades(contract_type string, currencyPair CurrencyPair, since int64) ([]Trade, error)

func (*OKEx) GetUnfinishFutureOrders

func (ok *OKEx) GetUnfinishFutureOrders(currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKEx) PlaceFutureOrder

func (ok *OKEx) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error)

type OKExFutureWs

type OKExFutureWs struct {
	*WsBuilder
	sync.Once
	// contains filtered or unexported fields
}

func NewOKExFutureWs

func NewOKExFutureWs() *OKExFutureWs

func (*OKExFutureWs) SetCallbacks

func (okWs *OKExFutureWs) SetCallbacks(tickerCallback func(*FutureTicker),
	depthCallback func(*Depth),
	tradeCallback func(*Trade, string))

func (*OKExFutureWs) SubscribeDepth

func (okWs *OKExFutureWs) SubscribeDepth(pair CurrencyPair, contract string, size int) error

func (*OKExFutureWs) SubscribeTicker

func (okWs *OKExFutureWs) SubscribeTicker(pair CurrencyPair, contract string) error

func (*OKExFutureWs) SubscribeTrade

func (okWs *OKExFutureWs) SubscribeTrade(pair CurrencyPair, contract string) error

type OKExSpot

type OKExSpot struct {
	OKCoinCN_API
}

func NewOKExSpot

func NewOKExSpot(client *http.Client, accesskey, secretkey string) *OKExSpot

func (*OKExSpot) GetAccount

func (ctx *OKExSpot) GetAccount() (*Account, error)

func (*OKExSpot) GetExchangeName

func (ctx *OKExSpot) GetExchangeName() string

type OKExSpotWs

type OKExSpotWs struct {
	*WsBuilder
	sync.Once
	// contains filtered or unexported fields
}

func NewOKExSpotWs

func NewOKExSpotWs() *OKExSpotWs

func (*OKExSpotWs) SetCallbacks

func (okWs *OKExSpotWs) SetCallbacks(tickerCallback func(*Ticker),
	depthCallback func(*Depth),
	tradeCallback func(*Trade),
	klineCallback func(*Kline, int))

func (*OKExSpotWs) SubscribeDepth

func (okWs *OKExSpotWs) SubscribeDepth(pair CurrencyPair, size int) error

func (*OKExSpotWs) SubscribeKline

func (okWs *OKExSpotWs) SubscribeKline(pair CurrencyPair, period int) error

func (*OKExSpotWs) SubscribeTicker

func (okWs *OKExSpotWs) SubscribeTicker(pair CurrencyPair) error

func (*OKExSpotWs) SubscribeTrade

func (okWs *OKExSpotWs) SubscribeTrade(pair CurrencyPair) error

type OKExV3

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

NOTE: contracts 默认五分钟更新一次。 由于V3没有自动合约日期的映射,到了周五交割的时候,最好还是手动平仓,关闭策略,交割完后重启。

func NewOKExV3

func NewOKExV3(client *http.Client, api_key, secret_key, passphrase, endpoint string) *OKExV3

func (*OKExV3) FutureCancelOrder

func (okv3 *OKExV3) FutureCancelOrder(currencyPair CurrencyPair, contractType, orderID string) (bool, error)

func (*OKExV3) GetContract

func (okv3 *OKExV3) GetContract(currencyPair CurrencyPair, contractType string) (*futureContract, error)

func (*OKExV3) GetContractID

func (okv3 *OKExV3) GetContractID(currencyPair CurrencyPair, contractType string) (string, error)

func (*OKExV3) GetContractValue

func (okv3 *OKExV3) GetContractValue(currencyPair CurrencyPair) (float64, error)

func (*OKExV3) GetDeliveryTime

func (okv3 *OKExV3) GetDeliveryTime() (int, int, int, int)

func (*OKExV3) GetExchangeName

func (okv3 *OKExV3) GetExchangeName() string

func (*OKExV3) GetFee

func (okv3 *OKExV3) GetFee() (float64, error)

func (*OKExV3) GetFinishedFutureOrders

func (okv3 *OKExV3) GetFinishedFutureOrders(currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetFinishedFutureOrdersByIDs

func (okv3 *OKExV3) GetFinishedFutureOrdersByIDs(orderIDs []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetFutureDepth

func (okv3 *OKExV3) GetFutureDepth(currencyPair CurrencyPair, contractType string, size int) (*Depth, error)

func (*OKExV3) GetFutureEstimatedPrice

func (okv3 *OKExV3) GetFutureEstimatedPrice(currencyPair CurrencyPair) (float64, error)

func (*OKExV3) GetFutureIndex

func (okv3 *OKExV3) GetFutureIndex(currencyPair CurrencyPair) (float64, error)

func (*OKExV3) GetFutureOrder

func (okv3 *OKExV3) GetFutureOrder(orderID string, currencyPair CurrencyPair, contractType string) (*FutureOrder, error)

func (*OKExV3) GetFutureOrders

func (okv3 *OKExV3) GetFutureOrders(orderIds []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetFutureOrdersByIDsAndState

func (okv3 *OKExV3) GetFutureOrdersByIDsAndState(orderIDs []string, state string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetFutureOrdersByState

func (okv3 *OKExV3) GetFutureOrdersByState(state string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetFuturePosition

func (okv3 *OKExV3) GetFuturePosition(currencyPair CurrencyPair, contractType string) ([]FuturePosition, error)

func (*OKExV3) GetFutureTicker

func (okv3 *OKExV3) GetFutureTicker(currencyPair CurrencyPair, contractType string) (*Ticker, error)

func (*OKExV3) GetFutureUserinfo

func (okv3 *OKExV3) GetFutureUserinfo() (*FutureAccount, error)

GetFutureUserinfo 还只能查交割合约接口

func (*OKExV3) GetKlineRecords

func (okv3 *OKExV3) GetKlineRecords(contractType string, currencyPair CurrencyPair, period, size, since int) ([]FutureKline, error)

func (*OKExV3) GetTrades

func (okv3 *OKExV3) GetTrades(contractType string, currencyPair CurrencyPair, since int64) ([]Trade, error)

func (*OKExV3) GetUnfinishFutureOrders

func (okv3 *OKExV3) GetUnfinishFutureOrders(currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetUnfinishFutureOrdersByIDs

func (okv3 *OKExV3) GetUnfinishFutureOrdersByIDs(orderIDs []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

func (*OKExV3) GetUrlRoot

func (okv3 *OKExV3) GetUrlRoot() (url string)

func (*OKExV3) ParseContractID

func (okv3 *OKExV3) ParseContractID(contractID string) (CurrencyPair, string, error)

func (*OKExV3) PlaceFutureOrder

func (okv3 *OKExV3) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error)

func (*OKExV3) PlaceFutureOrder2

func (okv3 *OKExV3) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, orderType, openType, matchPrice, leverRate int) (string, error)

type OKExV3DataParser

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

func NewOKExV3DataParser

func NewOKExV3DataParser(contractIDProvider IContractIDProvider) *OKExV3DataParser

func (*OKExV3DataParser) ParseDepth

func (okV3dp *OKExV3DataParser) ParseDepth(depth *Depth, data interface{}, size int) (*Depth, error)

func (*OKExV3DataParser) ParseFutureOrder

func (okV3dp *OKExV3DataParser) ParseFutureOrder(data interface{}) (*FutureOrder, string, error)

func (*OKExV3DataParser) ParseFutureTicker

func (okV3dp *OKExV3DataParser) ParseFutureTicker(data interface{}) (*FutureTicker, error)

func (*OKExV3DataParser) ParseTrade

func (okV3dp *OKExV3DataParser) ParseTrade(trade *Trade, contractType string, data interface{}) (*Trade, string, error)

type OKExV3FutureWs

type OKExV3FutureWs struct {
	*WsBuilder
	sync.Once
	// contains filtered or unexported fields
}

func NewOKExV3FutureWs

func NewOKExV3FutureWs(contractIDProvider IContractIDProvider) *OKExV3FutureWs

func (*OKExV3FutureWs) DepthCallback

func (okV3Ws *OKExV3FutureWs) DepthCallback(depthCallback func(*Depth)) *OKExV3FutureWs

func (*OKExV3FutureWs) Login

func (okV3Ws *OKExV3FutureWs) Login(apiKey string, apiSecretKey string, passphrase string) error

func (*OKExV3FutureWs) OrderCallback

func (okV3Ws *OKExV3FutureWs) OrderCallback(orderCallback func(*FutureOrder, string)) *OKExV3FutureWs

func (*OKExV3FutureWs) SetCallbacks

func (okV3Ws *OKExV3FutureWs) SetCallbacks(tickerCallback func(*FutureTicker),
	depthCallback func(*Depth),
	tradeCallback func(*Trade, string),
	klineCallback func(*FutureKline, int),
	orderCallback func(*FutureOrder, string))

func (*OKExV3FutureWs) SubscribeDepth

func (okV3Ws *OKExV3FutureWs) SubscribeDepth(currencyPair CurrencyPair, contractType string, size int) error

func (*OKExV3FutureWs) SubscribeKline

func (okV3Ws *OKExV3FutureWs) SubscribeKline(currencyPair CurrencyPair, contractType string, period int) error

func (*OKExV3FutureWs) SubscribeOrder

func (okV3Ws *OKExV3FutureWs) SubscribeOrder(currencyPair CurrencyPair, contractType string) error

func (*OKExV3FutureWs) SubscribeTicker

func (okV3Ws *OKExV3FutureWs) SubscribeTicker(currencyPair CurrencyPair, contractType string) error

func (*OKExV3FutureWs) SubscribeTrade

func (okV3Ws *OKExV3FutureWs) SubscribeTrade(currencyPair CurrencyPair, contractType string) error

func (*OKExV3FutureWs) TickerCallback

func (okV3Ws *OKExV3FutureWs) TickerCallback(tickerCallback func(*FutureTicker)) *OKExV3FutureWs

func (*OKExV3FutureWs) TradeCallback

func (okV3Ws *OKExV3FutureWs) TradeCallback(tradeCallback func(*Trade, string)) *OKExV3FutureWs

type TickerData

type TickerData struct {
	Last      float64 `json:"last,string"`
	Sell      float64 `json:"sell,string"`
	Buy       float64 `json:"buy,string"`
	High      float64 `json:"high,string"`
	Low       float64 `json:"low,string"`
	Vol       float64 `json:"vol,string"`
	Timestamp int64
}

type TradeData

type TradeData [][]string

type WsBaseResp

type WsBaseResp struct {
	Channel string
	Data    json.RawMessage
}

Jump to

Keyboard shortcuts

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