swap

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransferEndPoint    = "/v2/account/transfer"
	TransferSpotAccount = "spot"
	TransferSwapAccount = "swap"
)
View Source
const (
	SwapFeeEndPoint         = "/swap-api/v1/swap_fee"
	SwapAccountInfoEndPoint = "/swap-api/v1/swap_account_info"
)
View Source
const (
	SwapHost    = "api.hbdm.com"
	SwapProHost = "api.huobi.pro"
)
View Source
const (
	FinancialRecordEndPoint = "/swap-api/v3/swap_financial_record"

	FinancialRecordTypeFundingIncome  = 30
	FinancialRecordTypeFundingOutCome = 31
)
View Source
const (
	SwapOrderEndPoint       = "/swap-api/v1/swap_order"
	SwapCancelEndPoint      = "/swap-api/v1/swap_cancel"
	SwapOrderDetailEndPoint = "/swap-api/v1/swap_order_detail"

	OrderDirectionBuy  = "buy"
	OrderDirectionSell = "sell"
	OrderOffsetOpen    = "open"
	OrderOffsetClose   = "close"

	OrderPriceLimit    = "limit"
	OrderPriceMarket   = "opponent"
	OrderPriceOptimal5 = "optimal_5"
)
View Source
const (
	ContractEndPoint = "/swap-api/v1/swap_contract_info"
)
View Source
const (
	FundingRateEndPoint = "/swap-api/v1/swap_funding_rate"
)
View Source
const (
	PositionInfoEndPoint = "/swap-api/v1/swap_position_info"
)
View Source
const (
	SwapPrivateAddr = "wss://api.hbdm.com/swap-notification"
)
View Source
const (
	SwapWSAddr = "wss://api.hbdm.com/swap-ws"
)

Variables

This section is empty.

Functions

func Init added in v0.5.0

func Init(ctx context.Context) error

func NewDepthHighFreq added in v0.5.0

func NewDepthHighFreq(symbol string, size DepthSize) exchange.Channel

func NewOrdersChannel added in v0.5.0

func NewOrdersChannel(symbol string) exchange.Channel

func ParseDepth added in v0.5.0

func ParseDepth(raw json.RawMessage) (interface{}, error)

func ParseOrder added in v0.5.0

func ParseOrder(raw []byte) (*exchange.Order, error)

func ParseSymbol added in v0.5.0

func ParseSymbol(sym string) (exchange.SwapSymbol, error)

Types

type AuthResponse added in v0.5.0

type AuthResponse struct {
	Op      string `json:"op"`
	ErrCode int    `json:"err-code"`
	TS      int64  `json:"ts"`
	ErrMsg  string `json:"err-msg"`
}

type CodeC

type CodeC struct {
	*huobi.CodeC
}

func NewCodeC

func NewCodeC() *CodeC

func (*CodeC) Decode

func (cc *CodeC) Decode(raw []byte) (rpc.Response, error)

type ContractInfo

type ContractInfo struct {
	Status string `json:"status"`
	TS     int    `json:"ts"`
	Data   []Data `json:"data"`
}

type Data

type Data struct {
	Symbol         string  `json:"symbol"`
	ContractCode   string  `json:"contract_code"`
	ContractSize   float64 `json:"contract_size"`
	PriceTick      float64 `json:"price_tick"`
	CreateDate     string  `json:"create_date"`
	ContractStatus int     `json:"contract_status"`
	SettlementDate string  `json:"settlement_date"`
}

type Depth added in v0.5.0

type Depth struct {
	Asks    [][2]float64
	Bids    [][2]float64
	Ch      string
	Event   string
	ID      int64
	MrID    int64
	TS      int64
	Version int
}

type DepthHighFreqChannel added in v0.5.0

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

func (*DepthHighFreqChannel) String added in v0.5.0

func (ch *DepthHighFreqChannel) String() string

type DepthSize added in v0.5.0

type DepthSize int
const (
	DepthSize20  DepthSize = 20
	DepthSize150 DepthSize = 150
)

type FinancialRecord added in v0.5.2

