bitmexwrap

package module
v0.0.0-...-1dccf95 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: LGPL-3.0 Imports: 5 Imported by: 0

README

coinex

The futures coin api。This package only implement fetures exchange of crypto coin. If you want a more common package, see gocryptotrader

Exchange Support

Exchange REST API Streaming API
Bitmex Yes Yes
OKex No No

Cheers to

Original project refer to coinex

Bitmex Websocket refer to gocryptotrader

Bitmex RESTful API use go-swagger

Bitmex Auth refer to ccxt

Documentation

Index

Constants

View Source
const (
	Long  = 1
	Short = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType int
const (
	ActionBuy ActionType = iota
	ActionSell
	ActionOpenLong
	ActionCloseLong
	ActionOpenShort
	ActionCloseShort
)

func (ActionType) String

func (at ActionType) String() (msg string)

type Balance

type Balance struct {
	Currency  string
	Available float64
	Frozen    float64
	Balance   float64
}

type BaseExchanger

type BaseExchanger interface {
	Buy(price float64, amount float64) (*Order, error)
	Sell(price float64, amount float64) (*Order, error)
}

type Candle

type Candle struct {
	ID     int64   `xorm:"pk autoincr null 'id'"`
	Start  int64   `xorm:"unique index 'start'"`
	Open   float64 `xorm:"notnull 'open'"`
	High   float64 `xorm:"notnull 'high'"`
	Low    float64 `xorm:"notnull 'low'"`
	Close  float64 `xorm:"notnull 'close'"`
	VWP    float64 `xorm:"notnull 'vwp'"`
	Volume float64 `xorm:"notnull 'volume'"`
	Trades int64   `xorm:"notnull 'trades'"`
	Table  string  `xorm:"-"`
}

func (Candle) String

func (c Candle) String() string

func (Candle) TableName

func (c Candle) TableName() string

func (Candle) Time

func (c Candle) Time() time.Time

type Config

type Config struct {
	Exchanges map[string]ConfigItem
	Proxy     string
}

func LoadConfigFile

func LoadConfigFile(cfg string) (configs Config, err error)

func LoadConfigs

func LoadConfigs() (configs Config, err error)

func (*Config) Get

func (c *Config) Get(name string) (key, secret string)

type ConfigItem

type ConfigItem struct {
	Type   string
	Key    string
	Secret string
}

type Contract

type Contract struct {
	Symbol string
	Name   string
	Expiry time.Time
}

func (Contract) String

func (c Contract) String() string

type Depth

type Depth Orderbook

type DepthInfo

type DepthInfo struct {
	Price  float64
	Amount float64
}

type FuturesBaseExchanger

type FuturesBaseExchanger interface {
	BaseExchanger
	OpenLong(price float64, amount float64) (*Order, error)
	CloseLong(price float64, amount float64) (*Order, error)
	OpenShort(price float64, amount float64) (*Order, error)
	CloseShort(price float64, amount float64) (*Order, error)
	OpenLongMarket(amount float64) (*Order, error)
	CloseLongMarket(amount float64) (*Order, error)
	OpenShortMarket(amount float64) (*Order, error)
	CloseShortMarket(amount float64) (*Order, error)
}

type FuturesExchanger

type FuturesExchanger interface {
	FuturesBaseExchanger

	Contracts() ([]Contract, error)
	Positions() ([]Position, error)
	ContractBalances() (map[Contract]Balance, error)

	Depth(int) (Orderbook, error)
	Ticker() (Ticker, error)

	SetSymbol(symbol string) error
	SetContract(contract string) error
	SetLever(lever float64) error

	KlineRecent(count int32, binSize string) (klines []*Candle, err error)
	Kline(start, end time.Time, nLimit int, binSize string) (klines []*Candle, err error)
	KlineChan(start, end time.Time, bSize string) (klines chan []interface{}, err error)
}

type Order

type Order struct {
	OrderID    string
	Currency   string
	Amount     float64 // 委托数量
	DealAmount float64 // 成交数量
	Price      float64 // 委托价格
	PriceAvg   float64 // 平均成交价
	Status     string  // 状态
	Side       string
	Type       string
	Time       time.Time
}

type Orderbook

type Orderbook struct {
	Sells      []DepthInfo
	Buys       []DepthInfo
	Symbol     string
	UpdateTime time.Time
}

type Position

type Position struct {
	Info        Contract // 合约信息
	Type        int      // 合约类型,Long: 多头,Short: 空头
	Hold        float64  // 持有仓位
	Price       float64  // 开仓价格/开仓均价 AvgEntryPrice
	CostPrice   float64  // 成本价格
	LastPrice   float64  // 最新成交价
	MarkPrice   float64  // 标记价格
	ProfitRatio float64  // 盈利比例,正数表示盈利,负数表示亏损
}

type Symbol

type Symbol struct {
	Name          string
	BaseCurrency  string `json:"base_currency"`
	QuoteCurrency string `json:"quote_currency"`
	PriceDecimal  int    `json:"price_decimal"`
	AmountDecimal int    `json:"amount_decimal"`
}

type Ticker

type Ticker struct {
	CurrencyPair string
	Last         float64
	High         float64
	Low          float64
	Bid          float64
	Ask          float64
	Volume       float64
	Timestamp    time.Time
}

type Trade

type Trade struct {
	ID     string
	Symbol string
	Time   time.Time
	Price  float64
	Amount float64
	Side   string
	Remark string
}

type TradeAction

type TradeAction struct {
	Action ActionType
	Amount float64
	Price  float64
	Time   time.Time
}

func (*TradeAction) IsBuy

func (ta *TradeAction) IsBuy() bool

Jump to

Keyboard shortcuts

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