goex

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: MIT Imports: 30 Imported by: 0

README

goex

goex目标

goex项目是为了统一并标准化各个数字资产交易平台的接口而设计,同一个策略可以随时切换到任意一个交易平台,而不需要更改任何代码。

English

wiki文档

文档

goex已支持交易所 23+

交易所 行情接口 交易接口 版本号
huobi.pro Y Y 1
hbdm.com Y (REST / WS) Y 1
okex.com (spot/future) Y (REST / WS) Y 1
okex.com (swap future) Y Y 2
binance.com Y Y 1
kucoin.com Y Y 1
bitstamp.net Y Y 1
bitfinex.com Y Y 1
zb.com Y Y 1
kraken.com Y Y *
poloniex.com Y Y *
big.one Y Y 2|3
hitbtc.com Y Y *
coinex.com Y Y 1
exx.com Y Y 1
bithumb.com Y Y *
gate.io Y N 1
bittrex.com Y N 1.1

安装goex库

go get

go get github.com/nntaoli-project/goex

建议go mod 管理依赖

require (
          github.com/nntaoli-project/goex latest
)

注意事项

  1. 推荐使用GoLand开发。
  2. 推荐关闭自动格式化功能,代码请使用go fmt 格式化.
  3. 不建议对现已存在的文件进行重新格式化,这样会导致commit特别糟糕。
  4. 请用OrderID2这个字段代替OrderID
  5. 请不要使用deprecated关键字标注的方法和字段,后面版本可能随时删除的

donate

BTC:13cBHLk6B7t3Uj7caJbCwv1UaiuiA6Qx8z

LTC:LVxM7y1K2dnpuNBU42ei3dKzPySf4VAm1H

ETH:0x98573ddb33cdddce480c3bc1f9279ccd88ca1e93

欢迎为作者付一碗面钱

微信 支付宝

Documentation

Index

Constants

View Source
const (
	OPEN_BUY   = 1 + iota //开多
	OPEN_SELL             //开空
	CLOSE_BUY             //平多
	CLOSE_SELL            //平空
)
View Source
const (
	KLINE_PERIOD_1MIN = 1 + iota
	KLINE_PERIOD_3MIN
	KLINE_PERIOD_5MIN
	KLINE_PERIOD_15MIN
	KLINE_PERIOD_30MIN
	KLINE_PERIOD_60MIN
	KLINE_PERIOD_1H
	KLINE_PERIOD_2H
	KLINE_PERIOD_3H
	KLINE_PERIOD_4H
	KLINE_PERIOD_6H
	KLINE_PERIOD_8H
	KLINE_PERIOD_12H
	KLINE_PERIOD_1DAY
	KLINE_PERIOD_3DAY
	KLINE_PERIOD_1WEEK
	KLINE_PERIOD_1MONTH
	KLINE_PERIOD_1YEAR
)

k线周期

View Source
const (
	ORDER_FEATURE_ORDINARY = 0 + iota
	ORDER_FEATURE_POST_ONLY
	ORDER_FEATURE_FOK
	ORDER_FEATURE_IOC
	ORDER_FEATURE_FAK
	ORDER_FEATURE_LIMIT
)
View Source
const (
	ORDER_TYPE_LIMIT = 1 + iota
	ORDER_TYPE_MARKET
)
View Source
const (
	KUCOIN          = "kucoin.com"
	OKCOIN_COM      = "okcoin.com"
	OKEX            = "okex.com"
	OKEX_V3         = "okex.com_v3"
	OKEX_FUTURE     = "okex.com_future"
	OKEX_SWAP       = "okex.com_swap"
	HUOBI           = "huobi.com"
	HUOBI_PRO       = "huobi.pro"
	BITSTAMP        = "bitstamp.net"
	KRAKEN          = "kraken.com"
	ZB              = "zb.com"
	BITFINEX        = "bitfinex.com"
	BINANCE         = "binance.com"
	BINANCE_SWAP    = "binance.com_swap"
	BINANCE_FUTURES = "binance.com_futures"
	POLONIEX        = "poloniex.com"
	COINEX          = "coinex.com"
	BITHUMB         = "bithumb.com"
	GATEIO          = "gate.io"
	BITTREX         = "bittrex.com"
	GDAX            = "gdax.com"
	BIGONE          = "big.one"
	FCOIN           = "fcoin.com"
	FCOIN_MARGIN    = "fcoin.com_margin"
	FMEX            = "fmex.com"
	HITBTC          = "hitbtc.com"
	BITMEX          = "bitmex.com"
	BITMEX_TEST     = "testnet.bitmex.com"
	CRYPTOPIA       = "cryptopia.co.nz"
	HBDM            = "hbdm.com"
	HBDM_SWAP       = "hbdm.com_swap"
	COINBENE        = "coinbene.com"
	ATOP            = "a.top"
	BITGET_SWAP     = "bitget_swap"
)

exchanges const

View Source
const (
	SUB_ACCOUNT = iota //子账户
	SPOT               // 币币交易

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

	TIPS      //余币宝
	SWAP      //永续合约
	SWAP_USDT //usdt本位永续合约
)

Variables