type FinancialRecord struct {
	ID           int     `json:"id"`
	Symbol       string  `json:"symbol"`
	Type         int     `json:"type"`
	Amount       float64 `json:"amount"`
	TS           int64   `json:"ts"`
	ContractCode string  `json:"contract_code"`
	QueryID      int64   `json:"query_id"`
}

func (*FinancialRecord) Transform added in v0.5.2

func (fr *FinancialRecord) Transform() (*exchange.Finance, error)

Transform financeRecord to finacial currently only funding type is support

type FinancialRecordRequest added in v0.5.2

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

func NewFinancialRecordRequest added in v0.5.2

func NewFinancialRecordRequest(contractCode string) *FinancialRecordRequest

func (*FinancialRecordRequest) Direct added in v0.5.7

func (*FinancialRecordRequest) EndTime added in v0.5.7

EndTime specific record query end timestamp in milliseconds

func (*FinancialRecordRequest) FromID added in v0.5.7

func (frr *FinancialRecordRequest) FromID(fromID int) *FinancialRecordRequest

func (*FinancialRecordRequest) Serialize added in v0.5.2

func (frr *FinancialRecordRequest) Serialize() ([]byte, error)

func (*FinancialRecordRequest) StartTime added in v0.5.7

StartTime specific record query start timestamp in milliseconds

func (*FinancialRecordRequest) Type added in v0.5.2

func (frr *FinancialRecordRequest) Type(types ...int) *FinancialRecordRequest

type FinancialRecordResponse added in v0.5.2

type FinancialRecordResponse struct {
	Code int               `json:"code"`
	Msg  string            `json:"msg"`
	TS   int64             `json:"ts"`
	Data []FinancialRecord `json:"data"`
}

type FundingRateReq added in v0.5.4

type FundingRateReq struct {
	*exchange.RestReq
}

func NewFundingRateReq added in v0.5.4

func NewFundingRateReq(cc string) *FundingRateReq

type FundingRateResp added in v0.5.4

type FundingRateResp struct {
	EstimmatedRate  decimal.Decimal `json:"estimated_rate"`
	FundingRate     decimal.Decimal `json:"funding_rate"`
	ContractCode    string          `json:"contract_code"`
	Symbol          string          `json:"symbol"`
	FeeAsset        string          `json:"fee_asset"`
	FundingTime     string          `json:"funding_time"`
	NextFundingTime string          `json:"next_funding_time"`
}

func (*FundingRateResp) Transfer added in v0.5.4

func (tr *FundingRateResp) Transfer() (*exchange.FundingRate, error)

type OrderNotify added in v0.5.0

type OrderNotify struct {
	Op             string             `json:"op"`
	Topic          string             `json:"topic"`
	TS             int64              `json:"ts"` //ping message and auth message ts field have different type
	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      int                `json:"lever_rate"`
	OrderID        int64              `json:"order_id"`
	OrderIDStr     string             `json:"order_id_str"`
	ClientOrderID  int64              `json:"client_order_id"`
	OrderType      int                `json:"order_type"`
	CreatedAt      int64              `json:"created_at"`
	TradeVolume    int                `json:"trade_volume"`
	TradeTurnOver  float64            `json:"trade_turnover"`
	Fee            float64            `json:"fee"`
	FeeAsset       string             `json:"fee_asset"`
	TradeAvgPrice  float64            `json:"trade_avg_price"`
	CanceledAt     int64              `json:"canceled_at"`
	RealProfit     float64            `json:"real_profit"`
	Trades         []OrderNotifyTrade `json:"trade"`
}

type OrderNotifyTrade added in v0.5.0

type OrderNotifyTrade struct {
	TradeFee      float64 `json:"trade_fee"`
	FeeAsset      string  `json:"fee_asset"`
	TradeID       int64   `json:"trade_id"`
	ID            string  `json:"id"`
	TradeVolume   float64 `json:"trade_volume"`
	TradePrice    float64 `json:"trade_price"`
	TradeTurnOver float64 `json:"trade_turnover"`
	CreatedAt     int64   `json:"created_at"`
	Profit        float64 `json:"profit"`
	RealProfit    float64 `json:"real_profit"`
	Role          string  `json:"role"`
}

type OrderReq added in v0.5.0

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

