bitmex

package
v0.0.0-...-b6f6876 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: LGPL-3.0 Imports: 36 Imported by: 0

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

	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
)

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

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

func (b *Bitmex) Balance() (balance Balance, err error)

Balance get balance of user

func (*Bitmex) Buy

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

Buy open long with price and amount

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

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

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

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

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

func (*Bitmex) GetOrder

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

GetOrder get an active orders

func (*Bitmex) GetOrders

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

GetOrders get all active orders

func (*Bitmex) GetPositions

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

GetPositions get current open positions

func (*Bitmex) GetTicker

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

GetTicker get ticker

func (*Bitmex) GetWalletHistory

func (b *Bitmex) GetWalletHistory() (trans []*models.Transaction, err error)

GetWalletHistory get wallet history

func (*Bitmex) Info

func (b *Bitmex) Info() (info Info, err error)

Info get server information

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

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

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

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, postOnly bool, timeInForce string) (ret *Order, err error)

OpenShort open short with price and amount

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)

Order get an active orders

func (*Bitmex) OrderAmend

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

func (*Bitmex) Orders

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

Orders get all active orders

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) 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 short with price and amount

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

func (*Bitmex) UpdatePositions

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

UpdatePositions update current positions

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)

func (*BitmexWS) Connect

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

func (*BitmexWS) GetLastDepth

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

GetLastDepth get last depths

func (*BitmexWS) GetLastOrder

func (bw *BitmexWS) GetLastOrder(oid string) (order Order, err error)

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

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

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

func (d *DataDownload) RunOnce(start int) (bFinish bool, err error)

func (*DataDownload) SetFinish

func (d *DataDownload) SetFinish(nFinish int32)

func (*DataDownload) Start

func (d *DataDownload) Start() (dataCh chan []interface{})

type DownFunc

type DownFunc func(DownParam) ([]interface{}, error)

type DownParam

type DownParam interface {
	SetStart(start *int32)
	SetCount(count *int32)
	SetStartTime(startTime *strfmt.DateTime)
	SetEndTime(endTime *strfmt.DateTime)
}

type ErrorResponse

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

type Info

type Info struct {
	Name      string `json:"name"`
	Version   string `json:"version"`
	Timestamp int64  `json:"timestamp"`
}

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

type OrderMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewOrderMap

func NewOrderMap() (o *OrderMap)

func (*OrderMap) Orders

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

func (*OrderMap) Update

func (o *OrderMap) Update(orders []*models.Order, isDelete bool)

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

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

func (*Resp) GetOrders

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

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) 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
	// contains filtered or unexported fields
}

func NewTransport

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

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