bitmex

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: LGPL-3.0 Imports: 40 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BaseURL     = "www.bitmex.com"
	TestBaseURL = "testnet.bitmex.com"
)
View Source
const (
	MaxTableLen = 200

	// Bitmex websocket op
	BitmexWSOrderbookL2    = "orderBookL2"    // Full level 2 orderBook
	BitmexWSOrderbookL2_25 = "orderBookL2_25" // Full level 2 orderBook
	BitmexWSOrderbookL10   = "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
	BitmexWSWallet    = "wallet"    // wallet update

	WSTimeOut = 5 * time.Second
)
View Source
const (
	HashSHA1 = iota
	HashSHA256
	HashSHA512
	HashSHA512_384
	HashMD5
)
View Source
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
	PostOnly           = "ParticipateDoNotInitiate"
	ReduceOnly         = "ReduceOnly"
)

Variables

View Source
var (
	NoOrderFound = errors.New("no such order")
)

Functions

func GetClients

func GetClients(bTest bool) (clts map[string]*Bitmex)

func GetHMAC

func GetHMAC(hashType int, input, key []byte) []byte

GetHMAC returns a keyed-hash message authentication code using the desired hashtype

func IsOrderCanceled added in v1.0.1

func IsOrderCanceled(o *Order) bool

func IsOrderFilled added in v1.0.1

func IsOrderFilled(o *Order) bool

func IsOrderLong added in v1.0.1

func IsOrderLong(o *Order) bool

func TransCandle added in v1.0.3

func TransCandle(binSize string, v *models.TradeBin) (candle *Candle)

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

type Bitmex struct {
	APIKey    string
	APISecret string
	// contains filtered or unexported fields
}

func GetClientByName

func GetClientByName(name string, bTest bool) (bm *Bitmex)

func GetClientByViperName added in v1.0.5

func GetClientByViperName(cfg *viper.Viper, name string, bTest bool) (bm *Bitmex)

func GetDefaultClient

func GetDefaultClient() *Bitmex

func NewBitmex

