babeltrader_okex_v3

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 15 Imported by: 2

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"
)

Variables

This section is empty.

Functions

func ConvertCandleToQuotes

func ConvertCandleToQuotes(table string, candles []Candle) ([]common.MessageRspCommon, error)

func ConvertChannelToSubUnsub

func ConvertChannelToSubUnsub(channel string) (*common.MessageSubUnsub, error)

func ConvertDepthToQuotes

func ConvertDepthToQuotes(table string, depths []Depth) ([]common.MessageRspCommon, error)

func ConvertOrderTradeOkex2Common

func ConvertOrderTradeOkex2Common(productType string, okexTrade *OrderTrade) (*common.MessageRspCommon, error)

func ConvertQuoteToChannel

func ConvertQuoteToChannel(quote *common.MessageQuote) (string, error)

func ConvertTickerToQuotes

func ConvertTickerToQuotes(table string, tickers []Ticker) ([]common.MessageRspCommon, error)

func GenWsSign

func GenWsSign(timestamp, method, requestPath, secret string) (string, error)

/////////////// sign /////////////////

func Headers

func Headers(request *http.Request, config *Config, timestamp string, sign string)

Set http request headers:

Accept: application/json
Content-Type: application/json; charset=UTF-8  (default)
Cookie: locale=en_US        (English)
OK-ACCESS-KEY: (Your setting)
OK-ACCESS-SIGN: (Use your setting, auto sign and add)
OK-ACCESS-TIMESTAMP: (Auto add)
OK-ACCESS-PASSPHRASE: Your setting

func HmacSha256Base64Signer

func HmacSha256Base64Signer(message string, secretKey string) (string, error)

signing a message using: hmac sha256 + base64

eg:
  message = Pre_hash function comment
  secretKey = E65791902180E9EF4510DB6A77F6EBAE

return signed string = TO6uwdqz+31SIPkd4I+9NiZGmVH74dXi+Fd5X0EzzSQ=

func HttpRequst

func HttpRequst(client *http.Client, config *Config, method string, requestPath string, params, result interface{}) (response *http.Response, err error)

Send a http request to remote server and get a response data

func IsoTime

func IsoTime() string

Get a iso time

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

func ParseRequestParams

func ParseRequestParams(params interface{}) (string, *bytes.Reader, error)

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

func PreHashString

func PreHashString(timestamp string, method string, requestPath string, body string) string

the pre hash string

eg:
  timestamp = 2018-03-08T10:59:25.789Z
  method  = POST
  request_path = /orders?before=2&limit=30
  body = {"product_id":"BTC-USD-0309","order_id":"377454671037440"}

return pre hash string = 2018-03-08T10:59:25.789ZPOST/orders?before=2&limit=30{"product_id":"BTC-USD-0309","order_id":"377454671037440"}

Types

type Candle

type Candle struct {
	InstrumentId string   `json:"instrument_id"`
	Candle       []string `json:"candle"`
}

type ChannelSplit

type ChannelSplit struct {
	ProductType string
	Info1       string
	Info2       string
	Symbol      string
	Contract    string
}

func SplitChannel

func SplitChannel(channel string) (*ChannelSplit, error)

/////////////// converter /////////////////

type Config

type Config struct {
	RestEndpoint   string   `json:"rest_endpoint"`
	WsEndpoint     string   `json:"ws_endpoint"`
	Key            string   `json:"key"`
	Secret         string   `json:"secret"`
	Passphrase     string   `json:"passphrase"`
	RestTimeoutSec int      `json:"rest_timeout_sec"`
	QuoteSubTopics []string `json:"quote_sub_topics"`
	TradeSubTopics []string `json:"trade_sub_topics"`
}

func LoadConfig

func LoadConfig(conf_path string) (*Config, error)

type Depth

type Depth struct {
	Asks         [][]interface{} `json:"asks"`
	Bids         [][]interface{} `json:"bids"`
	InstrumentId string          `json:"instrument_id"`
	Timestamp    string          `json:"timestamp"`
}

type FuturesTicker

type FuturesTicker struct {
	InstrumentId string `json:"instrument_id"`
	Last         string `json:"last"`
	BestBid      string `json:"best_bid"`
	BestAsk      string `json:"best_ask"`
	Open24H      string `json:"open_24h"`
	High24H      string `json:"high_24h"`
	Low24H       string `json:"low_24h"`
	Vol24H       string `json:"volume_24h"`
	Timestamp    string `json:"timestamp"`
}

type OkexMsgCallback

type OkexMsgCallback func(msg *RspCommon)

callback function type

type Order

type Order struct {
	ClientOid    string `json:"client_oid,omitempty"`
	InstrumentId string `json:"instrument_id"`
	Type         string `json:"type,omitempty"`
	Side         string `json:"side,omitempty"`
	Price        string `json:"price,omitempty"`
	Size         string `json:"size,omitempty"`
	Notional     string `json:"notional,omitempty"`
	Leverage     string `json:"leverage,omitempty"`
}

func ConvertCancelOrderCommon2Okex

