ccxt-go/phemex_wrapper.go

1284 lines
44 KiB
Go
Raw Permalink Normal View History

2025-02-28 10:33:20 +08:00
package ccxt
type Phemex struct {
*phemex
Core *phemex
}
func NewPhemex(userConfig map[string]interface{}) Phemex {
p := &phemex{}
p.Init(userConfig)
return Phemex{
phemex: p,
Core: p,
}
}
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
/**
* @method
* @name phemex#fetchMarkets
* @description retrieves data on all markets for phemex
* @see https://phemex-docs.github.io/#query-product-information-3
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
func (this *Phemex) FetchMarkets(params ...interface{}) ([]MarketInterface, error) {
res := <- this.Core.FetchMarkets(params...)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewMarketInterfaceArray(res), nil
}
/**
* @method
* @name phemex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
*/
func (this *Phemex) FetchOrderBook(symbol string, options ...FetchOrderBookOptions) (OrderBook, error) {
opts := FetchOrderBookOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOrderBook(symbol, limit, params)
if IsError(res) {
return OrderBook{}, CreateReturnError(res)
}
return NewOrderBook(res), nil
}
/**
* @method
* @name phemex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#querykline
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-kline
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] *only used for USDT settled contracts, otherwise is emulated and not supported by the exchange* timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] *USDT settled/ linear swaps only* end time in ms
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
func (this *Phemex) FetchOHLCV(symbol string, options ...FetchOHLCVOptions) ([]OHLCV, error) {
opts := FetchOHLCVOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var timeframe interface{} = nil
if opts.Timeframe != nil {
timeframe = *opts.Timeframe
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOHLCV(symbol, timeframe, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewOHLCVArray(res), nil
}
/**
* @method
* @name phemex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query24hrsticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
func (this *Phemex) FetchTicker(symbol string, options ...FetchTickerOptions) (Ticker, error) {
opts := FetchTickerOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchTicker(symbol, params)
if IsError(res) {
return Ticker{}, CreateReturnError(res)
}
return NewTicker(res), nil
}
/**
* @method
* @name phemex#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://phemex-docs.github.io/#query-24-hours-ticker-for-all-symbols-2 // spot
* @see https://phemex-docs.github.io/#query-24-ticker-for-all-symbols // linear
* @see https://phemex-docs.github.io/#query-24-hours-ticker-for-all-symbols // inverse
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
func (this *Phemex) FetchTickers(options ...FetchTickersOptions) (Tickers, error) {
opts := FetchTickersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbols interface{} = nil
if opts.Symbols != nil {
symbols = *opts.Symbols
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchTickers(symbols, params)
if IsError(res) {
return Tickers{}, CreateReturnError(res)
}
return NewTickers(res), nil
}
/**
* @method
* @name phemex#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#querytrades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
*/
func (this *Phemex) FetchTrades(symbol string, options ...FetchTradesOptions) ([]Trade, error) {
opts := FetchTradesOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchTrades(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewTradeArray(res), nil
}
/**
* @method
* @name phemex#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://phemex-docs.github.io/#query-wallets
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
* @see https://phemex-docs.github.io/#query-trading-account-and-positions
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] spot or swap
* @param {string} [params.code] *swap only* currency code of the balance to query (USD, USDT, etc), default is USDT
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
*/
func (this *Phemex) FetchBalance(params ...interface{}) (Balances, error) {
res := <- this.Core.FetchBalance(params...)
if IsError(res) {
return Balances{}, CreateReturnError(res)
}
return NewBalances(res), nil
}
/**
* @method
* @name phemex#createOrder
* @description create a trade order
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#place-order
* @see https://phemex-docs.github.io/#place-order-http-put-prefered-3
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.trigger] trigger price for conditional orders
* @param {object} [params.takeProfit] *swap only* *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *swap only* *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {string} [params.posSide] *swap only* "Merged" for one way mode, "Long" for buy side of hedged mode, "Short" for sell side of hedged mode
* @param {bool} [params.hedged] *swap only* true for hedged mode, false for one way mode, default is false
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) CreateOrder(symbol string, typeVar string, side string, amount float64, options ...CreateOrderOptions) (Order, error) {
opts := CreateOrderOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var price interface{} = nil
if opts.Price != nil {
price = *opts.Price
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.CreateOrder(symbol, typeVar, side, amount, price, params)
if IsError(res) {
return Order{}, CreateReturnError(res)
}
return NewOrder(res), nil
}
/**
* @method
* @name phemex#editOrder
* @description edit a trade order
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#amend-order-by-orderid
* @param {string} id cancel order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.posSide] either 'Merged' or 'Long' or 'Short'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) EditOrder(id string, symbol string, typeVar string, side string, options ...EditOrderOptions) (Order, error) {
opts := EditOrderOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var amount interface{} = nil
if opts.Amount != nil {
amount = *opts.Amount
}
var price interface{} = nil
if opts.Price != nil {
price = *opts.Price
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.EditOrder(id, symbol, typeVar, side, amount, price, params)
if IsError(res) {
return Order{}, CreateReturnError(res)
}
return NewOrder(res), nil
}
/**
* @method
* @name phemex#cancelOrder
* @description cancels an open order
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#cancel-single-order-by-orderid
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.posSide] either 'Merged' or 'Long' or 'Short'
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) CancelOrder(id string, options ...CancelOrderOptions) (Order, error) {
opts := CancelOrderOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.CancelOrder(id, symbol, params)
if IsError(res) {
return Order{}, CreateReturnError(res)
}
return NewOrder(res), nil
}
/**
* @method
* @name phemex#cancelAllOrders
* @description cancel all open orders in a market
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#cancelall
* @param {string} symbol unified market symbol of the market to cancel orders in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) CancelAllOrders(options ...CancelAllOrdersOptions) ([]Order, error) {
opts := CancelAllOrdersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.CancelAllOrders(symbol, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewOrderArray(res), nil
}
/**
* @method
* @name phemex#fetchOrder
* @see https://phemex-docs.github.io/#query-orders-by-ids
* @description fetches information on an order made by the user
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) FetchOrder(id string, options ...FetchOrderOptions) (Order, error) {
opts := FetchOrderOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOrder(id, symbol, params)
if IsError(res) {
return Order{}, CreateReturnError(res)
}
return NewOrder(res), nil
}
/**
* @method
* @name phemex#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorder
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) FetchOrders(options ...FetchOrdersOptions) ([]Order, error) {
opts := FetchOrdersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOrders(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewOrderArray(res), nil
}
/**
* @method
* @name phemex#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryopenorder
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotListAllOpenOrder
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) FetchOpenOrders(options ...FetchOpenOrdersOptions) ([]Order, error) {
opts := FetchOpenOrdersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOpenOrders(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewOrderArray(res), nil
}
/**
* @method
* @name phemex#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorder
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#queryorder
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedgedd-Perpetual-API.md#query-closed-orders-by-symbol
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotDataOrdersByIds
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.settle] the settlement currency to fetch orders for
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
func (this *Phemex) FetchClosedOrders(options ...FetchClosedOrdersOptions) ([]Order, error) {
opts := FetchClosedOrdersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchClosedOrders(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewOrderArray(res), nil
}
/**
* @method
* @name phemex#fetchMyTrades
* @description fetch all trades made by the user
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-user-trade
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-user-trade
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotDataTradesHist
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
func (this *Phemex) FetchMyTrades(options ...FetchMyTradesOptions) ([]Trade, error) {
opts := FetchMyTradesOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchMyTrades(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewTradeArray(res), nil
}
/**
* @method
* @name phemex#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
*/
func (this *Phemex) FetchDepositAddress(code string, options ...FetchDepositAddressOptions) (DepositAddress, error) {
opts := FetchDepositAddressOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchDepositAddress(code, params)
if IsError(res) {
return DepositAddress{}, CreateReturnError(res)
}
return NewDepositAddress(res), nil
}
/**
* @method
* @name phemex#fetchDeposits
* @description fetch all deposits made to an account
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
*/
func (this *Phemex) FetchDeposits(options ...FetchDepositsOptions) ([]Transaction, error) {
opts := FetchDepositsOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var code interface{} = nil
if opts.Code != nil {
code = *opts.Code
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchDeposits(code, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewTransactionArray(res), nil
}
/**
* @method
* @name phemex#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
*/
func (this *Phemex) FetchWithdrawals(options ...FetchWithdrawalsOptions) ([]Transaction, error) {
opts := FetchWithdrawalsOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var code interface{} = nil
if opts.Code != nil {
code = *opts.Code
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchWithdrawals(code, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewTransactionArray(res), nil
}
/**
* @method
* @name phemex#fetchPositions
* @description fetch all open positions
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-trading-account-and-positions
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
* @see https://phemex-docs.github.io/#query-account-positions-with-unrealized-pnl
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.code] the currency code to fetch positions for, USD, BTC or USDT, USD is the default
* @param {string} [params.method] *USDT contracts only* 'privateGetGAccountsAccountPositions' or 'privateGetAccountsPositions' default is 'privateGetGAccountsAccountPositions'
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
*/
func (this *Phemex) FetchPositions(options ...FetchPositionsOptions) ([]Position, error) {
opts := FetchPositionsOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbols interface{} = nil
if opts.Symbols != nil {
symbols = *opts.Symbols
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchPositions(symbols, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewPositionArray(res), nil
}
/**
* @method
* @name phemex#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#futureDataFundingFeesHist
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
*/
func (this *Phemex) FetchFundingHistory(options ...FetchFundingHistoryOptions) ([]FundingHistory, error) {
opts := FetchFundingHistoryOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchFundingHistory(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewFundingHistoryArray(res), nil
}
/**
* @method
* @name phemex#fetchFundingRate
* @description fetch the current funding rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
*/
func (this *Phemex) FetchFundingRate(symbol string, options ...FetchFundingRateOptions) (FundingRate, error) {
opts := FetchFundingRateOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchFundingRate(symbol, params)
if IsError(res) {
return FundingRate{}, CreateReturnError(res)
}
return NewFundingRate(res), nil
}
/**
* @method
* @name phemex#setMargin
* @description Either adds or reduces margin in an isolated position in order to set the margin to a specific value
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#assign-position-balance-in-isolated-marign-mode
* @param {string} symbol unified market symbol of the market to set margin in
* @param {float} amount the amount to set the margin to
* @param {object} [params] parameters specific to the exchange API endpoint
* @returns {object} A [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
*/
func (this *Phemex) SetMargin(symbol string, amount float64, options ...SetMarginOptions) (MarginModification, error) {
opts := SetMarginOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.SetMargin(symbol, amount, params)
if IsError(res) {
return MarginModification{}, CreateReturnError(res)
}
return NewMarginModification(res), nil
}
/**
* @method
* @name phemex#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://phemex-docs.github.io/#set-leverage
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
func (this *Phemex) SetMarginMode(marginMode string, options ...SetMarginModeOptions) (map[string]interface{}, error) {
opts := SetMarginModeOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.SetMarginMode(marginMode, symbol, params)
if IsError(res) {
return map[string]interface{}{}, CreateReturnError(res)
}
return res.(map[string]interface{}), nil
}
/**
* @method
* @name phemex#setPositionMode
* @description set hedged to true or false for a market
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#switch-position-mode-synchronously
* @param {bool} hedged set to true to use dualSidePosition
* @param {string} symbol not used by binance setPositionMode ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
func (this *Phemex) SetPositionMode(hedged bool, options ...SetPositionModeOptions) (map[string]interface{}, error) {
opts := SetPositionModeOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.SetPositionMode(hedged, symbol, params)
if IsError(res) {
return map[string]interface{}{}, CreateReturnError(res)
}
return res.(map[string]interface{}), nil
}
/**
* @method
* @name phemex#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
*/
func (this *Phemex) FetchLeverageTiers(options ...FetchLeverageTiersOptions) (LeverageTiers, error) {
opts := FetchLeverageTiersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbols interface{} = nil
if opts.Symbols != nil {
symbols = *opts.Symbols
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchLeverageTiers(symbols, params)
if IsError(res) {
return LeverageTiers{}, CreateReturnError(res)
}
return NewLeverageTiers(res), nil
}
/**
* @method
* @name phemex#setLeverage
* @description set the level of leverage for a market
* @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#set-leverage
* @param {float} leverage the rate of leverage, 100 > leverage > -100 excluding numbers between -1 to 1
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.hedged] set to true if hedged position mode is enabled (by default long and short leverage are set to the same value)
* @param {float} [params.longLeverageRr] *hedged mode only* set the leverage for long positions
* @param {float} [params.shortLeverageRr] *hedged mode only* set the leverage for short positions
* @returns {object} response from the exchange
*/
func (this *Phemex) SetLeverage(leverage int64, options ...SetLeverageOptions) (map[string]interface{}, error) {
opts := SetLeverageOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.SetLeverage(leverage, symbol, params)
if IsError(res) {
return map[string]interface{}{}, CreateReturnError(res)
}
return res.(map[string]interface{}), nil
}
/**
* @method
* @name phemex#transfer
* @description transfer currency internally between wallets on the same account
* @see https://phemex-docs.github.io/#transfer-between-spot-and-futures
* @see https://phemex-docs.github.io/#universal-transfer-main-account-only-transfer-between-sub-to-main-main-to-sub-or-sub-to-sub
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.bizType] for transferring between main and sub-acounts either 'SPOT' or 'PERPETUAL' default is 'SPOT'
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
*/
func (this *Phemex) Transfer(code string, amount float64, fromAccount string, toAccount string, options ...TransferOptions) (TransferEntry, error) {
opts := TransferOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.Transfer(code, amount, fromAccount, toAccount, params)
if IsError(res) {
return TransferEntry{}, CreateReturnError(res)
}
return NewTransferEntry(res), nil
}
/**
* @method
* @name phemex#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://phemex-docs.github.io/#query-transfer-history
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfers structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
*/
func (this *Phemex) FetchTransfers(options ...FetchTransfersOptions) ([]TransferEntry, error) {
opts := FetchTransfersOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var code interface{} = nil
if opts.Code != nil {
code = *opts.Code
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchTransfers(code, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewTransferEntryArray(res), nil
}
/**
* @method
* @name phemex#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://phemex-docs.github.io/#query-funding-rate-history-2
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {int} [params.until] timestamp in ms of the latest funding rate
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
*/
func (this *Phemex) FetchFundingRateHistory(options ...FetchFundingRateHistoryOptions) ([]FundingRateHistory, error) {
opts := FetchFundingRateHistoryOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var symbol interface{} = nil
if opts.Symbol != nil {
symbol = *opts.Symbol
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchFundingRateHistory(symbol, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewFundingRateHistoryArray(res), nil
}
/**
* @method
* @name phemex#withdraw
* @description make a withdrawal
* @see https://phemex-docs.github.io/#create-withdraw-request
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the phemex api endpoint
* @param {string} [params.network] unified network code
* @returns {object} a [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
*/
func (this *Phemex) Withdraw(code string, amount float64, address string, options ...WithdrawOptions) (Transaction, error) {
opts := WithdrawOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var tag interface{} = nil
if opts.Tag != nil {
tag = *opts.Tag
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.Withdraw(code, amount, address, tag, params)
if IsError(res) {
return Transaction{}, CreateReturnError(res)
}
return NewTransaction(res), nil
}
/**
* @method
* @name phemex#fetchOpenInterest
* @description retrieves the open interest of a trading pair
* @see https://phemex-docs.github.io/#query-24-hours-ticker
* @param {string} symbol unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure}
*/
func (this *Phemex) FetchOpenInterest(symbol string, options ...FetchOpenInterestOptions) (OpenInterest, error) {
opts := FetchOpenInterestOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchOpenInterest(symbol, params)
if IsError(res) {
return OpenInterest{}, CreateReturnError(res)
}
return NewOpenInterest(res), nil
}
/**
* @method
* @name phemex#fetchConvertQuote
* @description fetch a quote for converting from one currency to another
* @see https://phemex-docs.github.io/#rfq-quote
* @param {string} fromCode the currency that you want to sell and convert from
* @param {string} toCode the currency that you want to buy and convert into
* @param {float} amount how much you want to trade in units of the from currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
*/
func (this *Phemex) FetchConvertQuote(fromCode string, toCode string, options ...FetchConvertQuoteOptions) (Conversion, error) {
opts := FetchConvertQuoteOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var amount interface{} = nil
if opts.Amount != nil {
amount = *opts.Amount
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchConvertQuote(fromCode, toCode, amount, params)
if IsError(res) {
return Conversion{}, CreateReturnError(res)
}
return NewConversion(res), nil
}
/**
* @method
* @name phemex#createConvertTrade
* @description convert from one currency to another
* @see https://phemex-docs.github.io/#convert
* @param {string} id the id of the trade that you want to make
* @param {string} fromCode the currency that you want to sell and convert from
* @param {string} toCode the currency that you want to buy and convert into
* @param {float} [amount] how much you want to trade in units of the from currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
*/
func (this *Phemex) CreateConvertTrade(id string, fromCode string, toCode string, options ...CreateConvertTradeOptions) (Conversion, error) {
opts := CreateConvertTradeOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var amount interface{} = nil
if opts.Amount != nil {
amount = *opts.Amount
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.CreateConvertTrade(id, fromCode, toCode, amount, params)
if IsError(res) {
return Conversion{}, CreateReturnError(res)
}
return NewConversion(res), nil
}
/**
* @method
* @name phemex#fetchConvertTradeHistory
* @description fetch the users history of conversion trades
* @see https://phemex-docs.github.io/#query-convert-history
* @param {string} [code] the unified currency code
* @param {int} [since] the earliest time in ms to fetch conversions for
* @param {int} [limit] the maximum number of conversion structures to retrieve, default 20, max 200
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.until] the end time in ms
* @param {string} [params.fromCurrency] the currency that you sold and converted from
* @param {string} [params.toCurrency] the currency that you bought and converted into
* @returns {object[]} a list of [conversion structures]{@link https://docs.ccxt.com/#/?id=conversion-structure}
*/
func (this *Phemex) FetchConvertTradeHistory(options ...FetchConvertTradeHistoryOptions) ([]Conversion, error) {
opts := FetchConvertTradeHistoryOptionsStruct{}
for _, opt := range options {
opt(&opts)
}
var code interface{} = nil
if opts.Code != nil {
code = *opts.Code
}
var since interface{} = nil
if opts.Since != nil {
since = *opts.Since
}
var limit interface{} = nil
if opts.Limit != nil {
limit = *opts.Limit
}
var params interface{} = nil
if opts.Params != nil {
params = *opts.Params
}
res := <- this.Core.FetchConvertTradeHistory(code, since, limit, params)
if IsError(res) {
return nil, CreateReturnError(res)
}
return NewConversionArray(res), nil
}