krisa_phemex_fork

package
v0.0.0-...-ea1cebd Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

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 (
	PerpetualProductType = "Perpetual"
	SpotProductType      = "Spot"
)
View Source
var (
	ListedProductStatus   = "Listed"
	DelistedProductStatus = "Delisted"
)
View Source
var ContractRateLimiterHeadersNames = RateLimiterGroupHeaderNames{
	GroupName:            ContractGroupName,
	RemainingHeaderName:  "X-RateLimit-Remaining-CONTRACT",
	CapacityHeaderName:   "X-RateLimit-Capacity-CONTRACT",
	RetryAfterHeaderName: "X-RateLimit-Retry-After-CONTRACT",
}
View Source
var OthersRateLimiterHeadersNames = RateLimiterGroupHeaderNames{
	GroupName:            OthersGroupName,
	RemainingHeaderName:  "X-RateLimit-Remaining-OTHERS",
	CapacityHeaderName:   "X-RateLimit-Capacity-OTHERS",
	RetryAfterHeaderName: "X-RateLimit-Retry-After-OTHERS",
}

Functions

This section is empty.

Types

type BaseResponse

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

BaseResponse base response for all requests

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, rateLimHeaders *RateLimiterHeaders, err error,
)

Do send request `rateLimHeaders` can be used <=> it isn't nil; despite the error

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, lg *zap.Logger) *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

func (*Client) NewListInactiveOrdersService

func (c *Client) NewListInactiveOrdersService() *ListInactiveOrdersService

func (*Client) NewListOpenOrdersService

func (c *Client) NewListOpenOrdersService() *ListOpenOrdersService

func (*Client) NewProductsService

func (c *Client) NewProductsService() *ProductsService

func (*Client) NewQueryOrderService

func (c *Client) NewQueryOrderService() *QueryOrderService

NewQueryOrderService init query order service

func (*Client) NewTradesService

func (c *Client) NewTradesService() *TradesService

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, rateLimHeaders *RateLimiterHeaders, err error,
)

Do send request `rateLimHeaders` can be used <=> it isn't nil; despite the error

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 Currency

type Currency struct {
	Currency   string `json:"currency"`   //  "BTC",
	Name       string `json:"name"`       //  "Bitcoin",
	ValueScale int64  `json:"valueScale"` //  8,

}

type ExchangeMarginType

type ExchangeMarginType int

ExchangeMarginType define exchange margin type

type ListInactiveOrdersService

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

ListInactiveOrdersService list closed orders

func (*ListInactiveOrdersService) Do

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

Do send request `rateLimHeaders` can be used <=> it isn't nil; despite the error

func (*ListInactiveOrdersService) End

end - Integer - end time range, Epoch millis

func (*ListInactiveOrdersService) Limit

limit - Integer - limit of resultset

func (*ListInactiveOrdersService) Offset

offset - Integer - offset to resultset

func (*ListInactiveOrdersService) Start

start - Integer - start time range, Epoch millis

func (*ListInactiveOrdersService) Symbol

symbol - String - which symbol needs to query - Trading symbols

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, rateLimHeaders *RateLimiterHeaders, err error,
)

Do send request `rateLimHeaders` can be used <=> it isn't nil; despite the error

func (*ListOpenOrdersService) 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 Product

