common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 4 Imported by: 1

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"
	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"
	COINBENE     = "coinbene.com"
	ATOP         = "a.top"
)

exchanges const

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

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

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

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"       //永续合约
)
View Source
var (
	UNKNOWN = Currency{"UNKNOWN", ""}
	USD     = Currency{"USD", ""}
	USDT    = Currency{"USDT", ""}
	BUSD    = Currency{"BUSD", ""}
	PAX     = Currency{"PAX", ""}
	USDC    = Currency{"USDC", ""}
	EUR     = Currency{"EUR", ""}
	KRW     = Currency{"KRW", ""}
	BTC     = Currency{"BTC", ""}
	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", ""}
	HT      = Currency{"HT", ""}
	BNB     = Currency{"BNB", ""}
	TRX     = Currency{"TRX", ""}
	XMR     = Currency{"XMR", ""}
)

supported token list

View Source
var (
	BTC_KRW = TradingPair{BTC, KRW}
	ETH_KRW = TradingPair{ETH, KRW}
	ETC_KRW = TradingPair{ETC, KRW}
	LTC_KRW = TradingPair{LTC, KRW}
	BCH_KRW = TradingPair{BCH, KRW}

	BTC_USD = TradingPair{BTC, USD}
	LTC_USD = TradingPair{LTC, USD}
	ETH_USD = TradingPair{ETH, USD}
	ETC_USD = TradingPair{ETC, USD}
	BCH_USD = TradingPair{BCH, USD}
	BCC_USD = TradingPair{BCC, USD}
	XRP_USD = TradingPair{XRP, USD}
	BCD_USD = TradingPair{BCD, USD}
	EOS_USD = TradingPair{EOS, USD}
	BTG_USD = TradingPair{BTG, USD}
	BSV_USD = TradingPair{BSV, USD}

	BTC_USDT = TradingPair{BTC, USDT}
	LTC_USDT = TradingPair{LTC, USDT}
	BCH_USDT = TradingPair{BCH, USDT}
	BCC_USDT = TradingPair{BCC, USDT}
	ETC_USDT = TradingPair{ETC, USDT}
	ETH_USDT = TradingPair{ETH, USDT}
	BCD_USDT = TradingPair{BCD, USDT}
	NEO_USDT = TradingPair{NEO, USDT}
	EOS_USDT = TradingPair{EOS, USDT}
	XRP_USDT = TradingPair{XRP, USDT}
	HSR_USDT = TradingPair{HSR, USDT}
	BSV_USDT = TradingPair{BSV, USDT}
	OKB_USDT = TradingPair{OKB, USDT}
	HT_USDT  = TradingPair{HT, USDT}
	BNB_USDT = TradingPair{BNB, USDT}
	PAX_USDT = TradingPair{PAX, USDT}
	TRX_USDT = TradingPair{TRX, USDT}

	BTC_BUSD = TradingPair{BTC, BUSD}
	LTC_BUSD = TradingPair{LTC, BUSD}
	BCH_BUSD = TradingPair{BCH, BUSD}
	BCC_BUSD = TradingPair{BCC, BUSD}
	ETC_BUSD = TradingPair{ETC, BUSD}
	ETH_BUSD = TradingPair{ETH, BUSD}
	BCD_BUSD = TradingPair{BCD, BUSD}
	NEO_BUSD = TradingPair{NEO, BUSD}
	EOS_BUSD = TradingPair{EOS, BUSD}
	XRP_BUSD = TradingPair{XRP, BUSD}
	HSR_BUSD = TradingPair{HSR, BUSD}
	BSV_BUSD = TradingPair{BSV, BUSD}
	OKB_BUSD = TradingPair{OKB, BUSD}
	HT_BUSD  = TradingPair{HT, BUSD}
	BNB_BUSD = TradingPair{BNB, BUSD}
	PAX_BUSD = TradingPair{PAX, BUSD}
	TRX_BUSD = TradingPair{TRX, BUSD}
	XMR_BUSD = TradingPair{XMR, BUSD}

	LTC_BTC = TradingPair{LTC, BTC}
	ETH_BTC = TradingPair{ETH, BTC}
	ETC_BTC = TradingPair{ETC, BTC}
	BCC_BTC = TradingPair{BCC, BTC}
	BCH_BTC = TradingPair{BCH, BTC}
	DCR_BTC = TradingPair{DCR, BTC}
	XRP_BTC = TradingPair{XRP, BTC}
	BTG_BTC = TradingPair{BTG, BTC}
	BCD_BTC = TradingPair{BCD, BTC}
	NEO_BTC = TradingPair{NEO, BTC}
	EOS_BTC = TradingPair{EOS, BTC}
	HSR_BTC = TradingPair{HSR, BTC}
	BSV_BTC = TradingPair{BSV, BTC}
	OKB_BTC = TradingPair{OKB, BTC}
	HT_BTC  = TradingPair{HT, BTC}
	BNB_BTC = TradingPair{BNB, BTC}
	TRX_BTC = TradingPair{TRX, BTC}

	ETC_ETH = TradingPair{ETC, ETH}
	EOS_ETH = TradingPair{EOS, ETH}
	ZEC_ETH = TradingPair{ZEC, ETH}
	NEO_ETH = TradingPair{NEO, ETH}
	HSR_ETH = TradingPair{HSR, ETH}
	LTC_ETH = TradingPair{LTC, ETH}

	UNKNOWN_PAIR = TradingPair{UNKNOWN, UNKNOWN}
)

