hbdmswap

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 15 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountInfo

type AccountInfo struct {
	Symbol            string  `json:"symbol"`
	MarginBalance     float64 `json:"margin_balance"`
	MarginPosition    float64 `json:"margin_position"`
	MarginFrozen      float64 `json:"margin_frozen"`
	MarginAvailable   float64 `json:"margin_available"`
	ProfitReal        float64 `json:"profit_real"`
	ProfitUnreal      float64 `json:"profit_unreal"`
	RiskRate          float64 `json:"risk_rate"` //*interface{}
	WithdrawAvailable float64 `json:"withdraw_available"`
	LiquidationPrice  float64 `json:"liquidation_price"` //*interface{}
	LeverRate         float64 `json:"lever_rate"`
	AdjustFactor      float64 `json:"adjust_factor"`
	MarginStatic      float64 `json:"margin_static"`
	ContractCode      string  `json:"contract_code"`
}

type AccountInfoResult

type AccountInfoResult struct {
	Status  string        `json:"status"` // "ok" , "error"
	ErrCode int           `json:"err_code"`
	ErrMsg  string        `json:"err_msg"`
	Data    []AccountInfo `json:"data"`
	Ts      int64         `json:"ts"`
}

type ApiParameter

type ApiParameter struct {
	Debug              bool
	AccessKey          string
	SecretKey          string
	EnablePrivateSign  bool
	BaseURL            string
	PrivateKeyPrime256 string
	HttpClient         *http.Client
	ProxyURL           string
}

type CancelData

type CancelData struct {
	Errors    []CancelError `json:"errors"`
	Successes string        `json:"successes"`
}

type CancelError

type CancelError struct {
	OrderID string `json:"order_id"`
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
}

type CancelResult