type Product struct {
	Symbol                   string        `json:"symbol"`                   // "BTCUSD",
	Type                     string        `json:"type"`                     // "Perpetual",
	DisplaySymbol            string        `json:"displaySymbol"`            // "BTC / USD",
	IndexSymbol              string        `json:"indexSymbol"`              // ".BTC",
	MarkSymbol               string        `json:"markSymbol"`               // ".MBTC",
	FundingRateSymbol        string        `json:"fundingRateSymbol"`        // ".BTCFR",
	FundingRate8hSymbol      string        `json:"fundingRate8hSymbol"`      // ".BTCFR8H",
	ContractUnderlyingAssets string        `json:"contractUnderlyingAssets"` // "USD",
	SettleCurrency           string        `json:"settleCurrency"`           // "BTC",
	QuoteCurrency            string        `json:"quoteCurrency"`            // "USD",
	ContractSize             utils.APDJSON `json:"contractSize"`             // 1.0,
	LotSize                  utils.APDJSON `json:"lotSize"`                  // 1,
	TickSize                 utils.APDJSON `json:"tickSize"`                 // 0.5,
	PriceScale               int64         `json:"priceScale"`               // 4,
	RatioScale               int64         `json:"ratioScale"`               // 8,
	PricePrecision           utils.APDJSON `json:"pricePrecision"`           // 1,
	MinPriceEp               utils.APDJSON `json:"minPriceEp"`               // 5000,
	MaxPriceEp               utils.APDJSON `json:"maxPriceEp"`               // 10000000000,
	MaxOrderQty              utils.APDJSON `json:"maxOrderQty"`              // 1000000,
	Description              string        `json:"description"`              // "BTC/USD perpetual contracts are priced on the .BTC Index. Each contract is worth 1 USD. Funding fees are paid and received every 8 hours at UTC time: 00:00, 08:00 and 16:00.",
	Status                   string        `json:"status"`                   // "Listed",

}

type ProductsResponse

type ProductsResponse struct {
	RatioScale int         `json:"ratioScale"`
	Currencies []*Currency `json:"currencies"`
	Products   []*Product  `json:"products"`
}

/public/products

type ProductsService

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

func (*ProductsService) Do

Do send request

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, rateLimHeaders *RateLimiterHeaders, err error)

Do send request `rateLimiterHeaders` can be used <=> it isn't nil; despite the error

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 RateLimiterGroupHeaderNames

type RateLimiterGroupHeaderNames struct {
	GroupName            RateLimiterGroupName
	RemainingHeaderName  string // Remaining request permits in this minute
	CapacityHeaderName   string // Request ratelimit capacity
	RetryAfterHeaderName string // Reset timeout in seconds for current ratelimited user
}

type RateLimiterGroupName

type RateLimiterGroupName string
const (
	ContractGroupName RateLimiterGroupName = "Contract" // 500/minutes
	OthersGroupName   RateLimiterGroupName = "Others"   // 100/minutes

)

type RateLimiterHeaders

type RateLimiterHeaders struct {
	GroupName RateLimiterGroupName

	Capacity   int            // Request ratelimit capacity
	Remaining  *int           // Remaining request permits in this minute
	RetryAfter *time.Duration // Reset timeout for current ratelimited user
}

func ParseRateLimiterHeaders

func ParseRateLimiterHeaders(headers http.Header) (*RateLimiterHeaders, error)

Can return `nil` in case of no rate limiting headers

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 TimeInForceType

type TimeInForceType string

TimeInForceType define time in force type of order

type TradesService

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

symbol=<symbol>&start=<start>&end=<end>&limit=<limit>&offset=<offset>&withCount=<withCount>

func (*TradesService) Do

func (s *TradesService) Do(ctx context.Context, opts ...RequestOption) (
	res map[string]interface{}, rateLimiterHeaders *RateLimiterHeaders, err error,
)

Do send request `rateLimiterHeaders` can be used <=> it isn't nil; despite the error

func (*TradesService) End

func (s *TradesService) End(end time.Time) *TradesService

end - Integer - ? end time range, Epoch millis

func (*TradesService) Limit

func (s *TradesService) Limit(limit int) *TradesService

limit - Integer - ? limit of resultset

func (*TradesService) Offset

func (s *TradesService) Offset(offset int) *TradesService

offset - Integer - ? offset to resultset

func (*TradesService) Start

func (s *TradesService) Start(start time.Time) *TradesService

start - Integer - ? start time range, Epoch millis

func (*TradesService) Symbol

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

symbol - String - ? which symbol needs to query - Trading symbols

type TriggerType

type TriggerType string

TriggerType define trigger type

Jump to

Keyboard shortcuts

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