Documentation ¶
Index ¶
- Constants
- Variables
- func GetClients(bTest bool) (clts map[string]*Bitmex)
- func GetHMAC(hashType int, input, key []byte) []byte
- type Announcement
- type Bitmex
- func (b *Bitmex) Balance() (balance Balance, err error)
- func (b *Bitmex) Buy(price float64, amount float64) (ret *Order, err error)
- func (b *Bitmex) CancelAllOrders() (orders []*Order, err error)
- func (b *Bitmex) CancelOrder(oid string) (newOrder *Order, err error)
- func (b *Bitmex) CloseLong(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
- func (b *Bitmex) CloseLongMarket(amount float64) (ret *Order, err error)
- func (b *Bitmex) CloseShort(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
- func (b *Bitmex) CloseShortMarket(amount float64) (ret *Order, err error)
- func (b *Bitmex) ContractBalances() (balances map[Contract]Balance, err error)
- func (b *Bitmex) Contracts() (contracts []Contract, err error)
- func (b *Bitmex) Depth(d int) (depth Orderbook, err error)
- func (b *Bitmex) GetDepth(d int) (depth Orderbook, err error)
- func (b *Bitmex) GetLever() (lever float64, err error)
- func (b *Bitmex) GetOpenOrders() (orders []Order, err error)
- func (b *Bitmex) GetOrder(oid string) (newOrder *Order, err error)
- func (b *Bitmex) GetOrders() (orders []Order, err error)
- func (b *Bitmex) GetPositions() (positions []Position, err error)
- func (b *Bitmex) GetTicker() (ticker Ticker, err error)
- func (b *Bitmex) GetWalletHistory() (trans []*models.Transaction, err error)
- func (b *Bitmex) Info() (info Info, err error)
- func (b *Bitmex) Kline(start, end time.Time, nLimit int, bSize string, partial bool) (klines []*Candle, err error)
- func (b *Bitmex) KlineChan(start, end time.Time, bSize string) (klines chan []interface{}, err error)
- func (b *Bitmex) KlineRecent(nCount int32, bSize string, partial bool) (klines []*Candle, err error)
- func (b *Bitmex) OpenLong(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
- func (b *Bitmex) OpenLongMarket(amount float64) (ret *Order, err error)
- func (b *Bitmex) OpenShort(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
- func (b *Bitmex) OpenShortMarket(amount float64) (ret *Order, err error)
- func (b *Bitmex) Order(oid string) (newOrder *Order, err error)
- func (b *Bitmex) OrderAmend(oid string, price float64) (newOrder *Order, err error)
- func (b *Bitmex) Orders() (orders []Order, err error)
- func (b *Bitmex) PlaceOrder(stopPrice float64, price float64, amount float64, execInst string, ...) (ret *Order, err error)
- func (b *Bitmex) Positions() (positions []Position, err error)
- func (b *Bitmex) Price() (price float64, err error)
- func (b *Bitmex) Sell(price float64, amount float64) (ret *Order, err error)
- func (b *Bitmex) SetContract(contract string) (err error)
- func (b *Bitmex) SetDebug(bDebug bool)
- func (b *Bitmex) SetDepthChan(depthChan chan Depth)
- func (b *Bitmex) SetLever(lever float64) (err error)
- func (b *Bitmex) SetMaxLocalDepth(nMaxDepth int)
- func (b *Bitmex) SetProxy(proxy string) (err error)
- func (b *Bitmex) SetSymbol(symbol string) (err error)
- func (b *Bitmex) SetTradeChan(tradeChan chan Trade)
- func (b *Bitmex) StartWS() (err error)
- func (b *Bitmex) StopLoseBuy(stopPrice, price, amount float64) (ret *Order, err error)
- func (b *Bitmex) StopLoseBuyMarket(price, amount float64) (ret *Order, err error)
- func (b *Bitmex) StopLoseSell(stopPrice, price, amount float64) (ret *Order, err error)
- func (b *Bitmex) StopLoseSellMarket(price, amount float64) (ret *Order, err error)
- func (b *Bitmex) Ticker() (ticker Ticker, err error)
- func (b *Bitmex) Trades(start, end time.Time) (trades []Trade, err error)
- func (b *Bitmex) TradesChan(start, end time.Time) (trades chan []interface{}, err error)
- func (b *Bitmex) UpdatePositions() (err error)
- func (b *Bitmex) User() (user *models.User, err error)
- func (b *Bitmex) WS() *BitmexWS
- type BitmexWS
- func (bw *BitmexWS) AddSubscribe(subcribeInfo SubscribeInfo)
- func (bw *BitmexWS) Connect() (err error)
- func (bw *BitmexWS) GetLastDepth() (depth Depth)
- func (bw *BitmexWS) GetLastOrder(oid string) (order Order, err error)
- func (bw *BitmexWS) GetLastOrders() (orders []Order)
- func (bw *BitmexWS) GetLastPos() (poses []Position)
- func (bw *BitmexWS) GetLastTrade() (trade Trade)
- func (bw *BitmexWS) SetDepthChan(depthChan chan Depth)
- func (bw *BitmexWS) SetExecutionChan(executionChan chan []Trade)
- func (bw *BitmexWS) SetKlineChan(binSize string, klineChan chan *Candle) (err error)
- func (bw *BitmexWS) SetLastDepth(depth Depth)
- func (bw *BitmexWS) SetLastOrders(orders []Order)
- func (bw *BitmexWS) SetLastPos(pos []Position)
- func (bw *BitmexWS) SetLastTrade(trade Trade)
- func (bw *BitmexWS) SetOrderChan(orderChan chan []Order)
- func (bw *BitmexWS) SetProxy(proxy string)
- func (bw *BitmexWS) SetSubscribe(subcribeTypes []SubscribeInfo)
- func (bw *BitmexWS) SetSymbol(symbol string) (err error)
- func (bw *BitmexWS) SetTradeChan(tradeChan chan Trade)
- func (bw *BitmexWS) Subscribe(subcribeInfo SubscribeInfo) (err error)
- func (bw *BitmexWS) UpdateOrders(orders []Order)
- type DataDownload
- type DownFunc
- type DownParam
- type ErrorResponse
- type Info
- type MainResponse
- type NewParamFunc
- type OrderBook10
- type OrderBook10Data
- type OrderBookData
- type OrderBookL2
- type OrderBookMap
- type OrderMap
- type PositionMap
- type RequestBuffer
- func (r *RequestBuffer) GetBody() []byte
- func (r *RequestBuffer) GetBodyParam() interface{}
- func (r *RequestBuffer) GetFileParam() map[string][]runtime.NamedReadCloser
- func (r *RequestBuffer) GetFormParams() url.Values
- func (r *RequestBuffer) GetHeaderParams() http.Header
- func (r *RequestBuffer) GetMethod() string
- func (r *RequestBuffer) GetPath() string
- func (r *RequestBuffer) GetQueryParams() url.Values
- func (r *RequestBuffer) SetBodyParam(payload interface{}) error
- func (r *RequestBuffer) SetFileParam(name string, files ...runtime.NamedReadCloser) error
- func (r *RequestBuffer) SetFormParam(name string, values ...string) error
- func (r *RequestBuffer) SetHeaderParam(name string, values ...string) error
- func (r *RequestBuffer) SetPathParam(name string, value string) error
- func (r *RequestBuffer) SetQueryParam(name string, values ...string) error
- func (r *RequestBuffer) SetTimeout(timeout time.Duration) error
- type Resp
- func (r *Resp) Decode(buf []byte) (err error)
- func (r *Resp) GetExecution() (execution []*models.Execution)
- func (r *Resp) GetOrderbook10() (orderbook OrderBook10Data)
- func (r *Resp) GetOrderbookL2() (orderbook OrderBookData)
- func (r *Resp) GetOrders() (orders []*models.Order)
- func (r *Resp) GetPostions() (positions []*models.Position)
- func (r *Resp) GetTradeBin() (klines []*models.TradeBin)
- func (r *Resp) GetTradeData() (trades []*models.Trade)
- func (r *Resp) HasStatus() bool
- func (r *Resp) HasSuccess() bool
- func (r *Resp) HasTable() bool
- type Shutdown
- type SubscribeInfo
- type SubscribeResp
- type TradeBitmex
- type Transport
- type WSCmd
- type Welcome
Constants ¶
const ( BaseURL = "www.bitmex.com" TestBaseURL = "testnet.bitmex.com" )
const ( MaxTableLen = 200 // Bitmex websocket op BitmexWSOrderbookL2 = "orderBookL2" // Full level 2 orderBook BitmexWSOrderbookL2_25 = "orderBookL2_25" // 前 25 层的 Level 2 委托列表 BitmexWSOrderbook10 = "orderBook10" // Top 10 levels using traditional full book push BitmexWSTrade = "trade" // Live trades BitmexWSTradeBin1m = "tradeBin1m" // 1-minute trade bins BitmexWSTradeBin5m = "tradeBin5m" // 5-minute trade bins BitmexWSTradeBin1h = "tradeBin1h" // 1-hour trade bins BitmexWSTradeBin1d = "tradeBin1d" // 1-day trade bins BitmexWSAnnouncement = "announcement" // Site announcements BitmexWSLiquidation = "liquidation" // Liquidation orders as they're entered into the book BitmexWSQuote = "quote" // Top level of the book BitmexWSQuoteBin1m = "quoteBin1m" // 1-minute quote bins BitmexWSQuoteBin5m = "quoteBin5m" // 5-minute quote bins BitmexWSQuoteBin1h = "quoteBin1h" // 1-hour quote bins BitmexWSQuoteBin1d = "quoteBin1d" // 1-day quote bins // Bitmex websocket private op BitmexWSExecution = "execution" // Individual executions; can be multiple per order BitmexWSOrder = "order" // Live updates on your orders BitmexWSMargin = "margin" // Updates on your current account balance and margin requirements BitmexWSPosition = "position" // Updates on your positions WSTimeOut = 30 * time.Second )
const ( HashSHA1 = iota HashSHA256 HashSHA512 HashSHA512_384 HashMD5 )
const ( OrderBuy = "Buy" OrderSell = "Sell" OrderTypeLimit = "Limit" OrderTypeMarket = "Market" OrderTypeStop = "Stop" // stop lose with market price, must set stopPx OrderTypeStopLimit = "StopLimit" // stop lose with limit price, must set stopPx )
Variables ¶
var (
NoOrderFound = errors.New("no such order")
)
Functions ¶
func GetClients ¶
Types ¶
type Announcement ¶
type Announcement struct { Content string `json:"content"` Date string `json:"date"` ID int32 `json:"id"` Link string `json:"link"` Title string `json:"title"` }
Announcement General Announcements
type Bitmex ¶
func GetClientByName ¶
func GetDefaultClient ¶
func GetDefaultClient() *Bitmex
func NewBitmexFromCfg ¶
func NewBitmexFromCfg(key, secret, baseURL string, cfg *apiclient.TransportConfig) *Bitmex
func NewBitmexFromCfg(key, secret, baseURL string, cfg *apiclient.Configuration) *Bitmex {
func NewBitmexTest ¶
func (*Bitmex) CancelAllOrders ¶
CancelAllOrders cancel all not filled orders
func (*Bitmex) CancelOrder ¶
CancelOrder with oid
func (*Bitmex) CloseLong ¶
func (b *Bitmex) CloseLong(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
CloseLong close long with price and amount
func (*Bitmex) CloseLongMarket ¶
CloseLongMarket close long with market price
func (*Bitmex) CloseShort ¶
func (b *Bitmex) CloseShort(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
CloseShort close short with price and amount
func (*Bitmex) CloseShortMarket ¶
CloseShortMarket close short with market price
func (*Bitmex) ContractBalances ¶
ContractBalances get balances of each contract
func (*Bitmex) Contracts ¶
Contracts get all support contracts Fixme: "parse error", may be the swagger code wrong
func (*Bitmex) GetOpenOrders ¶
GetOrders get all open orders
func (*Bitmex) GetPositions ¶
GetPositions get current positions
func (*Bitmex) GetWalletHistory ¶
func (b *Bitmex) GetWalletHistory() (trans []*models.Transaction, err error)
GetWalletHistory get wallet history
func (*Bitmex) Kline ¶
func (b *Bitmex) Kline(start, end time.Time, nLimit int, bSize string, partial bool) (klines []*Candle, err error)
Kline Timestamp of kline is the end of the binSize
func (*Bitmex) KlineRecent ¶
func (b *Bitmex) KlineRecent(nCount int32, bSize string, partial bool) (klines []*Candle, err error)
KlineRecent get recent nCount klines
func (*Bitmex) OpenLong ¶
func (b *Bitmex) OpenLong(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
OpenLong open long with price and amount
func (*Bitmex) OpenLongMarket ¶
OpenLongMarket open long with market price
func (*Bitmex) OpenShort ¶
func (b *Bitmex) OpenShort(price float64, amount float64, postOnly bool, timeInForce string) (ret *Order, err error)
OpenShort open short with price and amount
func (*Bitmex) OpenShortMarket ¶
OpenShortMarket open short with market price
func (*Bitmex) OrderAmend ¶
func (*Bitmex) PlaceOrder ¶
func (b *Bitmex) PlaceOrder(stopPrice float64, price float64, amount float64, execInst string, timeInForce string, side string, orderType string, comment string) (ret *Order, err error)
PlaceOrder open an order with price and amount side. Buy/Sell orderType. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, Pegged. Defaults to 'Limit' when `price` is specified. Defaults to 'Stop' when `stopPx` is specified. Defaults to 'StopLimit' when `price` and `stopPx` are specified.
func (*Bitmex) SetContract ¶
func (*Bitmex) SetDepthChan ¶
func (b *Bitmex) SetDepthChan(depthChan chan Depth)
func (*Bitmex) SetMaxLocalDepth ¶
SetMaxLocalDepth set max local depth cache len
func (*Bitmex) SetProxy ¶
SetProxy set proxy of websocket example: socks5://127.0.0.1:1080
http://127.0.0.1:1080
func (*Bitmex) SetTradeChan ¶
func (b *Bitmex) SetTradeChan(tradeChan chan Trade)
func (*Bitmex) StopLoseBuy ¶
StopLoseBuy when marketPrice>=stopPrice, create buy order with price and amount
func (*Bitmex) StopLoseBuyMarket ¶
StopLoseSell when marketPrice>=stopPrice, create buy order with marketPrice and amount
func (*Bitmex) StopLoseSell ¶
StopLoseSell when marketPrice<=stopPrice, create sell order with price and amount
func (*Bitmex) StopLoseSellMarket ¶
StopLoseSell when marketPrice<=stopPrice, create buy order with marketPrice and amount
func (*Bitmex) TradesChan ¶
func (*Bitmex) UpdatePositions ¶
UpdatePositions update current positions
type BitmexWS ¶
type BitmexWS struct { TableLen int // contains filtered or unexported fields }
func NewBitmexWS ¶
func NewBitmexWSTest ¶
func NewBitmexWSWithURL ¶
func (*BitmexWS) AddSubscribe ¶
func (bw *BitmexWS) AddSubscribe(subcribeInfo SubscribeInfo)
func (*BitmexWS) GetLastDepth ¶
func (bw *BitmexWS) GetLastDepth() (depth Depth)
GetLastDepth get last depths
func (*BitmexWS) GetLastOrder ¶
func (*BitmexWS) GetLastOrders ¶
func (bw *BitmexWS) GetLastOrders() (orders []Order)
func (*BitmexWS) GetLastPos ¶
func (bw *BitmexWS) GetLastPos() (poses []Position)
func (*BitmexWS) GetLastTrade ¶
func (bw *BitmexWS) GetLastTrade() (trade Trade)
GetLastDepth get last depths
func (*BitmexWS) SetDepthChan ¶
func (bw *BitmexWS) SetDepthChan(depthChan chan Depth)
func (*BitmexWS) SetExecutionChan ¶
func (bw *BitmexWS) SetExecutionChan(executionChan chan []Trade)
func (*BitmexWS) SetKlineChan ¶
func (*BitmexWS) SetLastDepth ¶
func (bw *BitmexWS) SetLastDepth(depth Depth)
SetLastDepth set depth data,call by websocket message handler
func (*BitmexWS) SetLastOrders ¶
func (bw *BitmexWS) SetLastOrders(orders []Order)
func (*BitmexWS) SetLastPos ¶
func (bw *BitmexWS) SetLastPos(pos []Position)
func (*BitmexWS) SetLastTrade ¶
func (bw *BitmexWS) SetLastTrade(trade Trade)
SetLastTrade set depth data,call by websocket message handler
func (*BitmexWS) SetOrderChan ¶
func (bw *BitmexWS) SetOrderChan(orderChan chan []Order)
func (*BitmexWS) SetSubscribe ¶
func (bw *BitmexWS) SetSubscribe(subcribeTypes []SubscribeInfo)
func (*BitmexWS) SetTradeChan ¶
func (bw *BitmexWS) SetTradeChan(tradeChan chan Trade)
func (*BitmexWS) Subscribe ¶
func (bw *BitmexWS) Subscribe(subcribeInfo SubscribeInfo) (err error)
Subscribe one subscribe to a websocket channel
func (*BitmexWS) UpdateOrders ¶
func (bw *BitmexWS) UpdateOrders(orders []Order)
type DataDownload ¶
type DataDownload struct {
// contains filtered or unexported fields
}
func NewDataDownload ¶
func NewDataDownload(start, end strfmt.DateTime, paramFunc NewParamFunc, downFunc DownFunc, onceCount int32, nRoutine int) (d *DataDownload)
func (*DataDownload) IsFinish ¶
func (d *DataDownload) IsFinish() (bFinish bool)
func (*DataDownload) Run ¶
func (d *DataDownload) Run()
func (*DataDownload) SetFinish ¶
func (d *DataDownload) SetFinish(nFinish int32)
func (*DataDownload) Start ¶
func (d *DataDownload) Start() (dataCh chan []interface{})
type ErrorResponse ¶
type MainResponse ¶
type MainResponse struct { Table string `json:"table"` Keys []string `json:"keys"` Types struct { ID string `json:"id"` Price string `json:"price"` Side string `json:"side"` Size string `json:"size"` Symbol string `json:"symbol"` } `json:"types"` ForeignKeys struct { Side string `json:"side"` Symbol string `json:"symbol"` } `json:"foreignKeys"` Attributes struct { ID string `json:"id"` Symbol string `json:"symbol"` } `json:"Attributes"` }
type NewParamFunc ¶
type NewParamFunc func() DownParam
type OrderBook10 ¶
type OrderBook10 struct { Bids [][]float64 `json:"bids"` Asks [][]float64 `json:"asks"` Timestamp time.Time `json:"timestamp"` Symbol string `json:"symbol"` }
OrderBook10 contains order book 10
type OrderBook10Data ¶
type OrderBook10Data []*OrderBook10
type OrderBookData ¶
type OrderBookData []*OrderBookL2
func (*OrderBookData) GetDataToMap ¶
func (od *OrderBookData) GetDataToMap(ret OrderBookMap)
func (*OrderBookData) GetMap ¶
func (od *OrderBookData) GetMap() (ret OrderBookMap)
type OrderBookL2 ¶
type OrderBookL2 struct { ID int64 `json:"id"` Price float64 `json:"price"` Side string `json:"side"` Size int64 `json:"size"` Symbol string `json:"symbol"` }
OrderBookL2 contains order book l2
func (*OrderBookL2) Key ¶
func (o *OrderBookL2) Key() string
type OrderBookMap ¶
type OrderBookMap map[string]*OrderBookL2
func NewOrderBookMap ¶
func NewOrderBookMap() (o OrderBookMap)
func (OrderBookMap) GetDepth ¶
func (o OrderBookMap) GetDepth() (depth Depth)
type OrderMap ¶
func NewOrderMap ¶
func NewOrderMap() (o *OrderMap)
type PositionMap ¶
func NewPositionMap ¶
func NewPositionMap() (o PositionMap)
func (PositionMap) Pos ¶
func (o PositionMap) Pos() (poses []Position)
func (PositionMap) Update ¶
func (o PositionMap) Update(pos []*models.Position)
type RequestBuffer ¶
type RequestBuffer struct {
// contains filtered or unexported fields
}
func NewRequestBuffer ¶
func NewRequestBuffer() (r *RequestBuffer)
func (*RequestBuffer) GetBody ¶
func (r *RequestBuffer) GetBody() []byte
func (*RequestBuffer) GetBodyParam ¶
func (r *RequestBuffer) GetBodyParam() interface{}
func (*RequestBuffer) GetFileParam ¶
func (r *RequestBuffer) GetFileParam() map[string][]runtime.NamedReadCloser
func (*RequestBuffer) GetFormParams ¶
func (r *RequestBuffer) GetFormParams() url.Values
func (*RequestBuffer) GetHeaderParams ¶
func (r *RequestBuffer) GetHeaderParams() http.Header
func (*RequestBuffer) GetMethod ¶
func (r *RequestBuffer) GetMethod() string
func (*RequestBuffer) GetPath ¶
func (r *RequestBuffer) GetPath() string
func (*RequestBuffer) GetQueryParams ¶
func (r *RequestBuffer) GetQueryParams() url.Values
func (*RequestBuffer) SetBodyParam ¶
func (r *RequestBuffer) SetBodyParam(payload interface{}) error
func (*RequestBuffer) SetFileParam ¶
func (r *RequestBuffer) SetFileParam(name string, files ...runtime.NamedReadCloser) error
func (*RequestBuffer) SetFormParam ¶
func (r *RequestBuffer) SetFormParam(name string, values ...string) error
func (*RequestBuffer) SetHeaderParam ¶
func (r *RequestBuffer) SetHeaderParam(name string, values ...string) error
func (*RequestBuffer) SetPathParam ¶
func (r *RequestBuffer) SetPathParam(name string, value string) error
func (*RequestBuffer) SetQueryParam ¶
func (r *RequestBuffer) SetQueryParam(name string, values ...string) error
func (*RequestBuffer) SetTimeout ¶
func (r *RequestBuffer) SetTimeout(timeout time.Duration) error
type Resp ¶
type Resp struct { Request WSCmd `json:"request"` SubscribeResp ErrorResponse MainResponse Action string // contains filtered or unexported fields }
func (*Resp) GetExecution ¶
func (*Resp) GetOrderbook10 ¶
func (r *Resp) GetOrderbook10() (orderbook OrderBook10Data)
func (*Resp) GetOrderbookL2 ¶
func (r *Resp) GetOrderbookL2() (orderbook OrderBookData)
func (*Resp) GetPostions ¶
func (*Resp) GetTradeBin ¶
func (*Resp) GetTradeData ¶
func (*Resp) HasSuccess ¶
type Shutdown ¶
type Shutdown struct {
// contains filtered or unexported fields
}
Shutdown to monitor and shut down routines package specific
func NewRoutineManagement ¶
func NewRoutineManagement() *Shutdown
NewRoutineManagement returns an new initial routine management system
func (*Shutdown) SignalShutdown ¶
func (r *Shutdown) SignalShutdown()
SignalShutdown signals a shutdown across routines
type SubscribeInfo ¶
type SubscribeResp ¶
type TradeBitmex ¶
type Transport ¶
type Transport struct { *httptransport.Runtime Key string Secret string }