func NewBitmex(key, secret string) (b *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 NewBitmexTest(key, secret string) (b *Bitmex)

func (*Bitmex) Buy

func (b *Bitmex) Buy(price float64, amount float64) (ret *Order, err error)

Buy open long with price

func (*Bitmex) CancelAllOrders

func (b *Bitmex) CancelAllOrders() (orders []*Order, err error)

CancelAllOrders cancel all not filled orders

func (*Bitmex) CancelOrder

func (b *Bitmex) CancelOrder(oid string) (newOrder *Order, err error)

CancelOrder with oid

func (*Bitmex) Clone added in v1.0.3

func (b *Bitmex) Clone() (ret *Bitmex)

func (*Bitmex) CloseLong

func (b *Bitmex) CloseLong(price float64, amount float64) (ret *Order, err error)

CloseLong close long with price

func (*Bitmex) CloseLongMarket

func (b *Bitmex) CloseLongMarket(amount float64) (ret *Order, err error)

CloseLongarket close long with market price

func (*Bitmex) CloseShort

func (b *Bitmex) CloseShort(price float64, amount float64) (ret *Order, err error)

CloseShort close short with price

func (*Bitmex) CloseShortMarket

func (b *Bitmex) CloseShortMarket(amount float64) (ret *Order, err error)

CloseShortMarket close short with market price

func (*Bitmex) ContractBalances

func (b *Bitmex) ContractBalances() (balances map[Contract]Balance, err error)

ContractBalances get balances of each contract

func (*Bitmex) Contracts

func (b *Bitmex) Contracts() (contracts []Contract, err error)

Contracts get all support contracts Fixme: "parse error", may be the swagger code wrong

func (*Bitmex) CreateOrder added in v1.0.6

func (b *Bitmex) CreateOrder(price float64, amount int32, symbol, side, orderType, comment string, execInsts ...string) (newOrder *models.Order, err error)

CreteOrder create bitmex order,return bitmex model information

func (*Bitmex) Depth

func (b *Bitmex) Depth(d int) (depth Orderbook, err error)

Depth get depth if d is 0, get all depth

func (*Bitmex) GetDepth

func (b *Bitmex) GetDepth(d int) (depth Orderbook, err error)

GetDepth get depth use RESTful API

func (*Bitmex) GetFunding added in v1.0.5

func (b *Bitmex) GetFunding(start, end time.Time) (funds []*models.Funding, err error)

GetFunding get insurance

func (*Bitmex) GetInsurance added in v1.0.5

func (b *Bitmex) GetInsurance(start, end time.Time) (ins []*models.Insurance, err error)

GetInsurance get insurance

func (*Bitmex) GetLever

func (b *Bitmex) GetLever() (lever float64, err error)

func (*Bitmex) GetTicker

func (b *Bitmex) GetTicker() (ticker Ticker, err error)

Ticker

func (*Bitmex) Kline

func (b *Bitmex) Kline(start, end time.Time, nLimit int, bSize string) (klines []*Candle, err error)

Kline Timestamp of kline is the end of the binSize

func (*Bitmex) KlineChan

func (b *Bitmex) KlineChan(start, end time.Time, bSize string) (klines chan []interface{}, err chan error)

func (*Bitmex) KlineRecent

func (b *Bitmex) KlineRecent(nCount int32, bSize string) (klines []*Candle, err error)

KlineRecent get recent nCount klines

func (*Bitmex) OpenLong

func (b *Bitmex) OpenLong(price float64, amount float64) (ret *Order, err error)

OpenLong open long with price

func (*Bitmex) OpenLongMarket

func (b *Bitmex) OpenLongMarket(amount float64) (ret *Order, err error)

OpenLongMarket open long with market price

func (*Bitmex) OpenShort

func (b *Bitmex) OpenShort(price float64, amount float64) (ret *Order, err error)

OpenShort open short with price

func (*Bitmex) OpenShortMarket

func (b *Bitmex) OpenShortMarket(amount float64) (ret *Order, err error)

OpenShortMarket open short with market price

func (*Bitmex) Order

func (b *Bitmex) Order(oid string) (newOrder *Order, err error)

Orders get all active orders

func (*Bitmex) Orders

func (b *Bitmex) Orders() (orders []*Order, err error)

Orders get all active orders

func (*Bitmex) Positions

func (b *Bitmex) Positions() (positions []Position, err error)

Positions get current positions

func (*Bitmex) Price

func (b *Bitmex) Price() (price float64, err error)

func (*Bitmex) Sell

func (b *Bitmex) Sell(price float64, amount float64) (ret *Order, err error)

Buy open long with price

func (*Bitmex) SetContract

func (b *Bitmex) SetContract(contract string) (err error)

func (*Bitmex) SetDebug

func (b *Bitmex) SetDebug(bDebug bool)

func (*Bitmex) SetDepthChan

func (b *Bitmex) SetDepthChan(depthChan chan Depth)

func (*Bitmex) SetLever

func (b *Bitmex) SetLever(lever float64) (err error)

SetLever set contract lever

func (*Bitmex) SetMaxLocalDepth

func (b *Bitmex) SetMaxLocalDepth(nMaxDepth int)

SetMaxLocalDepth set max local depth cache len

func (*Bitmex) SetPostOnly added in v1.0.4

func (b *Bitmex) SetPostOnly(postOnly bool)

func (*Bitmex) SetProxy

func (b *Bitmex) SetProxy(proxy string) (err error)

SetProxy set proxy of websocket example: socks5://127.0.0.1:1080

http://127.0.0.1:1080

func (*Bitmex) SetSymbol

func (b *Bitmex) SetSymbol(symbol string) (err error)

SetSymbol set symbol

func (*Bitmex) SetTradeChan

func (b *Bitmex) SetTradeChan(tradeChan chan Trade)

func (*Bitmex) StartWS

func (b *Bitmex) StartWS() (err error)

StartWS start websocket connection

func (*Bitmex) StopLoseBuy

func (b *Bitmex) StopLoseBuy(stopPrice, price, amount float64) (ret *Order, err error)

StopLoseBuy when marketPrice>=stopPrice, create buy order with price and amount

func (*Bitmex) StopLoseBuyMarket

func (b *Bitmex) StopLoseBuyMarket(price, amount float64) (ret *Order, err error)

StopLoseSell when marketPrice>=stopPrice, create buy order with marketPrice and amount

func (*Bitmex) StopLoseSell

func (b *Bitmex) StopLoseSell(stopPrice, price, amount float64) (ret *Order, err error)

StopLoseSell when marketPrice<=stopPrice, create sell order with price and amount

func (*Bitmex) StopLoseSellMarket

func (b *Bitmex) StopLoseSellMarket(price, amount float64) (ret *Order, err error)

StopLoseSell when marketPrice<=stopPrice, create buy order with marketPrice and amount

func (*Bitmex) Ticker

func (b *Bitmex) Ticker() (ticker Ticker, err error)

func (*Bitmex) Trades

func (b *Bitmex) Trades(start, end time.Time) (trades []Trade, err error)

Trades get trades

func (*Bitmex) TradesChan

func (b *Bitmex) TradesChan(start, end time.Time) (trades chan []interface{}, err chan error)

func (*Bitmex) User

func (b *Bitmex) User() (user *models.User, err error)

func (*Bitmex) WS

func (b *Bitmex) WS() *BitmexWS

WS return ws instance

type BitmexWS

type BitmexWS struct {
	TableLen int
	// contains filtered or unexported fields
}

func NewBitmexWS

func NewBitmexWS(symbol, key, secret, proxy string) (bw *BitmexWS)

func NewBitmexWSTest

func NewBitmexWSTest(symbol, key, secret, proxy string) (bw *BitmexWS)

func NewBitmexWSWithURL

func NewBitmexWSWithURL(symbol, key, secret, proxy, wsURL string) (bw *BitmexWS)

func (*BitmexWS) AddSubscribe

func (bw *BitmexWS) AddSubscribe(subcribeInfo SubscribeInfo) (err error)

AddSubscribe add subcribe

func (*BitmexWS) Connect

func (bw *BitmexWS) Connect() (err error)

func (*BitmexWS) GetLastDepth

func (bw *BitmexWS) GetLastDepth() (depth Depth)

GetLastDepth get last depths

func (*BitmexWS) GetLastOrders added in v1.0.1

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) SetBalanceChan added in v1.0.8