func ConvertCancelOrderCommon2Okex(order *common.MessageOrder) (string, *Order, error)

RETURN: productType, okex.Order, error

func ConvertInsertOrderCommon2Okex

func ConvertInsertOrderCommon2Okex(order *common.MessageOrder) (string, *Order, error)

RETURN: productType, okex.Order, error

type OrderRet

type OrderRet struct {
	OrderId   string `json:"order_id"`
	ClientOid string `json:"client_oid"`
	ErrId     int    `json:"error_code"`
	ErrMsg    string `json:"error_message"`
	Result    bool   `json:"result"`
}

type OrderTrade

type OrderTrade struct {
	InstrumentId string `json:"instrument_id"`
	OrderId      string `json:"order_id"`
	Price        string `json:"price"`
	Size         string `json:"size"`
	Timestamp    string `json:"timestamp"`

	Notional       string `json:"notional"`
	Side           string `json:"side"`
	Type           string `json:"type"`
	FilledSize     string `json:"filled_size"`
	FilledNotional string `json:"filled_notional"`
	Status         string `json:"status"`
	MarginTrading  string `json:"margin_trading"`

	FilledQty   string `json:"filled_qty"`
	Fee         string `json:"fee"`
	PriceAvg    string `json:"price_avg"`
	ContractVal string `json:"contract_val"`
	Leverage    string `json:"leverage"`
}

type Position

type Position struct {
	MarginMode string            `json:"margin_mode"`
	Result     bool              `json:"result"`
	Holding    []PositionHolding `json:"holding"`
}

type PositionHolding

type PositionHolding struct {
	MarginMode           string `json:"margin_mode"`
	LongQty              string `json:"long_qty"`
	LongAvailQty         string `json:"long_avail_qty"`
	LongAvgCost          string `json:"long_avg_cost"`
	LongSettlementPrice  string `json:"long_settlement_price"`
	ShortQty             string `json:"short_qty"`
	ShortAvailQty        string `json:"short_avail_qty"`
	ShortAvgCost         string `json:"short_avg_cost"`
	ShortSettlementPrice string `json:"short_settlement_price"`
	InstrumentId         string `json:"instrument_id"`
	Leverage             string `json:"leverage"`
}

type Query

type Query struct {
	CurrencyId   string
	InstrumentId string
	ProductType  string
	OrderId      string
}

func ConvertQryCommon2Okex

func ConvertQryCommon2Okex(qry *common.MessageQuery) (*Query, error)

type QuoteApi

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

func NewQuoteApi

func NewQuoteApi(config *Config) *QuoteApi

func (*QuoteApi) OnActive

func (this *QuoteApi) OnActive(peer *cascade.Peer)

/////////////// Slot callbacks /////////////////

func (*QuoteApi) OnDepth

func (this *QuoteApi) OnDepth(msg *RspCommon)

func (*QuoteApi) OnDepthL2

func (this *QuoteApi) OnDepthL2(msg *RspCommon)

func (*QuoteApi) OnError

func (this *QuoteApi) OnError(msg *RspCommon)

func (*QuoteApi) OnHubByteMessage

func (this *QuoteApi) OnHubByteMessage(msg *cascade.HubByteMessage)

func (*QuoteApi) OnHubObjectMessage

func (this *QuoteApi) OnHubObjectMessage(msg *cascade.HubObjectMessage)

func (*QuoteApi) OnInactive

func (this *QuoteApi) OnInactive(peer *cascade.Peer)

func (*QuoteApi) OnKline

func (this *QuoteApi) OnKline(msg *RspCommon)

func (*QuoteApi) OnLogin

func (this *QuoteApi) OnLogin(msg *RspCommon)

/////////////// response and quotes /////////////////

func (*QuoteApi) OnRead

func (this *QuoteApi) OnRead(peer *cascade.Peer, message []byte)

func (*QuoteApi) OnSub

func (this *QuoteApi) OnSub(msg *RspCommon)

func (*QuoteApi) OnTicker

func (this *QuoteApi) OnTicker(msg *RspCommon)

func (*QuoteApi) OnUnsub

func (this *QuoteApi) OnUnsub(msg *RspCommon)

func (*QuoteApi) Ping

func (this *QuoteApi) Ping()

func (*QuoteApi) RegisterCallbacks

func (this *QuoteApi) RegisterCallbacks()

func (*QuoteApi) Run

func (this *QuoteApi) Run() error

func (*QuoteApi) SetSpi

func (this *QuoteApi) SetSpi(spi QuoteSpi) error

func (*QuoteApi) Subscribe

func (this *QuoteApi) Subscribe(topics []string) error

/////////////// requests /////////////////

func (*QuoteApi) Unsubscribe

func (this *QuoteApi) Unsubscribe(topics []string) error

type QuoteSpi

type QuoteSpi interface {
	OnConnected(peer *cascade.Peer)
	OnDisconnected(peer *cascade.Peer)

	OnLogin(msg *RspCommon)
	OnError(msg *RspCommon)

	OnSub(msg *RspCommon)
	OnUnsub(msg *RspCommon)

	OnKline(msg *RspCommon)
	OnTicker(msg *RspCommon)
	OnDepth(msg *RspCommon)
	OnDepthL2(msg *RspCommon)
}