type CancelResult struct {
	Status  string     `json:"status"`
	ErrCode int        `json:"err_code"`
	ErrMsg  string     `json:"err_msg"`
	Data    CancelData `json:"data"`
	Ts      int64      `json:"ts"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(params *ApiParameter) *Client

func (*Client) Cancel

func (c *Client) Cancel(contractCode string, orderID int64, clientOrderID int64) (result CancelResult, err error)

* Cancel 撤销订单

func (*Client) GetAccountInfo

func (c *Client) GetAccountInfo(contractCode string) (result AccountInfoResult, err error)

GetAccountInfo 获取用户账户信息

func (*Client) GetHisOrders

func (c *Client) GetHisOrders(contractCode string, tradeType int, _type int, status int, createDate int,
	pageIndex int, pageSize int) (result HisOrdersResult, err error)

GetHisOrders 获取合约历史委托

func (*Client) GetKLine

func (c *Client) GetKLine(symbol string, period string, size int, from int64, to int64) (result KLineResult, err error)

func (*Client) GetMarketDepth

func (c *Client) GetMarketDepth(contractCode string, _type string) (result MarketDepthResult, err error)

GetMarketDepth 获取行情深度数据 step0-150档 step6-20档 (150档数据) step0, step1, step2, step3, step4, step5(合并深度1-5);step0时,不合并深度, (20档数据) step6, step7, step8, step9, step10, step11(合并深度7-11);step6时,不合并深度

func (*Client) GetOpenOrders

func (c *Client) GetOpenOrders(contractCode string, pageIndex int, pageSize int) (result OpenOrdersResult, err error)

GetOpenOrders 获取合约当前未成交委托单 page_index: 1,2,3...

func (*Client) GetPositionInfo

func (c *Client) GetPositionInfo(contractCode string) (result PositionInfoResult, err error)

GetPositionInfo 用户持仓信息

func (*Client) Heartbeat

func (c *Client) Heartbeat() (result HeartbeatResult, err error)

func (*Client) Order

func (c *Client) Order(contractCode string, clientOrderID int64, price float64,
	volume float64, direction string, offset string, leverRate int, orderPriceType string) (result OrderResult, err error)

Order 合约下单

contract_code: BTC-USD direction: "buy":买 "sell":卖 offset string true "open":开 "close":平 orderPriceType: 订单报价类型 "limit":限价 "opponent":对手价 "post_only":只做maker单,post only下单只受用户持仓数量限制,optimal_5:最优5档、optimal_10:最优10档、optimal_20:最优20档,"fok":FOK订单,"ioc":IOC订单, opponent_ioc": 对手价-IOC下单,"optimal_5_ioc":最优5档-IOC下单,"optimal_10_ioc":最优10档-IOC下单,"optimal_20_ioc":最优20档-IOC下单,"opponent_fok": 对手价-FOK下单,"optimal_5_fok":最优5档-FOK下单,"optimal_10_fok":最优10档-FOK下单,"optimal_20_fok":最优20档-FOK下单

func (*Client) OrderInfo

func (c *Client) OrderInfo(contractCode string, orderID int64, clientOrderID int64) (result OrderInfoResult, err error)

* OrderInfo 获取合约订单信息

type Heartbeat

type Heartbeat struct {
	Heartbeat                 int         `json:"heartbeat"`
	EstimatedRecoveryTime     interface{} `json:"estimated_recovery_time"`
	SwapHeartbeat             int         `json:"swap_heartbeat"`
	SwapEstimatedRecoveryTime interface{} `json:"swap_estimated_recovery_time"`
}

type HeartbeatResult

type HeartbeatResult struct {
	Status string    `json:"status"`
	Data   Heartbeat `json:"data"`
	Ts     int64     `json:"ts"`
}

type HisOrdersData

type HisOrdersData struct {
	Orders      []Order `json:"orders"`
	TotalPage   int     `json:"total_page"`
	CurrentPage int     `json:"current_page"`
	TotalSize   int     `json:"total_size"`
}

type HisOrdersResult

type HisOrdersResult struct {
	Status  string        `json:"status"`
	ErrCode int           `json:"err_code"`
	ErrMsg  string        `json:"err_msg"`
	Data    HisOrdersData `json:"data"`
	Ts      int64         `json:"ts"`
}

type KLine

type KLine struct {
	Amount float64 `json:"amount"`
	Close  float64 `json:"close"`
	Count  int     `json:"count"`
	High   float64 `json:"high"`
	ID     int     `json:"id"`
	Low    float64 `json:"low"`
	Open   float64 `json:"open"`
	Vol    int     `json:"vol"`
}

type KLineResult

type KLineResult struct {
	Ch      string  `json:"ch"`
	Data    []KLine `json:"data"`
	Status  string  `json:"status"`
	ErrCode int     `json:"err_code"`
	ErrMsg  string  `json:"err_msg"`
	Ts      int64   `json:"ts"`
}

type MarketDepthResult

type MarketDepthResult struct {
	Ch      string `json:"ch"`
	Status  string `json:"status"`
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
	Tick    Tick   `json:"tick"`
	Ts      int64  `json:"ts"`
}

type NWS

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

NWS WebSocket 订单和用户数据接口

func NewNWS

func NewNWS(wsURL string, accessKey string, secretKey string) *NWS

NewNWS 创建 NWS wsURL: 正式地址 wss://api.hbdm.com/swap-notification 开发地址 wss://api.btcgateway.pro/swap-notification

func (*NWS) Login

func (ws *NWS) Login() error

Login 授权接口

func (*NWS) SetAccountsCallback

func (ws *NWS) SetAccountsCallback(callback func(accounts *WSAccounts))

func (*NWS) SetLiquidationOrdersCallback

func (ws *NWS) SetLiquidationOrdersCallback(callback func(liquidationOrders *WSLiquidationOrders))

func (*NWS) SetOrdersCallback

func (ws *NWS) SetOrdersCallback(callback func(order *WSOrder))

func (*NWS) SetPositionsCallback

func (ws *NWS) SetPositionsCallback(callback func(positions *WSPositions))

func (*NWS) SetProxy

func (ws *NWS) SetProxy(proxyURL string) (err error)

SetProxy 设置代理地址 porxyURL: socks5://127.0.0.1:1080 https://127.0.0.1:1080

func (*NWS) Start

func (ws *NWS) Start()

func (*NWS) Subscribe

func (ws *NWS) Subscribe(id string, ch map[string]interface{}) error

Subscribe 订阅

func (*NWS) SubscribeAccounts

func (ws *NWS) SubscribeAccounts(id string, symbol string)

SubscribeAccounts 订阅资产变动数据 symbol: BTC-USD

func (*NWS) SubscribeLiquidationOrders

func (ws *NWS) SubscribeLiquidationOrders(id string, symbol string)

SubscribeLiquidationOrders 订阅强平订单数据 symbol: BTC-USD

func (*NWS) SubscribeOrders

func (ws *NWS) SubscribeOrders(id string, symbol string)

SubscribeOrders 订阅订单成交数据 symbol: BTC-USD

func (*NWS) SubscribePositions

func (ws *NWS) SubscribePositions(id string, symbol string)

SubscribePositions 订阅持仓变动更新数据 symbol: BTC-USD

func (*NWS) SubscribeTopic

func (ws *NWS) SubscribeTopic(id string, topic string)

SubscribeTopic 订阅

func (*NWS) Unsubscribe

func (ws *NWS) Unsubscribe(id string) error

Unsubscribe 取消订阅

type OpenOrdersData

type OpenOrdersData struct {
	Orders      []Order `json:"orders"`
	TotalPage   int     `json:"total_page"`
	CurrentPage int     `json:"current_page"`
	TotalSize   int     `json:"total_size"`
}

type OpenOrdersResult

type OpenOrdersResult struct {
	Status  string         `json:"status"`
	ErrCode int            `json:"err_code"`
	ErrMsg  string         `json:"err_msg"`
	Data    OpenOrdersData `json:"data"`
	Ts      int64          `json:"ts"`
}

type Order

type Order struct {
	Symbol            string           `json:"symbol"`
	ContractCode      string           `json:"contract_code"`
	Volume            float64          `json:"volume"`
	Price             float64          `json:"price"`
	OrderPriceTypeRaw sjson.RawMessage `json:"order_price_type"` // 1限价单,3对手价,4闪电平仓,5计划委托,6post_only
	OrderType         int              `json:"order_type"`
	Direction         string           `json:"direction"`
	Offset            string           `json:"offset"`
	LeverRate         int              `json:"lever_rate"`
	OrderID           int64            `json:"order_id"`
	ClientOrderID     string           `json:"client_order_id"`
	CreatedAt         int64            `json:"created_at"`
	TradeVolume       float64          `json:"trade_volume"`
	TradeTurnover     float64          `json:"trade_turnover"`
	Fee               float64          `json:"fee"`
	TradeAvgPrice     float64          `json:"trade_avg_price"`
	MarginFrozen      float64          `json:"margin_frozen"`
	Profit            float64          `json:"profit"`
	Status            int              `json:"status"`
	OrderSource       string           `json:"order_source"`
	OrderIDStr        string           `json:"order_id_str"`
	FeeAsset          string           `json:"fee_asset"`
}

func (*Order) OrderPriceType

func (o *Order) OrderPriceType() string

type OrderData

type OrderData struct {
	OrderID       int64  `json:"order_id"`
	OrderIDStr    string `json:"order_id_str"`
	ClientOrderID int64  `json:"client_order_id"`
}

type OrderInfoResult

type OrderInfoResult struct {
	Status  string  `json:"status"`
	ErrCode int     `json:"err_code"`
	ErrMsg  string  `json:"err_msg"`
	Data    []Order `json:"data"`
	Ts      int64   `json:"ts"`
}

type OrderResult

type OrderResult struct {
	Status  string    `json:"status"`
	ErrCode int       `json:"err_code"`
	ErrMsg  string    `json:"err_msg"`
	Data    OrderData `json:"data"`
	Ts      int64     `json:"ts"`
}

type Position

type Position struct {
	Symbol         string  `json:"symbol"`
	ContractCode   string  `json:"contract_code"`
	Volume         float64 `json:"volume"`
	Available      float64 `json:"available"`
	Frozen         float64 `json:"frozen"`
	CostOpen       float64 `json:"cost_open"`
	CostHold       float64 `json:"cost_hold"`
	ProfitUnreal   float64 `json:"profit_unreal"`
	ProfitRate     float64 `json:"profit_rate"`
	Profit         float64 `json:"profit"`
	PositionMargin float64 `json:"position_margin"`
	LeverRate      int     `json:"lever_rate"`
	Direction      string  `json:"direction"` // "buy":买 "sell":卖
	LastPrice      float64 `json:"last_price"`
}

type PositionInfoResult

type PositionInfoResult struct {
	Status  string     `json:"status"`
	ErrCode int        `json:"err_code"`
	ErrMsg  string     `json:"err_msg"`
	Data    []Position `json:"data"`
	Ts      int64      `json:"ts"`
}

type Tick

type Tick struct {
	Asks    [][]float64 `json:"asks"`
	Bids    [][]float64 `json:"bids"`
	Ch      string      `json:"ch"`
	ID      int64       `json:"id"`
	MrID    int64       `json:"mrid"`
	Ts      int64       `json:"ts"`
	Version int64       `json:"version"`
}

type WS

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

WS WebSocket 市场行情接口

func NewWS

func NewWS(wsURL string, accessKey string, secretKey string, debugMode bool) *WS

NewWS 创建 WS wsURL: 正式地址 wss://api.hbdm.com/swap-ws 开发地址 wss://api.btcgateway.pro/swap-ws

func (*WS) SetDepthCallback

func (ws *WS) SetDepthCallback(callback func(depth *WSDepth))

func (*WS) SetDepthHFCallback

func (ws *WS) SetDepthHFCallback(callback func(depth *WSDepthHF))

func (*WS) SetProxy

func (ws *WS) SetProxy(proxyURL string) (err error)

SetProxy 设置代理地址 porxyURL: socks5://127.0.0.1:1080 https://127.0.0.1:1080

func (*WS) SetTickerCallback

func (ws *WS) SetTickerCallback(callback func(ticker *WSTicker))

func (*WS) SetTradeCallback

func (ws *WS) SetTradeCallback(callback func(trade *WSTrade))

func (*WS) Start

func (ws *WS) Start()

func (*WS) Subscribe

func (ws *WS) Subscribe(id string, ch map[string]interface{}) error

Subscribe 订阅

func (*WS) SubscribeDepth

func (ws *WS) SubscribeDepth(id string, symbol string)

SubscribeDepth 订阅 Market Depth 数据 id: 订阅的编号 symbol: BTC_CQ

func (*WS) SubscribeDepthHF

func (ws *WS) SubscribeDepthHF(id string, symbol string, size int, dateType string)

SubscribeDepthHF 订阅增量深度 size: 20/150 档位数,20:表示20档不合并的深度,150:表示150档不合并的深度 dateType: 数据类型,不填默认为全量数据,"incremental":增量数据,"snapshot":全量数据

func (*WS) SubscribeTicker

func (ws *WS) SubscribeTicker(id string, symbol string)

SubscribeTicker 订阅 Market Ticker 数据 id: 订阅的编号 symbol: BTC_CQ

func (*WS) SubscribeTrade

func (ws *WS) SubscribeTrade(id string, symbol string)

SubscribeTrade 订阅 Market Trade 数据 id: 订阅的编号 symbol: BTC_CQ

func (*WS) Unsubscribe

func (ws *WS) Unsubscribe(id string) error

type WSAccountData

type WSAccountData struct {
	Symbol            string  `json:"symbol"`
	ContractCode      string  `json:"contract_code"`
	MarginBalance     float64 `json:"margin_balance"`
	MarginStatic      float64 `json:"margin_static"`
	MarginPosition    float64 `json:"margin_position"`
	MarginFrozen      float64 `json:"margin_frozen"`
	MarginAvailable   float64 `json:"margin_available"`
	ProfitReal        float64 `json:"profit_real"`
	ProfitUnreal      float64 `json:"profit_unreal"`
	WithdrawAvailable float64 `json:"withdraw_available"`
	RiskRate          float64 `json:"risk_rate"`
	LiquidationPrice  float64 `json:"liquidation_price"`
	LeverRate         float64 `json:"lever_rate"`
	AdjustFactor      float64 `json:"adjust_factor"`
}

type WSAccounts

type WSAccounts struct {
	Op    string          `json:"op"`
	Topic string          `json:"topic"`
	Ts    int64           `json:"ts"`
	Event string          `json:"event"`
	Data  []WSAccountData `json:"data"`
}

type WSDepth

type WSDepth struct {
	Ch   string `json:"ch"`
	Ts   int64  `json:"ts"`
	Tick Tick   `json:"tick"`
}

type WSDepthHF

type WSDepthHF struct {
	Ch   string   `json:"ch"`
	Tick WSTickHF `json:"tick"`
	Ts   int64    `json:"ts"`
}

type WSLiquidationOrderData

type WSLiquidationOrderData struct {
	Symbol       string  `json:"symbol"`
	ContractCode string  `json:"contract_code"`
	Direction    string  `json:"direction"`
	Offset       string  `json:"offset"`
	Volume       float64 `json:"volume"`
	Price        float64 `json:"price"`
	CreatedAt    int64   `json:"created_at"`
}

type WSLiquidationOrders

type WSLiquidationOrders struct {
	Op    string                   `json:"op"`
	Topic string                   `json:"topic"`
	Ts    int64                    `json:"ts"`
	Data  []WSLiquidationOrderData `json:"data"`
}

type WSMyTrade

type WSMyTrade struct {
	TradeID       int64   `json:"trade_id"`
	ID            string  `json:"id"`
	TradeVolume   float64 `json:"trade_volume"`
	TradePrice    float64 `json:"trade_price"`
	TradeFee      float64 `json:"trade_fee"`
	FeeAsset      string  `json:"fee_asset"`
	TradeTurnover float64 `json:"trade_turnover"`
	CreatedAt     int64   `json:"created_at"`
	Role          string  `json:"role"`
}

type WSOrder

type WSOrder struct {
	Op             string      `json:"op"`
	Topic          string      `json:"topic"`
	Ts             int64       `json:"ts"`
	Symbol         string      `json:"symbol"`
	ContractCode   string      `json:"contract_code"`
	Volume         float64     `json:"volume"`
	Price          float64     `json:"price"`
	OrderPriceType string      `json:"order_price_type"`
	Direction      string      `json:"direction"`
	Offset         string      `json:"offset"`
	Status         int         `json:"status"`
	LeverRate      float64     `json:"lever_rate"`
	OrderID        int64       `json:"order_id"`
	OrderIDStr     string      `json:"order_id_str"`
	ClientOrderID  int64       `json:"client_order_id"`
	OrderSource    string      `json:"order_source"`
	OrderType      int         `json:"order_type"`
	CreatedAt      int64       `json:"created_at"`
	TradeVolume    float64     `json:"trade_volume"`
	TradeTurnover  float64     `json:"trade_turnover"`
	Fee            float64     `json:"fee"`
	TradeAvgPrice  float64     `json:"trade_avg_price"`
	MarginFrozen   float64     `json:"margin_frozen"`
	Profit         float64     `json:"profit"`
	Trade          []WSMyTrade `json:"trade"`
}

type WSPositionData

type WSPositionData struct {
	Symbol         string  `json:"symbol"`
	ContractCode   string  `json:"contract_code"`
	Volume         float64 `json:"volume"`
	Available      float64 `json:"available"`
	Frozen         float64 `json:"frozen"`
	CostOpen       float64 `json:"cost_open"`
	CostHold       float64 `json:"cost_hold"`
	ProfitUnreal   float64 `json:"profit_unreal"`
	ProfitRate     float64 `json:"profit_rate"`
	Profit         float64 `json:"profit"`
	PositionMargin float64 `json:"position_margin"`
	LeverRate      float64 `json:"lever_rate"`
	Direction      string  `json:"direction"`
	LastPrice      float64 `json:"last_price"`
}

type WSPositions

type WSPositions struct {
	Op    string           `json:"op"`
	Topic string           `json:"topic"`
	Ts    int64            `json:"ts"`
	Event string           `json:"event"`
	Data  []WSPositionData `json:"data"`
}

type WSTick

type WSTick struct {
	MrID    int64       `json:"mrid"`
	ID      int         `json:"id"`
	Bids    [][]float64 `json:"bids"`
	Asks    [][]float64 `json:"asks"`
	Ts      int64       `json:"ts"`
	Version int         `json:"version"`
	Ch      string      `json:"ch"`
}

type WSTickHF

type WSTickHF struct {
	Asks    [][]float64 `json:"asks"`
	Bids    [][]float64 `json:"bids"`
	Ch      string      `json:"ch"`
	Event   string      `json:"event"`
	ID      int64       `json:"id"`
	Mrid    int64       `json:"mrid"`
	Ts      int64       `json:"ts"`
	Version int         `json:"version"`
}

type WSTicker

type WSTicker struct {
	Ch   string       `json:"ch"`
	Ts   int64        `json:"ts"`
	Tick WSTickerTick `json:"tick"`
}

type WSTickerTick

type WSTickerTick struct {
	ID     int64   `json:"id"`
	MrID   int64   `json:"mrid"`
	Open   float64 `json:"open"`
	Close  float64 `json:"close"`
	High   float64 `json:"high"`
	Low    float64 `json:"low"`
	Amount float64 `json:"amount"`
	Vol    float64 `json:"vol"`
	Count  int64   `json:"count"`
}

type WSTrade

type WSTrade struct {
	Ch   string      `json:"ch"`
	Ts   int64       `json:"ts"`
	Tick WSTradeTick `json:"tick"`
}

type WSTradeItem

type WSTradeItem struct {
	Amount    int     `json:"amount"`
	Ts        int64   `json:"ts"`
	ID        int64   `json:"id"`
	Price     float64 `json:"price"`
	Direction string  `json:"direction"`
}

type WSTradeTick

type WSTradeTick struct {
	ID   int64         `json:"id"`
	Ts   int64         `json:"ts"`
	Data []WSTradeItem `json:"data"`
}

Jump to

Keyboard shortcuts

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