phemex

package module
v0.0.0-...-e3a4376 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 20 Imported by: 2

README

go-phemex

A Golang SDK for phemex API.

Build Status GoDoc Go Report Card codecov

Most REST APIs listed in phemex API document are implemented, as well as the AOP websocket APIs.

For best compatibility, please use Go >= 1.8.

Make sure you have read phemex API document before continuing.

API List

Name Description Status
rest-api.md Details on the Rest API

Installation

go get github.com/Krisa/go-phemex

Importing

import (
    "github.com/Krisa/go-phemex"
)

Documentation

GoDoc

REST API

Setup

Init client for API services. Get APIKey/SecretKey from your phemex account.

var (
    apiKey = "your api key"
    secretKey = "your secret key"
)
client := phemex.NewClient(apiKey, secretKey)

A service instance stands for a REST API endpoint and is initialized by client.NewXXXService function.

Simply call API in chain style. Call Do() in the end to send HTTP request.

Create Order

order, err := client.NewCreateOrderService().Symbol("BTCUSD").
        Side(phemex.SideTypeBuy).Type(phemex.OrderTypeLimit).
        TimeInForce(phemex.TimeInForceTypeGTC).Quantity("5").
        Price("1000").Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(order)

Cancel Order

_, err := client.NewCancelOrderService().Symbol("BTCUSD").
    OrderID(4432844).Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}

List Open Orders

openOrders, err := client.NewListOpenOrdersService().Symbol("BTCUSD").
    Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, o := range openOrders {
    fmt.Println(o)
}

Get Account

res, err := client.NewGetAccountPositionService().Currency("BTC").Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(res)

Websocket

You initiate PhemexClient the same way

User Data

wsHandler := func(message interface{}) {
    switch message := message.(type) {
    case *phemex.WsAOP:
        // snapshots / increments
    case *phemex.WsPositionInfo:
        // when a position is active
    case *phemex.WsError:
        // on connection
    }
}

errHandler := func(err error) {
    // initiate reconnection with `once.Do...`
}

auth := PhemexClient.NewWsAuthService()

if test {
    auth = auth.URL("wss://testnet.phemex.com/ws")
}

c, err := auth.Do(context.Background())
// err handling

err = PhemexClient.NewStartWsAOPService().SetID(1).Do(c, wsHandler, errHandler)
// err handling

Documentation

Overview

Package phemex is a Golang SDK for binance APIs.

Index

Constants

View Source
const (
	ExchangeMarginTypeBTCToWallet ExchangeMarginType = 1
	ExchangeMarginTypeWalletToBTC ExchangeMarginType = 2
	ExchangeMarginTypeWalletToUSD ExchangeMarginType = 3
	ExchangeMarginTypeUSDToWallet ExchangeMarginType = 4

	SideTypeBuy  SideType = "Buy"
	SideTypeSell SideType = "Sell"

	OrderTypeLimit           OrderType = "Limit"
	OrderTypeMarket          OrderType = "Market"
	OrderTypeStop            OrderType = "Stop"
	OrderTypeStopLimit       OrderType = "StopLimit"
	OrderTypeMarketIfTouched OrderType = "MarketIfTouched"
	OrderTypeLimitIfTouched  OrderType = "LimitIfTouched"
	OrderTypePegged          OrderType = "Pegged"

	TimeInForceTypeDAY TimeInForceType = "Day"
	TimeInForceTypeGTC TimeInForceType = "GoodTillCancel"
	TimeInForceTypeIOC TimeInForceType = "ImmediateOrCancel"
	TimeInForceTypeFOK TimeInForceType = "FillOrKill"

	TriggerTypeByMarkPrice TriggerType = "ByMarkPrice"
	TriggerTypeByLastPrice TriggerType = "ByLastPrice"
)

Global enums

Variables

View Source
var (

	// WebsocketTimeout is an interval for sending ping/pong messages if WebsocketKeepalive is enabled
	WebsocketTimeout = 5 * time.Second
	// WebsocketKeepalive enables sending ping/pong messages to check the connection stability
	WebsocketKeepalive = true
)

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountID          int64   `json:"accountId"`
	Currency           string  `json:"currency"`
	AccountBalanceEv   float64 `json:"accountBalanceEv"`
	TotalUsedBalanceEv float64 `json:"totalUsedBalanceEv"`
}

Account account detail

type AccountPosition

type AccountPosition struct {
	Account   Account     `json:"account"`
	Positions []*Position `json:"positions"`
}

AccountPosition define account position info

type BaseResponse