func (bw *BitmexWS) SetBalanceChan(b chan Balance) (err error)

func (*BitmexWS) SetDepthChan

func (bw *BitmexWS) SetDepthChan(depthChan chan Depth)

func (*BitmexWS) SetHandle added in v1.0.3

func (bw *BitmexWS) SetHandle(tbl string, handle func(tbl string, msg *Resp))

func (*BitmexWS) SetKlineChan

func (bw *BitmexWS) SetKlineChan(binSize string, klineChan chan *Candle) (err error)

func (*BitmexWS) SetLastDepth

func (bw *BitmexWS) SetLastDepth(depth Depth)

SetLastDepth set depth data,call by websocket message handler

func (*BitmexWS) SetLastOrders added in v1.0.1

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 added in v1.0.1

func (bw *BitmexWS) SetOrderChan(orderChan chan []Order) (err error)

func (*BitmexWS) SetPositionChan added in v1.0.1

func (bw *BitmexWS) SetPositionChan(posChan chan []Position) (err error)

func (*BitmexWS) SetProxy

func (bw *BitmexWS) SetProxy(proxy string)

func (*BitmexWS) SetSubscribe

func (bw *BitmexWS) SetSubscribe(subcribeTypes []SubscribeInfo)

func (*BitmexWS) SetSymbol

func (bw *BitmexWS) SetSymbol(symbol string) (err error)

func (*BitmexWS) SetTradeChan

func (bw *BitmexWS) SetTradeChan(tradeChan chan Trade)

type ErrorResponse

type ErrorResponse struct {
	Status int         `json:"status"`
	Error  string      `json:"error"`
	Meta   interface{} `json:"meta"`
}

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 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 added in v1.0.1

type OrderMap map[string]*models.Order

func NewOrderMap added in v1.0.1

func NewOrderMap() OrderMap

func (OrderMap) Orders added in v1.0.1

func (o OrderMap) Orders() (orders []Order)

func (OrderMap) Update added in v1.0.1

func (o OrderMap) Update(orders []*models.Order) (ret []*models.Order)

type PositionMap

type PositionMap map[string]*models.Position

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 added in v1.0.1

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

func (r *Resp) Decode(buf []byte) (err error)

func (*Resp) GetMargins added in v1.0.8

func (r *Resp) GetMargins() (margins []*models.Margin)

func (*Resp) GetOrder added in v1.0.1

func (r *Resp) GetOrder() (orders []*models.Order)

func (*Resp) GetOrderbookL2

func (r *Resp) GetOrderbookL2() (orderbook OrderBookData)

func (*Resp) GetPostions

func (r *Resp) GetPostions() (positions []*models.Position)

func (*Resp) GetTradeBin

func (r *Resp) GetTradeBin() (klines []*models.TradeBin)

func (*Resp) GetTradeData

func (r *Resp) GetTradeData() (trades []*models.Trade)

func (*Resp) GetWallets added in v1.0.8

func (r *Resp) GetWallets() (wallets []*models.Wallet)

func (*Resp) HasStatus

func (r *Resp) HasStatus() bool

func (*Resp) HasSuccess

func (r *Resp) HasSuccess() bool

func (*Resp) HasTable

func (r *Resp) HasTable() bool

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 SubscribeInfo struct {
	Op    string
	Param string
}

type SubscribeResp

type SubscribeResp struct {
	Success   bool   `json:"success"`
	Subscribe string `json:"subscribe"`
}

type TradeBitmex

type TradeBitmex models.Trade

type Transport

type Transport struct {
	*httptransport.Runtime
	Key    string
	Secret string
}

func NewTransport

func NewTransport(host, basePath, key, secret string, schemes []string) (t *Transport)

func (*Transport) SetProxy added in v1.0.1

func (t *Transport) SetProxy(proxy string) (err error)

func (*Transport) Submit

func (t *Transport) Submit(operation *runtime.ClientOperation) (interface{}, error)

type WSCmd

type WSCmd struct {
	Command string        `json:"op"`
	Args    []interface{} `json:"args"`
}

type Welcome

type Welcome struct {
	Info      string
	Version   string
	Timestamp time.Time
	Docs      string
	Limit     struct {
		Remaining int
	}
}

Jump to

Keyboard shortcuts

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