View Source
var (
	API_ERR                      = ApiError{ErrCode: "EX_ERR_0000", ErrMsg: "unknown error"}
	HTTP_ERR_CODE                = ApiError{ErrCode: "HTTP_ERR_0001", ErrMsg: "http request error"}
	EX_ERR_API_LIMIT             = ApiError{ErrCode: "EX_ERR_1000", ErrMsg: "api limited"}
	EX_ERR_SIGN                  = ApiError{ErrCode: "EX_ERR_0001", ErrMsg: "signature error"}
	EX_ERR_NOT_FIND_SECRETKEY    = ApiError{ErrCode: "EX_ERR_0002", ErrMsg: "not find secretkey"}
	EX_ERR_NOT_FIND_APIKEY       = ApiError{ErrCode: "EX_ERR_0003", ErrMsg: "not find apikey"}
	EX_ERR_INSUFFICIENT_BALANCE  = ApiError{ErrCode: "EX_ERR_0004", ErrMsg: "Insufficient Balance"}
	EX_ERR_PLACE_ORDER_FAIL      = ApiError{ErrCode: "EX_ERR_0005", ErrMsg: "place order failure"}
	EX_ERR_CANCEL_ORDER_FAIL     = ApiError{ErrCode: "EX_ERR_0006", ErrMsg: "cancel order failure"}
	EX_ERR_INVALID_CURRENCY_PAIR = ApiError{ErrCode: "EX_ERR_0007", ErrMsg: "invalid currency pair"}
	EX_ERR_NOT_FIND_ORDER        = ApiError{ErrCode: "EX_ERR_0008", ErrMsg: "not find order"}
	EX_ERR_SYMBOL_ERR            = ApiError{ErrCode: "EX_ERR_0009", ErrMsg: "symbol error"}
)
View Source
var (
	THIS_WEEK_CONTRACT  = "this_week"  //周合约
	NEXT_WEEK_CONTRACT  = "next_week"  //次周合约
	QUARTER_CONTRACT    = "quarter"    //季度合约
	BI_QUARTER_CONTRACT = "bi_quarter" // NEXT QUARTER
	SWAP_CONTRACT       = "swap"       //永续合约
	SWAP_USDT_CONTRACT  = "swap-usdt"
)
View Source
var (
	UNKNOWN = Currency{"UNKNOWN", ""}
	CNY     = Currency{"CNY", ""}
	USD     = Currency{"USD", ""}
	USDT    = Currency{"USDT", ""}
	PAX     = Currency{"PAX", "https://www.paxos.com/"}
	USDC    = Currency{"USDC", "https://www.centre.io/"}
	EUR     = Currency{"EUR", ""}
	KRW     = Currency{"KRW", ""}
	JPY     = Currency{"JPY", ""}
	BTC     = Currency{"BTC", "https://bitcoin.org/"}
	XBT     = Currency{"XBT", ""}
	BCC     = Currency{"BCC", ""}
	BCH     = Currency{"BCH", ""}
	BCX     = Currency{"BCX", ""}
	LTC     = Currency{"LTC", ""}
	ETH     = Currency{"ETH", ""}
	ETC     = Currency{"ETC", ""}
	EOS     = Currency{"EOS", ""}
	BTS     = Currency{"BTS", ""}
	QTUM    = Currency{"QTUM", ""}
	SC      = Currency{"SC", ""}
	ANS     = Currency{"ANS", ""}
	ZEC     = Currency{"ZEC", ""}
	DCR     = Currency{"DCR", ""}
	XRP     = Currency{"XRP", ""}
	BTG     = Currency{"BTG", ""}
	BCD     = Currency{"BCD", ""}
	NEO     = Currency{"NEO", ""}
	HSR     = Currency{"HSR", ""}
	BSV     = Currency{"BSV", ""}
	OKB     = Currency{"OKB", "OKB is a global utility token issued by OK Blockchain Foundation"}
	HT      = Currency{"HT", "HuoBi Token"}
	BNB     = Currency{"BNB", "BNB, or Binance Coin, is a cryptocurrency created by Binance."}
	TRX     = Currency{"TRX", ""}
	GBP     = Currency{"GBP", ""}
	XLM     = Currency{"XLM", ""}
	DOT     = Currency{"DOT", ""}
	DASH    = Currency{"DASH", ""}
	CRV     = Currency{"CRV", ""}
	ALGO    = Currency{"ALGO", ""}

	//currency pair
	BTC_KRW = CurrencyPair{CurrencyA: BTC, CurrencyB: KRW, AmountTickSize: 2, PriceTickSize: 1}
	ETH_KRW = CurrencyPair{CurrencyA: ETH, CurrencyB: KRW, AmountTickSize: 2, PriceTickSize: 2}
	ETC_KRW = CurrencyPair{CurrencyA: ETC, CurrencyB: KRW, AmountTickSize: 2, PriceTickSize: 2}
	LTC_KRW = CurrencyPair{CurrencyA: LTC, CurrencyB: KRW, AmountTickSize: 2, PriceTickSize: 2}
	BCH_KRW = CurrencyPair{CurrencyA: BCH, CurrencyB: KRW, AmountTickSize: 2, PriceTickSize: 2}

	BTC_USD  = CurrencyPair{CurrencyA: BTC, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 1}
	LTC_USD  = CurrencyPair{CurrencyA: LTC, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	ETH_USD  = CurrencyPair{CurrencyA: ETH, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	ETC_USD  = CurrencyPair{CurrencyA: ETC, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	BCH_USD  = CurrencyPair{CurrencyA: BCH, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	XRP_USD  = CurrencyPair{CurrencyA: XRP, CurrencyB: USD, AmountTickSize: 3, PriceTickSize: 3}
	BCD_USD  = CurrencyPair{CurrencyA: BCD, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 3}
	EOS_USD  = CurrencyPair{CurrencyA: EOS, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	BTG_USD  = CurrencyPair{CurrencyA: BTG, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	BSV_USD  = CurrencyPair{CurrencyA: BSV, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	DOT_USD  = CurrencyPair{CurrencyA: DOT, CurrencyB: USD, AmountTickSize: 3, PriceTickSize: 2}
	DASH_USD = CurrencyPair{CurrencyA: DASH, CurrencyB: USD, AmountTickSize: 2, PriceTickSize: 2}
	CRV_USD  = CurrencyPair{CurrencyA: CRV, CurrencyB: USD, AmountTickSize: 4, PriceTickSize: 3}
	ALGO_USD = CurrencyPair{CurrencyA: ALGO, CurrencyB: USD, AmountTickSize: 4, PriceTickSize: 4}

	BTC_USDT  = CurrencyPair{CurrencyA: BTC, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 1}
	LTC_USDT  = CurrencyPair{CurrencyA: LTC, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	BCH_USDT  = CurrencyPair{CurrencyA: BCH, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	ETC_USDT  = CurrencyPair{CurrencyA: ETC, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 3}
	ETH_USDT  = CurrencyPair{CurrencyA: ETH, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	BCD_USDT  = CurrencyPair{CurrencyA: BCD, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	NEO_USDT  = CurrencyPair{CurrencyA: NEO, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	EOS_USDT  = CurrencyPair{CurrencyA: EOS, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	XRP_USDT  = CurrencyPair{CurrencyA: XRP, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	HSR_USDT  = CurrencyPair{CurrencyA: HSR, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	BSV_USDT  = CurrencyPair{CurrencyA: BSV, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	OKB_USDT  = CurrencyPair{CurrencyA: OKB, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	HT_USDT   = CurrencyPair{CurrencyA: HT, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 4}
	BNB_USDT  = CurrencyPair{CurrencyA: BNB, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	PAX_USDT  = CurrencyPair{CurrencyA: PAX, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 3}
	TRX_USDT  = CurrencyPair{CurrencyA: TRX, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 3}
	DOT_USDT  = CurrencyPair{CurrencyA: DOT, CurrencyB: USDT, AmountTickSize: 3, PriceTickSize: 2}
	DASH_USDT = CurrencyPair{CurrencyA: DASH, CurrencyB: USDT, AmountTickSize: 2, PriceTickSize: 2}
	CRV_USDT  = CurrencyPair{CurrencyA: CRV, CurrencyB: USDT, AmountTickSize: 3, PriceTickSize: 3}
	ALGO_USDT = CurrencyPair{CurrencyA: ALGO, CurrencyB: USDT, AmountTickSize: 3, PriceTickSize: 4}

	XRP_EUR = CurrencyPair{CurrencyA: XRP, CurrencyB: EUR, AmountTickSize: 2, PriceTickSize: 4}

	BTC_JPY = CurrencyPair{CurrencyA: BTC, CurrencyB: JPY, AmountTickSize: 2, PriceTickSize: 0}
	LTC_JPY = CurrencyPair{CurrencyA: LTC, CurrencyB: JPY, AmountTickSize: 2, PriceTickSize: 0}
	ETH_JPY = CurrencyPair{CurrencyA: ETH, CurrencyB: JPY, AmountTickSize: 2, PriceTickSize: 0}
	ETC_JPY = CurrencyPair{CurrencyA: ETC, CurrencyB: JPY, AmountTickSize: 2, PriceTickSize: 0}
	BCH_JPY = CurrencyPair{CurrencyA: BCH, CurrencyB: JPY, AmountTickSize: 2, PriceTickSize: 0}

	LTC_BTC = CurrencyPair{CurrencyA: LTC, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	ETH_BTC = CurrencyPair{CurrencyA: ETH, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	ETC_BTC = CurrencyPair{CurrencyA: ETC, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	BCC_BTC = CurrencyPair{CurrencyA: BCC, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	BCH_BTC = CurrencyPair{CurrencyA: BCH, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	DCR_BTC = CurrencyPair{CurrencyA: DCR, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	XRP_BTC = CurrencyPair{CurrencyA: XRP, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 6}
	BTG_BTC = CurrencyPair{CurrencyA: BTG, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	BCD_BTC = CurrencyPair{CurrencyA: BCD, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	NEO_BTC = CurrencyPair{CurrencyA: NEO, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	EOS_BTC = CurrencyPair{CurrencyA: EOS, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 5}
	HSR_BTC = CurrencyPair{CurrencyA: HSR, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	BSV_BTC = CurrencyPair{CurrencyA: BSV, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 4}
	OKB_BTC = CurrencyPair{CurrencyA: OKB, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 6}
	HT_BTC  = CurrencyPair{CurrencyA: HT, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 7}
	BNB_BTC = CurrencyPair{CurrencyA: BNB, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 6}
	TRX_BTC = CurrencyPair{CurrencyA: TRX, CurrencyB: BTC, AmountTickSize: 2, PriceTickSize: 7}
	DOT_BTC = CurrencyPair{CurrencyA: DOT, CurrencyB: BTC, AmountTickSize: 3, PriceTickSize: 6}

	ETC_ETH = CurrencyPair{CurrencyA: ETC, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}
	EOS_ETH = CurrencyPair{CurrencyA: EOS, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}
	ZEC_ETH = CurrencyPair{CurrencyA: ZEC, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}
	NEO_ETH = CurrencyPair{CurrencyA: NEO, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}
	HSR_ETH = CurrencyPair{CurrencyA: HSR, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}
	LTC_ETH = CurrencyPair{CurrencyA: LTC, CurrencyB: ETH, AmountTickSize: 2, PriceTickSize: 4}

	UNKNOWN_PAIR = CurrencyPair{CurrencyA: UNKNOWN, CurrencyB: UNKNOWN}
)

Functions

func AdaptKlinePeriodForOKEx

func AdaptKlinePeriodForOKEx(period int) string

func CancelAllUnfinishedFutureOrders

func CancelAllUnfinishedFutureOrders(api FutureRestAPI, contractType string, currencyPair CurrencyPair) int

*

  • call all unfinished future orders
  • @return c 成功撤单数量

func CancelAllUnfinishedOrders

func CancelAllUnfinishedOrders(api API, currencyPair CurrencyPair) int

*

  • call all unfinished orders

func FlateDecompress

func FlateDecompress(data []byte) ([]byte, error)

func FloatToFixed

func FloatToFixed(v float64, precision int) float64

func FloatToString

func FloatToString(v float64, precision int) string

func GenerateOrderClientId

func GenerateOrderClientId(size int) string

func GetParamHmacMD5Sign

func GetParamHmacMD5Sign(secret, params string) (string, error)

func GetParamHmacSHA1Sign

func GetParamHmacSHA1Sign(secret, params string) (string, error)

func GetParamHmacSHA256Base64Sign

func GetParamHmacSHA256Base64Sign(secret, params string) (string, error)

func GetParamHmacSHA256Sign

func GetParamHmacSHA256Sign(secret, params string) (string, error)

func GetParamHmacSHA512Base64Sign

func GetParamHmacSHA512Base64Sign(hmac_key string, hmac_data string) string

func GetParamHmacSHA512Sign

func GetParamHmacSHA512Sign(secret, params string) (string, error)

func GetParamHmacSha384Sign

func GetParamHmacSha384Sign(secret, params string) (string, error)

for bitfinex.com

func GetParamMD5Sign

func GetParamMD5Sign(secret, params string) (string, error)

*

*md5签名,okcoin和huobi适用

func GetSHA

func GetSHA(text string) (string, error)

func GzipDecompress

func GzipDecompress(data []byte) ([]byte, error)

func HttpDeleteForm

func HttpDeleteForm(client *http.Client, reqUrl string, postData url.Values, headers map[string]string) ([]byte, error)

func HttpGet

func HttpGet(client *http.Client, reqUrl string) (map[string]interface{}, error)

func HttpGet2

func HttpGet2(client *http.Client, reqUrl string, headers map[string]string) (map[string]interface{}, error)

func HttpGet3

func HttpGet3(client *http.Client, reqUrl string, headers map[string]string) ([]interface{}, error)

func HttpGet4

func HttpGet4(client *http.Client, reqUrl string, headers map[string]string, result interface{}) error

func HttpGet5

func HttpGet5(client *http.Client, reqUrl string, headers map[string]string) ([]byte, error)

func HttpPostForm

func HttpPostForm(client *http.Client, reqUrl string, postData url.Values) ([]byte, error)

func HttpPostForm2

func HttpPostForm2(client *http.Client, reqUrl string, postData url.Values, headers map[string]string) ([]byte, error)

func HttpPostForm3

func HttpPostForm3(client *http.Client, reqUrl string, postData string, headers map[string]string) ([]byte, error)

func HttpPostForm4

func HttpPostForm4(client *http.Client, reqUrl string, postData map[string]string, headers map[string]string) ([]byte, error)

func HttpPut

func HttpPut(client *http.Client, reqUrl string, postData url.Values, headers map[string]string) ([]byte, error)

func MergeOptionalParameter

func MergeOptionalParameter(values *url.Values, opts ...OptionalParameter) url.Values

func NewHttpRequest

func NewHttpRequest(client *http.Client, reqType string, reqUrl string, postData string, requstHeaders map[string]string) ([]byte, error)

func NewHttpRequestWithFasthttp

func NewHttpRequestWithFasthttp(client *http.Client, reqMethod, reqUrl, postData string, headers map[string]string) ([]byte, error)

func RE

func RE(retry int, delay time.Duration, method interface{}, params ...interface{}) interface{}

*

本函数只适合,返回两个参数的API重试调用,其中一个参数必须是error
@retry  重试次数
@delay  每次重试延迟时间间隔
@method 调用的函数,比如: api.GetTicker ,注意:不是api.GetTicker(...)
@params 参数,顺序一定要按照实际调用函数入参顺序一样
@return 返回

func ToFloat64

func ToFloat64(v interface{}) float64

func ToInt

func ToInt(v interface{}) int

func ToInt64

func ToInt64(v interface{}) int64

func ToUint64

func ToUint64(v interface{}) uint64

func ValuesToJson

func ValuesToJson(v url.Values) ([]byte, error)

Types

type API

type API interface {
	LimitBuy(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)
	LimitSell(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)
	MarketBuy(amount, price string, currency CurrencyPair) (*Order, error)
	MarketSell(amount, price string, currency CurrencyPair) (*Order, error)
	CancelOrder(orderId string, currency CurrencyPair) (bool, error)
	GetOneOrder(orderId string, currency CurrencyPair) (*Order, error)
	GetUnfinishOrders(currency CurrencyPair) ([]Order, error)
	GetOrderHistorys(currency CurrencyPair, opt ...OptionalParameter) ([]Order, error)
	GetAccount() (*Account, error)

	GetTicker(currency CurrencyPair) (*Ticker, error)
	GetDepth(size int, currency CurrencyPair) (*Depth, error)
	GetKlineRecords(currency CurrencyPair, period KlinePeriod, size int, optional ...OptionalParameter) ([]Kline, error)
	//非个人,整个交易所的交易记录
	GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)

	GetExchangeName() string
}

type APIConfig

type APIConfig struct {
	HttpClient    *http.Client
	Endpoint      string
	ApiKey        string
	ApiSecretKey  string
	ApiPassphrase string //for okex.com v3 api
	ClientId      string //for bitstamp.net , huobi.pro

	Lever float64 //杠杆倍数 , for future
}

type Account

type Account struct {
	Exchange    string
	Asset       float64 //总资产
	NetAsset    float64 //净资产
	SubAccounts map[Currency]SubAccount
}

type ApiError

type ApiError struct {
	ErrCode,
	ErrMsg,
	OriginErrMsg string
}

func (ApiError) Error

func (e ApiError) Error() string

func (ApiError) OriginErr

func (e ApiError) OriginErr(err string) ApiError

type BorrowParameter

type BorrowParameter struct {
	CurrencyPair CurrencyPair
	Currency     Currency
	Amount       float64
}

type Currency

type Currency struct {
	Symbol string
	Desc   string
}

func NewCurrency

func NewCurrency(symbol, desc string) Currency

func (Currency) AdaptBccToBch

func (c Currency) AdaptBccToBch() Currency

func (Currency) AdaptBchToBcc

func (c Currency) AdaptBchToBcc() Currency

func (Currency) Eq

func (c Currency) Eq(c2 Currency) bool

func (Currency) String

func (c Currency) String() string

type CurrencyPair

type CurrencyPair struct {
	CurrencyA      Currency
	CurrencyB      Currency
	AmountTickSize int // 下单量精度
	PriceTickSize  int //交易对价格精度
}

A->B(A兑换为B)

func NewCurrencyPair

func NewCurrencyPair(currencyA Currency, currencyB Currency) CurrencyPair

func NewCurrencyPair2

func NewCurrencyPair2(currencyPairSymbol string) CurrencyPair

func NewCurrencyPair3

func NewCurrencyPair3(currencyPairSymbol string, sep string) CurrencyPair

func (CurrencyPair) AdaptUsdToUsdt

func (pair CurrencyPair) AdaptUsdToUsdt() CurrencyPair

func (CurrencyPair) AdaptUsdtToUsd

func (pair CurrencyPair) AdaptUsdtToUsd() CurrencyPair

func (CurrencyPair) Eq

func (pair CurrencyPair) Eq(c2 CurrencyPair) bool

func (CurrencyPair) Reverse

func (pair CurrencyPair) Reverse() CurrencyPair

func (*CurrencyPair) SetAmountTickSize

func (pair *CurrencyPair) SetAmountTickSize(tickSize int) CurrencyPair

func (*CurrencyPair) SetPriceTickSize

func (pair *CurrencyPair) SetPriceTickSize(tickSize int) CurrencyPair

func (CurrencyPair) String

func (pair CurrencyPair) String() string

func (CurrencyPair) ToLower

func (pair CurrencyPair) ToLower() CurrencyPair

for to symbol lower , Not practical '==' operation method

func (CurrencyPair) ToSymbol

func (pair CurrencyPair) ToSymbol(joinChar string) string

func (CurrencyPair) ToSymbol2

func (pair CurrencyPair) ToSymbol2(joinChar string) string

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 Depth

type Depth struct {
	ContractType string `json:"contract_type,omitempty"` //for futures
	ContractId   string `json:"contract_id,omitempty"`   // for futures
	Pair         CurrencyPair
	UTime        time.Time
	AskList      DepthRecords // Descending order
	BidList      DepthRecords // Descending order
}

type DepthRecord

type DepthRecord struct {
	Price  float64
	Amount float64
}

type DepthRecords

type DepthRecords []DepthRecord

func (DepthRecords) Len

func (dr DepthRecords) Len() int

func (DepthRecords) Less

func (dr DepthRecords) Less(i, j int) bool

func (DepthRecords) Swap

func (dr DepthRecords) Swap(i, j int)

type FutureAccount

type FutureAccount struct {
	FutureSubAccounts map[Currency]FutureSubAccount
}

type FutureKline

type FutureKline struct {
	*Kline
	Vol2 float64 //个数
}

type FutureOrder

type FutureOrder struct {
	ClientOid    string //自定义ID,GoEx内部自动生成
	OrderID2     string //请尽量用这个字段替代OrderID字段
	Price        float64
	Amount       float64
	AvgPrice     float64
	DealAmount   float64
	OrderID      int64 //deprecated
	OrderTime    int64
	Status       TradeStatus
	Currency     CurrencyPair
	OrderType    int     //ORDINARY=0 POST_ONLY=1 FOK= 2 IOC= 3
	OType        int     //1:开多 2:开空 3:平多 4: 平空
	LeverRate    float64 //倍数
	Fee          float64 //手续费
	ContractName string
	FinishedTime int64 // finished timestamp

	//策略委托单
	TriggerPrice float64
	AlgoType     int //1:限价 2:市场价;触发价格类型,默认是限价;为市场价时,委托价格不必填;
}

type FuturePosition

type FuturePosition struct {
	BuyAmount      float64
	BuyAvailable   float64
	BuyPriceAvg    float64
	BuyPriceCost   float64
	BuyProfitReal  float64
	BuyProfit      float64
	CreateDate     int64
	LeverRate      float64
	SellAmount     float64
	SellAvailable  float64
	SellPriceAvg   float64
	SellPriceCost  float64
	SellProfitReal float64
	SellProfit     float64
	Symbol         CurrencyPair //btc_usd:比特币,ltc_usd:莱特币
	ContractType   string
	ContractId     int64
	ForceLiquPrice float64 //预估爆仓价
	ShortPnlRatio  float64 //空仓收益率
	LongPnlRatio   float64 //多仓收益率
}

type FutureRestAPI

type FutureRestAPI interface {
	/**
	 *获取交易所名字
	 */
	GetExchangeName() string

	/**
	 *获取交割预估价
	 */
	GetFutureEstimatedPrice(currencyPair CurrencyPair) (float64, error)

	/**
	 * 期货行情
	 * @param currency_pair   btc_usd:比特币    ltc_usd :莱特币
	 * @param contractType  合约类型: this_week:当周   next_week:下周   month:当月   quarter:季度
	 */
	GetFutureTicker(currencyPair CurrencyPair, contractType string) (*Ticker, error)

	/**
	 * 期货深度
	 * @param currencyPair  btc_usd:比特币    ltc_usd :莱特币
	 * @param contractType  合约类型: this_week:当周   next_week:下周   month:当月   quarter:季度
	 * @param size 获取深度档数
	 * @return
	 */
	GetFutureDepth(currencyPair CurrencyPair, contractType string, size int) (*Depth, error)

	/**
	 * 期货指数
	 * @param currencyPair   btc_usd:比特币    ltc_usd :莱特币
	 */
	GetFutureIndex(currencyPair CurrencyPair) (float64, error)

	/**
	 *全仓账户
	 *@param currency
	 */
	GetFutureUserinfo(currencyPair ...CurrencyPair) (*FutureAccount, error)

	/**
	 * @deprecated
	 * 期货下单
	 * @param currencyPair   btc_usd:比特币    ltc_usd :莱特币
	 * @param contractType   合约类型: this_week:当周   next_week:下周   month:当月   quarter:季度
	 * @param price  价格
	 * @param amount  委托数量
	 * @param openType   1:开多   2:开空   3:平多   4:平空
	 * @param matchPrice  是否为对手价 0:不是    1:是   ,当取值为1时,price无效
	 */
	PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error)

	LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error)

	//对手价下单
	MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error)

	/**
	 * 取消订单
	 * @param symbol   btc_usd:比特币    ltc_usd :莱特币
	 * @param contractType    合约类型: this_week:当周   next_week:下周   month:当月   quarter:季度
	 * @param orderId   订单ID

	 */
	FutureCancelOrder(currencyPair CurrencyPair, contractType, orderId string) (bool, error)

	/**
	 * 用户持仓查询
	 * @param symbol   btc_usd:比特币    ltc_usd :莱特币
	 * @param contractType   合约类型: this_week:当周   next_week:下周   month:当月   quarter:季度
	 * @return
	 */
	GetFuturePosition(currencyPair CurrencyPair, contractType string) ([]FuturePosition, error)

	/**
	 *获取订单信息
	 */
	GetFutureOrders(orderIds []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

	/**
	 *获取单个订单信息
	 */
	GetFutureOrder(orderId string, currencyPair CurrencyPair, contractType string) (*FutureOrder, error)

	/**
	 *获取未完成订单信息
	 */
	GetUnfinishFutureOrders(currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

	/**
	 * 获取个人订单历史,默认获取最近的订单历史列表,返回多少条订单数据,需根据平台接口定义而定
	 */
	GetFutureOrderHistory(pair CurrencyPair, contractType string, optional ...OptionalParameter) ([]FutureOrder, error)

	/**
	 *获取交易费
	 */
	GetFee() (float64, error)

	/**
	 *获取每张合约价值
	 */
	GetContractValue(currencyPair CurrencyPair) (float64, error)

	/**
	 *获取交割时间 星期(0,1,2,3,4,5,6),小时,分,秒
	 */
	GetDeliveryTime() (int, int, int, int)

	/**
	 * 获取K线数据
	 */
	GetKlineRecords(contractType string, currency CurrencyPair, period KlinePeriod, size int, optional ...OptionalParameter) ([]FutureKline, error)

	/**
	 * 获取Trade数据
	 */
	GetTrades(contractType string, currencyPair CurrencyPair, since int64) ([]Trade, error)
}

type FutureSubAccount

type FutureSubAccount struct {
	Currency      Currency
	AccountRights float64 //账户权益
	KeepDeposit   float64 //保证金
	ProfitReal    float64 //已实现盈亏
	ProfitUnreal  float64
	RiskRate      float64 //保证金率
}

type FutureTicker

type FutureTicker struct {
	*Ticker
	ContractType string  `json:"omitempty"`
	ContractId   string  `json:"contractId"`
	LimitHigh    float64 `json:"limitHigh,string"`
	LimitLow     float64 `json:"limitLow,string"`
	HoldAmount   float64 `json:"hold_amount,string"`
	UnitAmount   float64 `json:"unitAmount,string"`
}

type FuturesContractInfo

type FuturesContractInfo struct {
	*TickSize
	ContractVal  float64 //合约面值(美元)
	Delivery     string  //交割日期
	ContractType string  //	本周 this_week 次周 next_week 季度 quarter
}

type FuturesWsApi

type FuturesWsApi interface {
	DepthCallback(func(depth *Depth))
	TickerCallback(func(ticker *FutureTicker))
	TradeCallback(func(trade *Trade, contract string))

	SubscribeDepth(pair CurrencyPair, contractType string) error
	SubscribeTicker(pair CurrencyPair, contractType string) error
	SubscribeTrade(pair CurrencyPair, contractType string) error
}

type HistoricalFunding

type HistoricalFunding struct {
	InstrumentId string    `json:"instrument_id"`
	RealizedRate float64   `json:"realized_rate,string"`
	FundingTime  time.Time `json:"funding_time"`
}

type Kline

type Kline struct {
	Pair      CurrencyPair
	Timestamp int64
	Open      float64
	Close     float64
	High      float64
	Low       float64
	Vol       float64
}

type KlinePeriod

type KlinePeriod int

type LimitOrderOptionalParameter

type LimitOrderOptionalParameter int
const (
	PostOnly LimitOrderOptionalParameter = iota + 1
	Ioc
	Fok
)

func (LimitOrderOptionalParameter) String

func (opt LimitOrderOptionalParameter) String() string

type MarginAccount

type MarginAccount struct {
	Sub              map[Currency]MarginSubAccount
	LiquidationPrice float64
	RiskRate         float64
	MarginRatio      float64
}

type MarginSubAccount

type MarginSubAccount struct {
	Balance     float64
	Frozen      float64
	Available   float64
	CanWithdraw float64
	Loan        float64
	LendingFee  float64
}

type OptionalParameter

type OptionalParameter map[string]interface{}

func (OptionalParameter) GetFloat64

func (optional OptionalParameter) GetFloat64(name string) float64

func (OptionalParameter) GetInt

func (optional OptionalParameter) GetInt(name string) int

func (OptionalParameter) GetInt64

func (optional OptionalParameter) GetInt64(name string) int64

func (OptionalParameter) GetString

func (optional OptionalParameter) GetString(name string) string

func (OptionalParameter) GetTime

func (optional OptionalParameter) GetTime(name string) *time.Time

func (OptionalParameter) Optional

func (optional OptionalParameter) Optional(name string, value interface{}) OptionalParameter

type Order

type Order struct {
	Price        float64
	Amount       float64
	AvgPrice     float64
	DealAmount   float64
	Fee          float64
	Cid          string //客户端自定义ID
	OrderID2     string
	OrderID      int //deprecated
	Status       TradeStatus
	Currency     CurrencyPair
	Side         TradeSide
	Type         string //limit / market
	OrderType    int    //0:default,1:maker,2:fok,3:ioc
	OrderTime    int    // create  timestamp
	FinishedTime int64  //finished timestamp
}

type OrderFeature

type OrderFeature int

func (OrderFeature) String

func (of OrderFeature) String() string

type OrderType

type OrderType int

func (OrderType) String

func (ot OrderType) String() string

type RepaymentParameter

type RepaymentParameter struct {
	BorrowParameter
	BorrowId string
}

type SpotWsApi

type SpotWsApi interface {
	DepthCallback(func(depth *Depth))
	TickerCallback(func(ticker *Ticker))
	TradeCallback(func(trade *Trade))

	SubscribeDepth(pair CurrencyPair) error
	SubscribeTicker(pair CurrencyPair) error
	SubscribeTrade(pair CurrencyPair) error
}

type SubAccount

type SubAccount struct {
	Currency     Currency
	Amount       float64
	ForzenAmount float64
	LoanAmount   float64
}

type TickSize

type TickSize struct {
	InstrumentID    string
	UnderlyingIndex string
	QuoteCurrency   string
	PriceTickSize   float64 //下单价格精度
	AmountTickSize  float64 //数量精度
}

type Ticker

type Ticker struct {
	Pair CurrencyPair `json:"omitempty"`
	Last float64      `json:"last,string"`
	Buy  float64      `json:"buy,string"`
	Sell float64      `json:"sell,string"`
	High float64      `json:"high,string"`
	Low  float64      `json:"low,string"`
	Vol  float64      `json:"vol,string"`
	Date uint64       `json:"date"` // 单位:ms
}

type Trade

type Trade struct {
	Tid    int64        `json:"tid"`
	Type   TradeSide    `json:"type"`
	Amount float64      `json:"amount,string"`
	Price  float64      `json:"price,string"`
	Date   int64        `json:"date_ms"`
	Pair   CurrencyPair `json:"omitempty"`
}

type TradeSide

type TradeSide int
const (
	BUY TradeSide = 1 + iota
	SELL
	BUY_MARKET
	SELL_MARKET
)

func AdaptTradeSide

func AdaptTradeSide(side string) TradeSide

func (TradeSide) String

func (ts TradeSide) String() string

type TradeStatus

type TradeStatus int
const (
	ORDER_UNFINISH TradeStatus = iota
	ORDER_PART_FINISH
	ORDER_FINISH
	ORDER_CANCEL
	ORDER_REJECT
	ORDER_CANCEL_ING
	ORDER_FAIL
)

func (TradeStatus) String

func (ts TradeStatus) String() string

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 WalletApi

type WalletApi interface {
	//获取钱包资产
	GetAccount() (*Account, error)
	//提币
	Withdrawal(param WithdrawParameter) (withdrawId string, err error)
	//划转资产
	Transfer(param TransferParameter) error
	//获取提币记录
	GetWithDrawHistory(currency *Currency) ([]DepositWithdrawHistory, error)
	//获取充值记录
	GetDepositHistory(currency *Currency) ([]DepositWithdrawHistory, error)
}

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"`
}

type WsBuilder

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

func NewWsBuilder

func NewWsBuilder() *WsBuilder

func (*WsBuilder) AutoReconnect

func (b *WsBuilder) AutoReconnect() *WsBuilder

func (*WsBuilder) Build

func (b *WsBuilder) Build() *WsConn

func (*WsBuilder) ConnectSuccessAfterSendMessage

func (b *WsBuilder) ConnectSuccessAfterSendMessage(msg func() []byte) *WsBuilder

func (*WsBuilder) DecompressFunc

func (b *WsBuilder) DecompressFunc(f func([]byte) ([]byte, error)) *WsBuilder

func (*WsBuilder) DisableEnableCompression

func (b *WsBuilder) DisableEnableCompression() *WsBuilder

func (*WsBuilder) Dump

func (b *WsBuilder) Dump() *WsBuilder

func (*WsBuilder) ErrorHandleFunc

func (b *WsBuilder) ErrorHandleFunc(f func(err error)) *WsBuilder

func (*WsBuilder) Heartbeat

func (b *WsBuilder) Heartbeat(heartbeat func() []byte, t time.Duration) *WsBuilder

func (*WsBuilder) ProtoHandleFunc

func (b *WsBuilder) ProtoHandleFunc(f func([]byte) error) *WsBuilder

func (*WsBuilder) ProxyUrl

func (b *WsBuilder) ProxyUrl(proxyUrl string) *WsBuilder

func (*WsBuilder) ReconnectInterval

func (b *WsBuilder) ReconnectInterval(t time.Duration) *WsBuilder

func (*WsBuilder) ReqHeader

func (b *WsBuilder) ReqHeader(key, value string) *WsBuilder

func (*WsBuilder) WsUrl

func (b *WsBuilder) WsUrl(wsUrl string) *WsBuilder

type WsConfig

type WsConfig struct {
	WsUrl                          string
	ProxyUrl                       string
	ReqHeaders                     map[string][]string //连接的时候加入的头部信息
	HeartbeatIntervalTime          time.Duration       //
	HeartbeatData                  func() []byte       //心跳数据2
	IsAutoReconnect                bool
	ProtoHandleFunc                func([]byte) error           //协议处理函数
	DecompressFunc                 func([]byte) ([]byte, error) //解压函数
	ErrorHandleFunc                func(err error)
	ConnectSuccessAfterSendMessage func() []byte //for reconnect
	IsDump                         bool
	DisableEnableCompression       bool
	// contains filtered or unexported fields
}

type WsConn

type WsConn struct {
	WsConfig
	// contains filtered or unexported fields
}

func (*WsConn) CloseWs

func (ws *WsConn) CloseWs()

func (*WsConn) NewWs

func (ws *WsConn) NewWs() *WsConn

func (*WsConn) SendCloseMessage

func (ws *WsConn) SendCloseMessage(msg []byte)

func (*WsConn) SendJsonMessage

func (ws *WsConn) SendJsonMessage(m interface{}) error

func (*WsConn) SendMessage

func (ws *WsConn) SendMessage(msg []byte)

func (*WsConn) SendPingMessage

func (ws *WsConn) SendPingMessage(msg []byte)

func (*WsConn) SendPongMessage

func (ws *WsConn) SendPongMessage(msg []byte)

func (*WsConn) Subscribe

func (ws *WsConn) Subscribe(subEvent interface{}) error

Jump to

Keyboard shortcuts

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