func NewOrderReq added in v0.5.0

func NewOrderReq(contractCode string, volume int, direction string, offset string, lever int, orderPriceType string) *OrderReq

func (*OrderReq) Price added in v0.5.0

func (or *OrderReq) Price(price float64) *OrderReq

func (*OrderReq) Serialize added in v0.5.0

func (or *OrderReq) Serialize() ([]byte, error)

type OrderResp added in v0.5.0

type OrderResp struct {
	OrderID    int64  `json:"order_id"`
	OrderIDStr string `json:"order_id_str"`
}

type PingResponse added in v0.5.0

type PingResponse struct {
	Op string `json:"op"`
	TS string `json:"ts"`
}

type Position added in v0.5.2

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

func (*Position) Transfer added in v0.5.2

func (p *Position) Transfer() (*ccexgo.Position, error)

type PositionInfoRequest added in v0.5.2

type PositionInfoRequest struct {
	ContractCode string `json:"contract_code"`
}

func NewPositionInfoRequest added in v0.5.2

func NewPositionInfoRequest(code string) *PositionInfoRequest

func (*PositionInfoRequest) Serialize added in v0.5.2

func (pir *PositionInfoRequest) Serialize() ([]byte, error)

type PrivateCodeC added in v0.5.0

type PrivateCodeC struct {
	*huobi.CodeC
}

func NewPrivateCodeC added in v0.5.0

func NewPrivateCodeC() *PrivateCodeC

func (*PrivateCodeC) Decode added in v0.5.0

func (pcc *PrivateCodeC) Decode(raw []byte) (rpc.Response, error)

func (*PrivateCodeC) Encode added in v0.5.0

func (pcc *PrivateCodeC) Encode(req rpc.Request) ([]byte, error)

type PrivateWSClient added in v0.5.0

type PrivateWSClient struct {
	*exchange.WSClient
	// contains filtered or unexported fields
}

func NewPrivateWSClient added in v0.5.0

func NewPrivateWSClient(key, secret string, data chan interface{}) *PrivateWSClient

func (*PrivateWSClient) Auth added in v0.5.0

func (ws *PrivateWSClient) Auth(ctx context.Context) error

func (*PrivateWSClient) Handle added in v0.5.0

func (ws *PrivateWSClient) Handle(ctx context.Context, notify *rpc.Notify)

func (*PrivateWSClient) Run added in v0.5.0

func (ws *PrivateWSClient) Run(ctx context.Context) error

func (*PrivateWSClient) Subscribe added in v0.5.0

func (ws *PrivateWSClient) Subscribe(ctx context.Context, channels ...exchange.Channel) error

type Response added in v0.5.0

type Response struct {
	Op string `json:"op"`
}

type RestClient

type RestClient struct {
	*huobi.RestClient
}

func NewRestClient

func NewRestClient(key string, secret string) *RestClient

func NewRestClientWithHost added in v0.5.0

func NewRestClientWithHost(key, secret, host string) *RestClient

func (*RestClient) FetchBalance added in v0.5.2

func (rc *RestClient) FetchBalance(ctx context.Context, currencies ...string) (*exchange.Balances, error)

func (*RestClient) FetchFundingRate added in v0.5.4

func (rc *RestClient) FetchFundingRate(ctx context.Context, symbol exchange.Symbol) (*exchange.FundingRate, error)

func (*RestClient) FetchOrder added in v0.5.1

func (rc *RestClient) FetchOrder(ctx context.Context, order *exchange.Order) (*exchange.Order, error)

func (*RestClient) Finance added in v0.5.2

func (rc *RestClient) Finance(ctx context.Context, params *exchange.FinanceReqParam) ([]exchange.Finance, error)

func (*RestClient) FinancialRecord added in v0.5.2

func (*RestClient) PositionInfo added in v0.5.2

func (rc *RestClient) PositionInfo(ctx context.Context, req *PositionInfoRequest) ([]Position, error)

func (*RestClient) PrivatePostReq added in v0.5.0

func (rc *RestClient) PrivatePostReq(ctx context.Context, endPoint string, req interface{}, dst interface{}) error