supported trading pair

Functions

This section is empty.

Types

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 TradingPair
	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 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         TradingPair
	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     TradingPair
	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
	CreateDate     int64
	LeverRate      float64
	SellAmount     float64
	SellAvailable  float64
	SellPriceAvg   float64
	SellPriceCost  float64
	SellProfitReal float64
	Symbol         TradingPair //btc_usd:比特币,ltc_usd:莱特币
	ContractType   string
	ContractId     int64
	ForceLiquPrice float64 //预估爆仓价
	ShortPnlRatio  float64 //空仓收益率
	LongPnlRatio   float64 //多仓收益率
}

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 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      TradingPair
	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 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     TradingPair
	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 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 TradingPair `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   TradingPair `json:"omitempty"`
}

type TradeSide

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

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 TradingPair

type TradingPair struct {
	CurrencyA Currency
	CurrencyB Currency
}

trading pair from A to B

func NewCurrencyPair

func NewCurrencyPair(currencyA Currency, currencyB Currency) TradingPair

func NewCurrencyPair2

func NewCurrencyPair2(currencyPairSymbol string) TradingPair

func NewCurrencyPair3

func NewCurrencyPair3(currencyPairSymbol string, sep string) TradingPair

func (TradingPair) AdaptBccToBch

func (pair TradingPair) AdaptBccToBch() TradingPair

func (TradingPair) AdaptBchToBcc

func (pair TradingPair) AdaptBchToBcc() TradingPair

It is currently applicable to binance and zb

func (TradingPair) AdaptUsdToUsdt

func (pair TradingPair) AdaptUsdToUsdt() TradingPair

func (TradingPair) AdaptUsdtToUsd

func (pair TradingPair) AdaptUsdtToUsd() TradingPair

func (TradingPair) Equal

func (c TradingPair) Equal(c2 TradingPair) bool

func (TradingPair) Reverse

func (pair TradingPair) Reverse() TradingPair

func (TradingPair) String

func (c TradingPair) String() string

func (TradingPair) ToLower

func (pair TradingPair) ToLower() TradingPair

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

func (TradingPair) ToSymbol

func (pair TradingPair) ToSymbol(joinChar string) string

func (TradingPair) ToSymbol2

func (pair TradingPair) ToSymbol2(joinChar 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 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