type ReqCommon

type ReqCommon struct {
	Op   string      `json:"op"`
	Args interface{} `json:"args"`
}

type RspCommon

type RspCommon struct {
	Event   string      `json:"event"`
	Table   string      `json:"table"`
	Data    interface{} `json:"data"`
	Success bool        `json:"success"` // for login response
	Channel string      `json:"channel"` // for subscribe
}

type Ticker

type Ticker struct {
	InstrumentId string `json:"instrument_id"`
	Last         string `json:"last"`
	BestBid      string `json:"best_bid"`
	BestAsk      string `json:"best_ask"`
	Open24H      string `json:"open_24h"`
	High24H      string `json:"high_24h"`
	Low24H       string `json:"low_24h"`
	Vol24H       string `json:"volume_24h"`
	BaseVol24H   string `json:"base_volume_24h"`
	QuoteVol24H  string `json:"quote_volume_24h"`
	Timestamp    string `json:"timestamp"`
}

type TradeAccount

type TradeAccount struct {
	// futures
	MarginMode        string `json:"margin_mode"`
	TotalAvailBalance string `json:"total_avail_balance"`
	Equity            string `json:"equity"`
	MarginRatio       string `json:"margin_ratio"`

	// spot
	Balance   string `json:"balance"`
	Hold      string `json:"hold"`
	Available string `json:"available"`
}

type TradeApi

type TradeApi struct {
	HttpClient *http.Client
	// contains filtered or unexported fields
}

func NewTradeApi

func NewTradeApi(config *Config) *TradeApi

func (*TradeApi) CancelOrder

func (this *TradeApi) CancelOrder(order *Order, okexProductType, outsideOrderId string, result interface{}) (response *http.Response, err error)

func (*TradeApi) InsertOrder

func (this *TradeApi) InsertOrder(order *Order, okexProductType string, result interface{}) (response *http.Response, err error)

func (*TradeApi) Login

func (this *TradeApi) Login() error

/////////////// requests /////////////////

func (*TradeApi) OnAccount

func (this *TradeApi) OnAccount(msg *RspCommon)

func (*TradeApi) OnActive

func (this *TradeApi) OnActive(peer *cascade.Peer)

/////////////// Slot callbacks /////////////////

func (*TradeApi) OnError

func (this *TradeApi) OnError(msg *RspCommon)

func (*TradeApi) OnHubByteMessage

func (this *TradeApi) OnHubByteMessage(msg *cascade.HubByteMessage)

func (*TradeApi) OnHubObjectMessage

func (this *TradeApi) OnHubObjectMessage(msg *cascade.HubObjectMessage)

func (*TradeApi) OnInactive

func (this *TradeApi) OnInactive(peer *cascade.Peer)

func (*TradeApi) OnLogin

func (this *TradeApi) OnLogin(msg *RspCommon)

/////////////// response and quotes /////////////////

func (*TradeApi) OnOrder

func (this *TradeApi) OnOrder(msg *RspCommon)

func (*TradeApi) OnPosition

func (this *TradeApi) OnPosition(msg *RspCommon)

func (*TradeApi) OnRead

func (this *TradeApi) OnRead(peer *cascade.Peer, message []byte)

func (*TradeApi) OnSub

func (this *TradeApi) OnSub(msg *RspCommon)

func (*TradeApi) OnUnsub

func (this *TradeApi) OnUnsub(msg *RspCommon)

func (*TradeApi) Ping

func (this *TradeApi) Ping()

func (*TradeApi) QueryAccount

func (this *TradeApi) QueryAccount(qry *Query, result interface{}) (response *http.Response, err error)

func (*TradeApi) QueryOrder

func (this *TradeApi) QueryOrder(qry *Query, result interface{}) (response *http.Response, err error)

func (*TradeApi) QueryPosition

func (this *TradeApi) QueryPosition(qry *Query, result interface{}) (response *http.Response, err error)

func (*TradeApi) RegisterCallbacks

func (this *TradeApi) RegisterCallbacks()

func (*TradeApi) Run

func (this *TradeApi) Run() error

func (*TradeApi) SetSpi

func (this *TradeApi) SetSpi(spi TradeSpi) error

func (*TradeApi) Subscribe

func (this *TradeApi) Subscribe(topics []string) error

func (*TradeApi) Unsubscribe

func (this *TradeApi) Unsubscribe(topics []string) error

type TradeSpi

type TradeSpi interface {
	OnConnected(peer *cascade.Peer)
	OnDisconnected(peer *cascade.Peer)

	OnLogin(msg *RspCommon)
	OnError(msg *RspCommon)

	OnSub(msg *RspCommon)
	OnUnsub(msg *RspCommon)

	OnOrder(msg *RspCommon)
	OnPosition(msg *RspCommon)
	OnAccount(msg *RspCommon)
}

Jump to

Keyboard shortcuts

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