PrivatePostReq send post request to huobi swap api. the request body is generate from req param vai json.Marshal() or Serialize()

func (*RestClient) SwapAccountInfo added in v0.5.2

func (rc *RestClient) SwapAccountInfo(ctx context.Context, req *SwapAccountInfoReq) ([]SwapAccountInfo, error)

func (*RestClient) SwapCancel added in v0.5.0

func (rc *RestClient) SwapCancel(ctx context.Context, req *SwapCancelReq) (*SwapCancelResp, error)

func (*RestClient) SwapFee added in v0.5.1

func (rc *RestClient) SwapFee(ctx context.Context, req *SwapFeeReq) ([]SwapFee, error)

func (*RestClient) SwapFundingRate added in v0.5.4

func (rc *RestClient) SwapFundingRate(ctx context.Context, req *FundingRateReq) (*FundingRateResp, error)

func (*RestClient) SwapOrder added in v0.5.0

func (rc *RestClient) SwapOrder(ctx context.Context, req *OrderReq) (*OrderResp, error)

func (*RestClient) SwapOrderDetail added in v0.5.1

func (rc *RestClient) SwapOrderDetail(ctx context.Context, req *SwapOrderDetailReq) (*SwapOrderDetailResp, error)

func (*RestClient) Transfer added in v0.5.0

func (rc *RestClient) Transfer(ctx context.Context, req *TransferReq) (*TransferResp, error)

type Serializer added in v0.5.0

type Serializer interface {
	Serialize() ([]byte, error)
}

type SwapAccountInfo added in v0.5.2

type SwapAccountInfo struct {
	Symbol            string          `json:"symbol"`
	ContractCode      string          `json:"contract_code"`
	MarginBalance     decimal.Decimal `json:"margin_balance"`
	MarginFrozen      decimal.Decimal `json:"margin_frozen"`
	MarginAvailable   decimal.Decimal `json:"margin_available"`
	ProfitReal        decimal.Decimal `json:"profit_real"`
	ProfitUnreal      decimal.Decimal `json:"profit_unreal"`
	RiskRate          decimal.Decimal `json:"risk_rate"`
	LiquidationPrice  decimal.Decimal `json:"liquidation_price"`
	WithdrawAvailable decimal.Decimal `json:"withdraw_available"`
	LeverRate         decimal.Decimal `json:"lever_rate"`
	AdjustFactor      decimal.Decimal `json:"adjust_factor"`
}

type SwapAccountInfoReq added in v0.5.2

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

func NewSwapAccountInfoReq added in v0.5.2

func NewSwapAccountInfoReq() *SwapAccountInfoReq

func (*SwapAccountInfoReq) ContractCode added in v0.5.2

func (sai *SwapAccountInfoReq) ContractCode(code string) *SwapAccountInfoReq

func (*SwapAccountInfoReq) Serialize added in v0.5.2

func (sai *SwapAccountInfoReq) Serialize() ([]byte, error)

type SwapCancelError added in v0.5.0

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

type SwapCancelReq added in v0.5.0

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

func NewSwapCancelReq added in v0.5.0

func NewSwapCancelReq(symbol string) *SwapCancelReq

func (*SwapCancelReq) ClientOrderIDs added in v0.5.0

func (scr *SwapCancelReq) ClientOrderIDs(ids ...string) *SwapCancelReq

func (*SwapCancelReq) Orders added in v0.5.0

func (scr *SwapCancelReq) Orders(ids ...string) *SwapCancelReq

func (*SwapCancelReq) Serialize added in v0.5.0

func (scr *SwapCancelReq) Serialize() ([]byte, error)

type SwapCancelResp added in v0.5.0

type SwapCancelResp struct {
	Errors    []SwapCancelError `json:"errors"`
	Successes string            `json:"successes"` //id1,id2,id3 ...
}

type SwapFee added in v0.5.1

type SwapFee struct {
	Symbol        string `json:"symbol"`
	ContractCode  string `json:"contract_code"`
	OpenMakerFee  string `json:"open_maker_fee"`
	OpenTakerFee  string `json:"open_taker_fee"`
	CloseMakerFee string `json:"close_maker_fee"`
	CloseTakerFee string `json:"close_taker_fee"`
	FeeAsset      string `json:"fee_asset"`
}