type BaseResponse struct {
	Code int64       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

BaseResponse base response for all requests

type BaseTickerResponse

type BaseTickerResponse struct {
	Error  int64       `json:"error"`
	ID     int64       `json:"id"`
	Result interface{} `json:"result"`
}

BaseTickerResponse base ticker response

type CancelOrderService

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

CancelOrderService cancel an order

func (*CancelOrderService) Do

func (s *CancelOrderService) Do(ctx context.Context, opts ...RequestOption) (res *OrderResponse, err error)

Do send request

func (*CancelOrderService) OrderID

func (s *CancelOrderService) OrderID(orderID string) *CancelOrderService

OrderID set orderID

func (*CancelOrderService) Symbol

func (s *CancelOrderService) Symbol(symbol string) *CancelOrderService

Symbol set symbol

type Client

type Client struct {
	APIKey     string
	SecretKey  string
	BaseURL    string
	UserAgent  string
	HTTPClient *http.Client
	Debug      bool
	Logger     *log.Logger
	// contains filtered or unexported fields
}

Client define API client

func NewClient

func NewClient(apiKey, secretKey string) *Client

NewClient initialize an API client instance with API key and secret key. You should always call this function before using this SDK. Services will be created by the form client.NewXXXService().

func (*Client) NewCancelOrderService

func (c *Client) NewCancelOrderService() *CancelOrderService

NewCancelOrderService init cancel order service

func (*Client) NewCreateOrderService

func (c *Client) NewCreateOrderService() *CreateOrderService

NewCreateOrderService init create order service

func (*Client) NewCreateReplaceOrderService

func (c *Client) NewCreateReplaceOrderService() *CreateReplaceOrderService

NewCreateReplaceOrderService init replace order service

func (*Client) NewExchangeMarginService

func (c *Client) NewExchangeMarginService() *ExchangeMarginService

NewExchangeMarginService transfer funds between main wallet and margin account

func (*Client) NewExchangeProductsService

func (c *Client) NewExchangeProductsService() *ExchangeProductsService

NewExchangeProductsService init exchange info service

func (*Client) NewGetAccountPositionService

func (c *Client) NewGetAccountPositionService() *GetAccountPositionService

NewGetAccountPositionService init getting account position service

func (*Client) NewGetUserWalletService

func (c *Client) NewGetUserWalletService() *GetUserWalletService

NewGetUserWalletService getting wallet service

func (*Client) NewListOpenOrdersService

func (c *Client) NewListOpenOrdersService() *ListOpenOrdersService

NewListOpenOrdersService init list open orders service

func (*Client) NewListPriceChangeStatsService

func (c *Client) NewListPriceChangeStatsService() *ListPriceChangeStatsService

NewListPriceChangeStatsService init list prices change stats service

func (*Client) NewPositionsAssignService

func (c *Client) NewPositionsAssignService() *PositionsAssignService

NewPositionsAssignService init positions assign service

func (*Client) NewPositionsLeverageService

func (c *Client) NewPositionsLeverageService() *PositionsLeverageService

NewPositionsLeverageService init positions leverage service

func (*Client) NewQueryOrderService

func (c *Client) NewQueryOrderService() *QueryOrderService

NewQueryOrderService init query order service

func (*Client) NewStartWsAOPService

func (c *Client) NewStartWsAOPService() *StartWsAOPService

NewStartWsAOPService AOP service

func (*Client) NewStartWsOrderBookService

func (c *Client) NewStartWsOrderBookService() *StartWsOrderBookService

NewStartWsOrderBookService OrderBook service

func (*Client) NewStartWsTradeService

func (c *Client) NewStartWsTradeService() *StartWsTradeService

NewStartWsTradeService Trade service

func (*Client) NewWsAuthService

func (c *Client) NewWsAuthService() *WsAuthService

NewWsAuthService init starting auth ws service

type CreateOrderService

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

CreateOrderService create order

func (*CreateOrderService) ActionBy

func (s *CreateOrderService) ActionBy(actionBy string) *CreateOrderService

ActionBy set actionBy

func (*CreateOrderService) ClOrdID

func (s *CreateOrderService) ClOrdID(clOrdID string) *CreateOrderService

ClOrdID set clOrID

func (*CreateOrderService) CloseOnTrigger

func (s *CreateOrderService) CloseOnTrigger(closeOnTrigger bool) *CreateOrderService

CloseOnTrigger set closeOnTrigger

func (*CreateOrderService) Do

func (s *CreateOrderService) Do(ctx context.Context, opts ...RequestOption) (res *OrderResponse, err error)

Do send request

func (*CreateOrderService) OrdType

func (s *CreateOrderService) OrdType(ordType OrderType) *CreateOrderService

OrdType set ordType

func (*CreateOrderService) OrderQty

func (s *CreateOrderService) OrderQty(orderQty float64) *CreateOrderService

OrderQty set orderQty

func (*CreateOrderService) PegOffsetValueEp

func (s *CreateOrderService) PegOffsetValueEp(pegOffsetValueEp int64) *CreateOrderService

PegOffsetValueEp set pegOffsetValueEp

func (*CreateOrderService) PegPriceType

func (s *CreateOrderService) PegPriceType(pegPriceType string) *CreateOrderService

PegPriceType set pegPriceType

func (*CreateOrderService) PriceEp

func (s *CreateOrderService) PriceEp(priceEp int64) *CreateOrderService

PriceEp set priceEp

func (*CreateOrderService) ReduceOnly

func (s *CreateOrderService) ReduceOnly(reduceOnly bool) *CreateOrderService

ReduceOnly set reduceOnly

func (*CreateOrderService) Side

Side set side

func (*CreateOrderService) StopLossEp

func (s *CreateOrderService) StopLossEp(stopLossEp int64) *CreateOrderService

StopLossEp set stopLossEp

func (*CreateOrderService) StopPxEp

func (s *CreateOrderService) StopPxEp(stopPxEp int64) *CreateOrderService

StopPxEp set stopPxEp

func (*CreateOrderService) Symbol

func (s *CreateOrderService) Symbol(symbol string) *CreateOrderService

Symbol set symbol

func (*CreateOrderService) TakeProfitEp

func (s *CreateOrderService) TakeProfitEp(takeProfitEp int64) *CreateOrderService

TakeProfitEp set takeProfitEp

func (*CreateOrderService) Text

Text set text

func (*CreateOrderService) TimeInForce

func (s *CreateOrderService) TimeInForce(timeInForce TimeInForceType) *CreateOrderService

TimeInForce set timeInForce

func (*CreateOrderService) TriggerType

func (s *CreateOrderService) TriggerType(triggerType TriggerType) *CreateOrderService

TriggerType set triggerType

type CreateReplaceOrderService

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

CreateReplaceOrderService create order

func (*CreateReplaceOrderService) ClOrdID

ClOrdID set clOrID

func (*CreateReplaceOrderService) Do

Do send request

func (*CreateReplaceOrderService) OrderID

OrderID set orderID

func (*CreateReplaceOrderService) OrderQty

OrderQty set orderQty

func (*CreateReplaceOrderService) OrigClOrdID

func (s *CreateReplaceOrderService) OrigClOrdID(origClOrdID string) *CreateReplaceOrderService

OrigClOrdID set origClOrdID

func (*CreateReplaceOrderService) PegOffset

PegOffset set pegOffset

func (*CreateReplaceOrderService) PegOffsetEp

func (s *CreateReplaceOrderService) PegOffsetEp(pegOffsetEp int64) *CreateReplaceOrderService

PegOffsetEp set pegOffsetEp

func (*CreateReplaceOrderService) Price

Price set price

func (*CreateReplaceOrderService) PriceEp

PriceEp set priceEp

func (*CreateReplaceOrderService) StopLoss

StopLoss set stopLoss

func (*CreateReplaceOrderService) StopLossEp

func (s *CreateReplaceOrderService) StopLossEp(stopLossEp int64) *CreateReplaceOrderService

StopLossEp set stopLossEp

func (*CreateReplaceOrderService) StopPx

StopPx set stopPx

func (*CreateReplaceOrderService) StopPxEp

StopPxEp set stopPxEp

func (*CreateReplaceOrderService) Symbol

Symbol set symbol

func (*CreateReplaceOrderService) TakeProfit

func (s *CreateReplaceOrderService) TakeProfit(takeProfit float64) *CreateReplaceOrderService

TakeProfit set takeProfit

func (*CreateReplaceOrderService) TakeProfitEp

func (s *CreateReplaceOrderService) TakeProfitEp(takeProfitEp int64) *CreateReplaceOrderService

TakeProfitEp set takeProfitEp

type ErrHandler

type ErrHandler func(err error)

ErrHandler handles errors

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error ws error

type ExchangeCurrency

type ExchangeCurrency struct {
}

type ExchangeLeverage

type ExchangeLeverage struct{}

type ExchangeMargin

type ExchangeMargin struct {
	MoveOp           int    `json:"moveOp"`
	FromCurrencyName string `json:"fromCurrencyName"`
	ToCurrencyName   string `json:"toCurrencyName"`
	FromAmount       string `json:"fromAmount"`
	ToAmount         string `json:"toAmount"`
	LinkKey          string `json:"linkKey"`
	Status           int64  `json:"status"`
}

ExchangeMargin exchange margin

type ExchangeMarginService

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

ExchangeMarginService get account info

func (*ExchangeMarginService) BtcAmount

func (s *ExchangeMarginService) BtcAmount(btcAmount float64) *ExchangeMarginService

BtcAmount set btcAmount

func (*ExchangeMarginService) BtcAmountEv

func (s *ExchangeMarginService) BtcAmountEv(btcAmountEv int64) *ExchangeMarginService

BtcAmountEv set btcAmountEv

func (*ExchangeMarginService) Do

Do send request

func (*ExchangeMarginService) LinkKey

func (s *ExchangeMarginService) LinkKey(linkKey string) *ExchangeMarginService

LinkKey set linkKey

func (*ExchangeMarginService) MoveOp

MoveOp set moveOp

func (*ExchangeMarginService) UsdAmount

func (s *ExchangeMarginService) UsdAmount(usdAmount float64) *ExchangeMarginService

UsdAmount set usdAmount

func (*ExchangeMarginService) UsdAmountEv

func (s *ExchangeMarginService) UsdAmountEv(usdAmountEv int64) *ExchangeMarginService

UsdAmountEv set usdAmountEv

type ExchangeMarginType

type ExchangeMarginType int

ExchangeMarginType define exchange margin type

type ExchangeProduct

type ExchangeProduct struct {
	Symbol                   string  `json:"symbol"`
	Code                     int64   `json:"code"`
	DisplaySymbol            string  `json:"displaySymbol"`
	IndexSymbol              string  `json:"indexSymbol"`
	MarkSymbol               string  `json:"markSymbol"`
	FundingRateSymbol        string  `json:"fundingRateSymbol"`
	FundingRate8HSymbol      string  `json:"fundingRate8hSymbol"`
	ContractUnderlyingAssets string  `json:"contractUnderlyingAssets"`
	SettleCurrency           string  `json:"settleCurrency"`
	QuoteCurrency            string  `json:"quoteCurrency"`
	ContractSize             float64 `json:"contractSize"`
	LotSize                  int64   `json:"lotSize"`
	TickSize                 float64 `json:"tickSize"`
	PriceScale               int64   `json:"priceScale"`
	RatioScale               int64   `json:"ratioScale"`
	PricePrecision           int64   `json:"pricePrecision"`
	MinPriceEp               int64   `json:"minPriceEp"`
	MaxPriceEp               int64   `json:"maxPriceEp"`
	MaxOrderQty              int64   `json:"maxOrderQty"`
	Type                     string  `json:"type"`
	Status                   string  `json:"status"`
	TipOrderQty              int64   `json:"tipOrderQty"`
	Description              string  `json:"description"`
}

type ExchangeProductsService

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

ExchangeProductsService exchange info service

func (*ExchangeProductsService) Do

Do send request

type ExchangeProductsServiceResponse

type ExchangeProductsServiceResponse struct {
	Currencies []ExchangeCurrency  `json:"currencies"`
	Products   []ExchangeProduct   `json:"products"`
	RiskLimits []ExchangeRiskLimit `json:"riskLimitsV2"`
	Leverages  []ExchangeLeverage  `json:"leverages"`
}

type ExchangeRiskLimit

type ExchangeRiskLimit struct{}

type GetAccountPositionService

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

GetAccountPositionService get account info

func (*GetAccountPositionService) Currency

Currency set currency

func (*GetAccountPositionService) Do

Do send request

type GetUserWalletService

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

GetUserWalletService get account info

func (*GetUserWalletService) Do

Do send request

func (*GetUserWalletService) Limit

Limit set limit

func (*GetUserWalletService) Offset

func (s *GetUserWalletService) Offset(offset int64) *GetUserWalletService

Offset set offset

func (*GetUserWalletService) WithCount

func (s *GetUserWalletService) WithCount(withCount int64) *GetUserWalletService

WithCount set with count

type ListOpenOrdersService

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

ListOpenOrdersService list opened orders

func (*ListOpenOrdersService) Do

func (s *ListOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*OrderResponse, err error)

Do send request

func (*ListOpenOrdersService) Symbol

Symbol set symbol

type ListPriceChangeStatsService

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

ListPriceChangeStatsService show stats of price change in last 24 hours for all symbols

func (*ListPriceChangeStatsService) Do

Do send request

func (*ListPriceChangeStatsService) Symbol

Symbol set symbol

type OrderResponse

type OrderResponse struct {
	BizError       int             `json:"bizError"`
	OrderID        string          `json:"orderID"`
	ClOrdID        string          `json:"clOrdID"`
	Symbol         string          `json:"symbol"`
	Side           SideType        `json:"side"`
	ActionTimeNs   int64           `json:"actionTimeNs"`
	TransactTimeNs int64           `json:"transactTimeNs"`
	OrderType      OrderType       `json:"orderType"`
	PriceEp        int64           `json:"priceEp"`
	Price          float64         `json:"price"`
	OrderQty       float64         `json:"orderQty"`
	DisplayQty     float64         `json:"displayQty"`
	TimeInForce    TimeInForceType `json:"timeInForce"`
	ReduceOnly     bool            `json:"reduceOnly"`
	TakeProfitEp   int64           `json:"takeProfitEp"`
	TakeProfit     float64         `json:"takeProfit"`
	StopPxEp       int64           `json:"stopPxEp"`
	StopPx         float64         `json:"stopPx"`
	StopLossEp     int64           `json:"stopLossEp"`
	ClosedPnlEv    int64           `json:"closedPnlEv"`
	ClosedPnl      float64         `json:"closedPnl"`
	ClosedSize     float64         `json:"closedSize"`
	CumQty         float64         `json:"cumQty"`
	CumValueEv     int64           `json:"cumValueEv"`
	CumValue       float64         `json:"cumValue"`
	LeavesQty      float64         `json:"leavesQty"`
	LeavesValueEv  int64           `json:"leavesValueEv"`
	LeavesValue    float64         `json:"leavesValue"`
	StopLoss       float64         `json:"stopLoss"`
	StopDirection  string          `json:"stopDirection"`
	OrdStatus      string          `json:"ordStatus"`
	Trigger        string          `json:"trigger"`
}

OrderResponse define create order response

type OrderType

type OrderType string

OrderType define order type

type Position

type Position struct {
	AccountID              int64   `json:"accountID"`
	Symbol                 string  `json:"symbol"`
	Currency               string  `json:"currency"`
	Side                   string  `json:"side"`
	PositionStatus         string  `json:"positionStatus"`
	CrossMargin            bool    `json:"crossMargin"`
	LeverageEr             float64 `json:"leverageEr"`
	Leverage               float64 `json:"leverage"`
	InitMarginReqEr        float64 `json:"initMarginReqEr"`
	InitMarginReq          float64 `json:"initMarginReq"`
	MaintMarginReqEr       float64 `json:"maintMarginReqEr"`
	MaintMarginReq         float64 `json:"maintMarginReq"`
	RiskLimitEv            float64 `json:"riskLimitEv"`
	RiskLimit              float64 `json:"riskLimit"`
	Size                   float64 `json:"size"`
	Value                  float64 `json:"value"`
	ValueEv                float64 `json:"valueEv"`
	AvgEntryPriceEp        float64 `json:"avgEntryPriceEp"`
	AvgEntryPrice          float64 `json:"avgEntryPrice"`
	PosCostEv              float64 `json:"posCostEv"`
	PosCost                float64 `json:"posCost"`
	AssignedPosBalanceEv   float64 `json:"assignedPosBalanceEv"`
	AssignedPosBalance     float64 `json:"assignedPosBalance"`
	BankruptCommEv         float64 `json:"bankruptCommEv"`
	BankruptComm           float64 `json:"bankruptComm"`
	BankruptPriceEp        float64 `json:"bankruptPriceEp"`
	BankruptPrice          float64 `json:"bankruptPrice"`
	PositionMarginEv       float64 `json:"positionMarginEv"`
	PositionMargin         float64 `json:"positionMargin"`
	LiquidationPriceEp     float64 `json:"liquidationPriceEp"`
	LiquidationPrice       float64 `json:"liquidationPrice"`
	DeleveragePercentileEr float64 `json:"deleveragePercentileEr"`
	DeleveragePercentile   float64 `json:"deleveragePercentile"`
	BuyValueToCostEr       float64 `json:"buyValueToCostEr"`
	BuyValueToCost         float64 `json:"buyValueToCost"`
	SellValueToCostEr      float64 `json:"sellValueToCostEr"`
	SellValueToCost        float64 `json:"sellValueToCost"`
	MarkPriceEp            float64 `json:"markPriceEp"`
	MarkPrice              float64 `json:"markPrice"`
	MarkValueEv            float64 `json:"markValueEv"`
	MarkValue              float64 `json:"markValue"`
	UnRealisedPosLossEv    float64 `json:"unRealisedPosLossEv"`
	UnRealisedPosLoss      float64 `json:"unRealisedPosLoss"`
	EstimatedOrdLossEv     float64 `json:"estimatedOrdLossEv"`
	EstimatedOrdLoss       float64 `json:"estimatedOrdLoss"`
	UsedBalanceEv          float64 `json:"usedBalanceEv"`
	UsedBalance            float64 `json:"usedBalance"`
	TakeProfitEp           float64 `json:"takeProfitEp"`
	TakeProfit             float64 `json:"takeProfit"`
	StopLossEp             float64 `json:"stopLossEp"`
	StopLoss               float64 `json:"stopLoss"`
	RealisedPnlEv          float64 `json:"realisedPnlEv"`
	RealisedPnl            float64 `json:"realisedPnl"`
	CumRealisedPnlEv       float64 `json:"cumRealisedPnlEv"`
	CumRealisedPnl         float64 `json:"cumRealisedPnl"`
}

Position position detail

type PositionInfo

type PositionInfo struct {
	AccountID int64   `json:"accountID"`
	Light     float64 `json:"light"`
	Symbol    string  `json:"symbol"`
	UserID    int64   `json:"userID"`
}

PositionInfo position info

type PositionsAssignService

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

PositionsAssignService cancel an order

func (*PositionsAssignService) Do

func (s *PositionsAssignService) Do(ctx context.Context, opts ...RequestOption) (res *BaseResponse, err error)

Do send request

func (*PositionsAssignService) PosBalance

func (s *PositionsAssignService) PosBalance(posBalance float64) *PositionsAssignService

PosBalance set posBalance

func (*PositionsAssignService) PosBalanceEr

func (s *PositionsAssignService) PosBalanceEr(posBalanceEv int64) *PositionsAssignService

PosBalanceEr set posBalanceEv

func (*PositionsAssignService) Symbol

Symbol set symbol

type PositionsLeverageService

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

PositionsLeverageService cancel an order

func (*PositionsLeverageService) Do

func (s *PositionsLeverageService) Do(ctx context.Context, opts ...RequestOption) (res *BaseResponse, err error)

Do send request

func (*PositionsLeverageService) Leverage

Leverage set leverage

func (*PositionsLeverageService) LeverageEr

func (s *PositionsLeverageService) LeverageEr(leverageEr int64) *PositionsLeverageService

LeverageEr set leverageEr

func (*PositionsLeverageService) Symbol

Symbol set symbol

type PriceChangeStats

type PriceChangeStats struct {
	AskEp             int64   `json:"askEp"`
	BidEp             int64   `json:"bidEp"`
	OpenEp            int64   `json:"openEp"`
	HighEp            int64   `json:"highEp"`
	LowEp             int64   `json:"lowEp"`
	LastEp            int64   `json:"lastEp"`
	IndexEp           int64   `json:"indexEp"`
	MarkEp            int64   `json:"markEp"`
	OpenInterest      float64 `json:"openInterest"`
	FundingRateEr     float64 `json:"fundingRateEr"`
	PredFundingRateEr float64 `json:"predFundingRateEr"`
	Timestamp         int64   `json:"timestamp"`
	Symbol            string  `json:"symbol"`
	TurnoverEv        int64   `json:"turnoverEv"`
	Volume            float64 `json:"volume"`
}

PriceChangeStats define price change stats

type QueryOrderService

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

QueryOrderService cancel an order

func (*QueryOrderService) ClOrderID

func (s *QueryOrderService) ClOrderID(clOrderID string) *QueryOrderService

ClOrderID set clOrderID

func (*QueryOrderService) Do

func (s *QueryOrderService) Do(ctx context.Context, opts ...RequestOption) (res []*OrderResponse, err error)

Do send request

func (*QueryOrderService) OrderID

func (s *QueryOrderService) OrderID(orderID string) *QueryOrderService

OrderID set orderID

func (*QueryOrderService) Symbol

func (s *QueryOrderService) Symbol(symbol string) *QueryOrderService

Symbol set symbol

type RequestOption

type RequestOption func(*request)

RequestOption define option type for request

func WithRecvWindow

func WithRecvWindow(recvWindow int64) RequestOption

WithRecvWindow set recvWindow param for the request

type RowsOrderResponse

type RowsOrderResponse struct {
	Rows []*OrderResponse `json:"rows"`
}

RowsOrderResponse rows order response

type SideType

type SideType string

SideType define side type of order

type StartWsAOPService

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

StartWsAOPService create listen key for user stream service

func (*StartWsAOPService) Do

func (s *StartWsAOPService) Do(c *websocket.Conn, handler WsHandler, errHandler ErrHandler, opts ...RequestOption) (err error)

Do send request

func (*StartWsAOPService) SetID

SetID set id

type StartWsOrderBookService

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

StartWsOrderBookService :

func (*StartWsOrderBookService) Do

func (s *StartWsOrderBookService) Do(c *websocket.Conn, handler WsHandler, errHandler ErrHandler, opts ...RequestOption) (err error)

Do :

func (*StartWsOrderBookService) ID

ID :

func (*StartWsOrderBookService) Symbols

Symbols :

type StartWsTradeService

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

StartWsTradeService :

func (*StartWsTradeService) Do

func (s *StartWsTradeService) Do(c *websocket.Conn, handler WsHandler, errHandler ErrHandler, opts ...RequestOption) (err error)

Do :

func (*StartWsTradeService) ID

ID :

func (*StartWsTradeService) Symbols

func (s *StartWsTradeService) Symbols(symbols []string) *StartWsTradeService

Symbols :

type Status

type Status struct {
	Status string `json:"status"`
}

Status status

type TimeInForceType

type TimeInForceType string

TimeInForceType define time in force type of order

type TriggerType

type TriggerType string

TriggerType define trigger type

type UserMarginUserWalletVo

type UserMarginUserWalletVo struct {
	Currency           string  `json:"currency"`
	AccountBalance     string  `json:"accountBalance"`
	TotalUsedBalance   string  `json:"totalUsedBalance"`
	AccountBalanceEv   float64 `json:"accountBalanceEv"`
	TotalUsedBalanceEv float64 `json:"totalUsedBalanceEv"`
	BonusBalanceEv     float64 `json:"bonusBalanceEv"`
	BonusBalance       string  `json:"bonusBalance"`
}

UserMarginUserWalletVo user margin UserWalletvo

type UserWallet

type UserWallet struct {
	UserID        int                       `json:"userId"`
	Email         string                    `json:"email"`
	NickName      string                    `json:"nickName"`
	PasswordState float64                   `json:"passwordState"`
	ClientCnt     float64                   `json:"clientCnt"`
	Totp          float64                   `json:"totp"`
	Logon         float64                   `json:"logon"`
	ParentID      float64                   `json:"parentId"`
	ParentEmail   string                    `json:"parentEmail"`
	Status        float64                   `json:"status"`
	Wallet        *WalletUserWallet         `json:"wallet"`
	UserMarginVo  []*UserMarginUserWalletVo `json:"userMarginVo"`
}

UserWallet user wallet

type WalletUserWallet

type WalletUserWallet struct {
	TotalBalance    string  `json:"totalBalance"`
	TotalBalanceEv  float64 `json:"totalBalanceEv"`
	AvailBalance    string  `json:"availBalance"`
	AvailBalanceEv  float64 `json:"availBalanceEv"`
	FreezeBalance   string  `json:"freezeBalance"`
	FreezeBalanceEv float64 `json:"freezeBalanceEv"`
	Currency        string  `json:"currency"`
	CurrencyCode    float64 `json:"currencyCode"`
}

WalletUserWallet wallet user wallet

type WsAOP

type WsAOP struct {
	Accounts  []*WsAccount  `json:"accounts"`
	Orders    []*WsOrder    `json:"orders"`
	Positions []*WsPosition `json:"positions"`
	Sequence  int64         `json:"sequence"`
	Timestamp int64         `json:"timestamp"`
	Type      string        `json:"type"`
}

WsAOP ws AOP

type WsAccount

type WsAccount struct {
	AccountBalanceEv   int64  `json:"accountBalanceEv"`
	AccountID          int64  `json:"accountID"`
	BonusBalanceEv     int64  `json:"bonusBalanceEv"`
	Currency           string `json:"currency"`
	TotalUsedBalanceEv int64  `json:"totalUsedBalanceEv"`
	UserID             int64  `json:"userID"`
}

WsAccount ws account

type WsAuthService

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

WsAuthService create listen key for user stream service

func (*WsAuthService) Do

func (s *WsAuthService) Do(ctx context.Context, opts ...RequestOption) (c *websocket.Conn, err error)

Do send request

func (*WsAuthService) URL

func (s *WsAuthService) URL(url string) *WsAuthService

URL set url. wss://testnet.phemex.com/ws for test net

type WsError

type WsError struct {
	Error  *Error  `json:"error"`
	Result *Status `json:"result"`
	ID     int     `json:"id"`
}

WsError ws error

type WsHandler

type WsHandler func(message interface{})

WsHandler handle raw websocket message

type WsOrder

type WsOrder struct {
	AccountID               int64       `json:"accountID"`
	Action                  string      `json:"action"`
	ActionBy                string      `json:"actionBy"`
	ActionTimeNs            int64       `json:"actionTimeNs"`
	AddedSeq                int64       `json:"addedSeq"`
	BonusChangedAmountEv    int64       `json:"bonusChangedAmountEv"`
	ClOrdID                 string      `json:"clOrdID"`
	ClosedPnlEv             int64       `json:"closedPnlEv"`
	ClosedSize              float64     `json:"closedSize"`
	Code                    int64       `json:"code"`
	CumQty                  float64     `json:"cumQty"`
	CurAccBalanceEv         int64       `json:"curAccBalanceEv"`
	CurAssignedPosBalanceEv int64       `json:"curAssignedPosBalanceEv"`
	CurLeverageEr           int64       `json:"curLeverageEr"`
	CurPosSide              string      `json:"curPosSide"`
	CurPosSize              float64     `json:"curPosSize"`
	CurPosTerm              int64       `json:"curPosTerm"`
	CurPosValueEv           int64       `json:"curPosValueEv"`
	CurRiskLimitEv          int64       `json:"curRiskLimitEv"`
	Currency                string      `json:"currency"`
	CxlRejReason            int64       `json:"cxlRejReason"`
	DisplayQty              float64     `json:"displayQty"`
	ExecFeeEv               int64       `json:"execFeeEv"`
	ExecID                  string      `json:"execID"`
	ExecInst                string      `json:"execInst"`
	ExecPriceEp             int64       `json:"execPriceEp"`
	ExecQty                 float64     `json:"execQty"`
	ExecSeq                 float64     `json:"execSeq"`
	ExecStatus              string      `json:"execStatus"`
	ExecValueEv             int64       `json:"execValueEv"`
	FeeRateEr               int64       `json:"feeRateEr"`
	LeavesQty               float64     `json:"leavesQty"`
	LeavesValueEv           int64       `json:"leavesValueEv"`
	Message                 string      `json:"message"`
	OrdStatus               string      `json:"ordStatus"`
	OrdType                 string      `json:"ordType"`
	OrderID                 string      `json:"orderID"`
	OrderQty                float64     `json:"orderQty"`
	PegOffsetValueEp        int64       `json:"pegOffsetValueEp"`
	Platform                string      `json:"platform"`
	PriceEp                 int64       `json:"priceEp"`
	RelatedPosTerm          int64       `json:"relatedPosTerm"`
	RelatedReqNum           int64       `json:"relatedReqNum"`
	Side                    string      `json:"side"`
	StopDirection           string      `json:"stopDirection"`
	StopLossEp              int64       `json:"stopLossEp"`
	StopPxEp                int64       `json:"stopPxEp"`
	Symbol                  string      `json:"symbol"`
	TakeProfitEp            int64       `json:"takeProfitEp"`
	TimeInForce             string      `json:"timeInForce"`
	TransactTimeNs          int64       `json:"transactTimeNs"`
	Trigger                 TriggerType `json:"trigger"`
	UserID                  int64       `json:"userID"`
}

WsOrder ws order

type WsOrderBook

type WsOrderBook struct {
	Asks [][]int `json:"asks"`
	Bids [][]int `json:"bids"`
}

WsOrderBook ws OrderBook

type WsOrderBookEvent

type WsOrderBookEvent struct {
	Book      WsOrderBook `json:"book"`
	Depth     int         `json:"depth"`
	Sequence  int         `json:"sequence"`
	Symbol    string      `json:"symbol"`
	Timestamp int         `json:"timestamp"`
	Type      string      `json:"type"`
}

WsOrderBookEvent ws OrderBookEvent

type WsPosition

type WsPosition struct {
	AccountID              int64   `json:"accountID"`
	ActionTimeNs           int64   `json:"actionTimeNs"`
	AssignedPosBalanceEv   int64   `json:"assignedPosBalanceEv"`
	AvgEntryPriceEp        int64   `json:"avgEntryPriceEp"`
	BankruptCommEv         int64   `json:"bankruptCommEv"`
	BankruptPriceEp        int64   `json:"bankruptPriceEp"`
	BuyLeavesQty           float64 `json:"buyLeavesQty"`
	BuyLeavesValueEv       int64   `json:"buyLeavesValueEv"`
	BuyValueToCostEr       int64   `json:"buyValueToCostEr"`
	CreatedAtNs            int64   `json:"createdAtNs"`
	CrossSharedBalanceEv   int64   `json:"crossSharedBalanceEv"`
	CumClosedPnlEv         int64   `json:"cumClosedPnlEv"`
	CumFundingFeeEv        int64   `json:"cumFundingFeeEv"`
	CumTransactFeeEv       int64   `json:"cumTransactFeeEv"`
	CurTermRealisedPnlEv   int64   `json:"curTermRealisedPnlEv"`
	Currency               string  `json:"currency"`
	DataVer                float64 `json:"dataVer"`
	DeleveragePercentileEr int64   `json:"deleveragePercentileEr"`
	DisplayLeverageEr      int64   `json:"displayLeverageEr"`
	EstimatedOrdLossEv     int64   `json:"estimatedOrdLossEv"`
	ExecSeq                int64   `json:"execSeq"`
	FreeCostEv             int64   `json:"freeCostEv"`
	FreeQty                float64 `json:"freeQty"`
	InitMarginReqEr        int64   `json:"initMarginReqEr"`
	LastFundingTime        int64   `json:"lastFundingTime"`
	LastTermEndTime        int64   `json:"lastTermEndTime"`
	LeverageEr             int64   `json:"leverageEr"`
	LiquidationPriceEp     int64   `json:"liquidationPriceEp"`
	MaintMarginReqEr       int64   `json:"maintMarginReqEr"`
	MakerFeeRateEr         int64   `json:"makerFeeRateEr"`
	MarkPriceEp            int64   `json:"markPriceEp"`
	OrderCostEv            int64   `json:"orderCostEv"`
	PosCostEv              int64   `json:"posCostEv"`
	PositionMarginEv       int64   `json:"positionMarginEv"`
	PositionStatus         string  `json:"positionStatus"`
	RiskLimitEv            int64   `json:"riskLimitEv"`
	SellLeavesQty          float64 `json:"sellLeavesQty"`
	SellLeavesValueEv      int64   `json:"sellLeavesValueEv"`
	SellValueToCostEr      int64   `json:"sellValueToCostEr"`
	Side                   string  `json:"side"`
	Size                   float64 `json:"size"`
	Symbol                 string  `json:"symbol"`
	TakerFeeRateEr         int64   `json:"takerFeeRateEr"`
	Term                   int64   `json:"term"`
	UnrealisedPnlEv        int64   `json:"unrealisedPnlEv"`
	UpdatedAtNs            int64   `json:"updatedAtNs"`
	UsedBalanceEv          int64   `json:"usedBalanceEv"`
	UserID                 int64   `json:"userID"`
	ValueEv                int64   `json:"valueEv"`
}

WsPosition ws position

type WsPositionInfo

type WsPositionInfo struct {
	PositionInfo *PositionInfo `json:"position_info"`
	Sequence     int64         `json:"sequence"`
}

WsPositionInfo ws position info

type WsTrade

type WsTrade struct {
}

type WsTradeEvent

type WsTradeEvent struct {
	Trade     []WsTrade `json:"trades"`
	Sequence  int       `json:"sequence"`
	Symbol    string    `json:"symbol"`
	Timestamp int       `json:"timestamp"`
	Type      string    `json:"type"`
}

WsTradeEvent ws WsTradeEvent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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