type SwapFeeReq added in v0.5.1

type SwapFeeReq struct {
	ContractCode string `json:"contract_code"`
}

func NewSwapFeeReq added in v0.5.1

func NewSwapFeeReq(symbol string) *SwapFeeReq

type SwapOrderDetailReq added in v0.5.1

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

func NewSwapOrderDetailReq added in v0.5.1

func NewSwapOrderDetailReq(cc string, id int64) *SwapOrderDetailReq

func (*SwapOrderDetailReq) CreatedAt added in v0.5.1

func (sdr *SwapOrderDetailReq) CreatedAt(ts int64) *SwapOrderDetailReq

func (*SwapOrderDetailReq) OrderType added in v0.5.1

func (sdr *SwapOrderDetailReq) OrderType(ot int) *SwapOrderDetailReq

func (*SwapOrderDetailReq) PageIndex added in v0.5.1

func (sdr *SwapOrderDetailReq) PageIndex(pi int) *SwapOrderDetailReq

func (*SwapOrderDetailReq) PageSize added in v0.5.1

func (sdr *SwapOrderDetailReq) PageSize(ps int) *SwapOrderDetailReq

func (*SwapOrderDetailReq) Serialize added in v0.5.1

func (sdr *SwapOrderDetailReq) Serialize() ([]byte, error)

type SwapOrderDetailResp added in v0.5.1

type SwapOrderDetailResp struct {
	Symbol          string             `json:"symbol"`
	ContractCode    string             `json:"contract_code"`
	LeverRate       int                `json:"lever_rate"`
	Direction       string             `json:"direction"`
	Offset          string             `json:"offset"`
	Volume          float64            `json:"volume"`
	Price           float64            `json:"price"`
	CreatedAt       int64              `json:"created_at"`
	CanceledAt      int64              `json:"canceled_at"`
	OrderSource     string             `json:"order_source"`
	OrderPriceType  string             `json:"order_price_type"`
	MarginFrozen    float64            `json:"margin_frozen"`
	Profit          float64            `json:"profit"`
	Trades          []OrderNotifyTrade `json:"trades"`
	TotalPage       int                `json:"total_page"`
	CurrentPage     int                `json:"current_page"`
	TotalSize       int                `json:"total_size"`
	LiquidationType string             `json:"liquidation_type"`
	FeeAsset        string             `json:"fee_asset"`
	Fee             float64            `json:"fee"`
	OrderID         int64              `json:"order_id"`
	OrderIDStr      string             `json:"order_id_str"`
	ClientOrderID   interface{}        `json:"client_order_id"`
	OrderType       string             `json:"order_type"`
	Status          int                `json:"status"`
	TradeAvgPrice   float64            `json:"trade_avg_price"`
	TradeTurnOver   float64            `json:"trade_turn_over"`
	TradeVolume     float64            `json:"trade_volume"`
	IsTpsl          interface{}        `json:"is_tpsl"`
	RealProfit      float64            `json:"real_profit"`
}

func (*SwapOrderDetailResp) Transform added in v0.5.1

func (r *SwapOrderDetailResp) Transform() (*exchange.Order, error)

type Symbol

type Symbol struct {
	*exchange.BaseSwapSymbol
}

func (*Symbol) String

func (s *Symbol) String() string

type TransferReq added in v0.5.0

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

func NewTransferReq added in v0.5.0

func NewTransferReq(from, to, currency string, amount float64) *TransferReq

NewTransferReq build swap transfer reqeust amount will truncate 8 decimal places

func (*TransferReq) Serialize added in v0.5.0

func (tr *TransferReq) Serialize() ([]byte, error)

type TransferResp added in v0.5.0

type TransferResp struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"string"`
	Success bool        `json:"success"`
}

type WSClient

type WSClient struct {
	*future.WSClientDeriv
}

func NewWSClient

func NewWSClient(data chan interface{}) *WSClient

func (*WSClient) Subscribe

func (ws *WSClient) Subscribe(ctx context.Context, cs ...exchange.Channel) error

Jump to

Keyboard shortcuts

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