The resource loading... loading...

Account

exchange.GetAccount

The exchange.GetAccount() function is used to request exchange account information. The GetAccount() function is a member function of the exchange object {@var/EXCHANGE exchange}. The purpose of the member functions (methods) of the exchange object is only related to exchange, and it will not be repeated after the documentation.

Query the account asset information and return the {@struct/Account Account} structure if the query succeeds or null if it fails. {@struct/Account Account}, null value

exchange.GetAccount()

function main(){
    // Switching trading pairs
    exchange.IO("currency", "BTC_USDT")     
    // Take OKX futures as an example, set the contract as the current week's contract, the current trading pair is BTC_USDT, so the current contract is BTC's U-nominal current week contract
    exchange.SetContractType("this_week")   
    // Get current account asset data
    var account = exchange.GetAccount()
    // Available balance of USDT as margin
    Log(account.Balance)
    // USDT freeze amount as margin
    Log(account.FrozenBalance)
    // Current asset equity
    Log(account.Equity)
    // The unrealized profit and loss of all positions held with the current asset as margin
    Log(account.UPnL)
}
def main():
    exchange.IO("currency", "BTC_USDT")
    exchange.SetContractType("this_week")    
    account = exchange.GetAccount()
    Log(account["Balance"])
    Log(account["FrozenBalance"])
    Log(account["Equity"])
    Log(account["UPnL"])
void main() {
    exchange.IO("currency", "BTC_USDT");
    exchange.SetContractType("this_week");    
    auto account = exchange.GetAccount();
    Log(account.Balance);
    Log(account.FrozenBalance);
    Log(account["Equity"])
    Log(account["UPnL"])
}

Set up trading pairs, contract codes, and get current account information.

If the exchange object is set to a cryptocurrency futures contract exchange, and switched to a contract with USDT as margin (see {@fun/Account/exchange.SetCurrency exchange.SetCurrency}, {@fun/Futures/exchange.SetContractType exchange.SetContractType} functions for how to switch). The asset is USDT as margin, which is recorded in the Balance, FrozenBalance attributes of the {@struct/Account Account} structure. If the exchange object is set to a cryptocurrency futures contract exchange, and switched to a currency-based contract, the asset is in currency as margin and is recorded in the Stocks, FrozenStocks attributes of the {@struct/Account Account} structure. When using the Binance Futures unified account, when calling the exchange.GetAccount() function to request account information, the encapsulated data is the amount of all assets converted into USD. It is displayed in the Balance field of the {@struct/Account Account} structure. If you need to calculate the conversion amount of other assets, you can use the USD conversion amount divided by the index price (of the asset to be converted) and then divided by the pledge rate (of the asset to be converted) to calculate it.

{@struct/Account Account}, {@fun/Account/exchange.SetCurrency exchange.SetCurrency}, {@fun/Futures/exchange.SetContractType exchange.SetContractType}

exchange.GetAssets

The exchange.GetAssets function is used to request exchange account asset information.

The exchange.GetAssets() function returns an array of {@struct/Asset Asset} structures if the request for data succeeds, or null if the request fails. {@struct/Asset Asset} array, null value

exchange.GetAssets()

function main() {
    // exchange.SetCurrency("BTC_USDT")  // You can set up trading pairs
    // exchange.SetContractType("swap")  // You can set up contracts
    var assets = exchange.GetAssets()
    Log(assets)
}
def main():
    # exchange.SetCurrency("BTC_USDT")  # You can set up trading pairs
    # exchange.SetContractType("swap")  # You can set up contracts
    assets = exchange.GetAssets()
    Log(assets)
void main() {
    // exchange.SetCurrency("BTC_USDT");  // You can set up trading pairs
    // exchange.SetContractType("swap");  // You can set up contracts
    auto assets = exchange.GetAssets();
    Log(assets);
}

Get information about the assets of an exchange account, exchange.GetAssets() returns an array with elements of the Asset structure.

The GetAssets() function of the Futures Exchange object returns the margin assets under the current trading pair (currency-based, USDT-based, USDC-based, etc.).

{@struct/Asset Asset}

exchange.GetName

The exchange.GetName() function is used to get the name of the exchange to which the current exchange object is bound.

The exchange.GetName() function returns the name of the exchange defined by the FMZ Quant Trading platform. string

exchange.GetName()

function main() {
    Log("The exchange object exchange is judged to be Binance spot, and the result is judged to be:", exchange.GetName() == "Binance")
}
def main():
    Log("The exchange object exchange is judged to be Binance spot, and the result is judged to be:", exchange.GetName() == "Binance")
void main() {
    Log("The exchange object exchange is judged to be Binance spot, and the result is judged to be:", exchange.GetName() == "Binance");
}

The exchange.GetName() function is generally used to identify the exchange objects, such as exchange or exchanges[1], exchanges[2] in the strategy code. The names of cryptocurrency futures contract exchanges have the fixed prefix Futures_.

{@fun/Account/exchange.GetLabel exchange.GetLabel}

exchange.GetLabel

The exchange.GetLabel() function is used to get the custom label that was set when the exchange object was configured.

The exchange.GetLabel() function returns the custom label that was set when the exchange object was configured. string

exchange.GetLabel()

function main() {
    Log("exchange label:", exchange.GetLabel())
}
def main():
    Log("exchange label:", exchange.GetLabel())
void main() {
    Log("exchange label:", exchange.GetLabel());
}

Exchange objects such as exchange or exchanges[1], exchanges[2] in the strategy code are identified by the set tag.

{@var/EXCHANGE exchange}

exchange.GetCurrency

The exchange.GetCurrency() function is used to get the currently set trading pair.

The exchange.GetCurrency() function returns the trading pair set by the current {@var/EXCHANGE exchange} exchange object. string

exchange.GetCurrency()

function main() {
    Log("the current trading pair of exchange is:", exchange.GetCurrency())
}
def main():
    Log("the current trading pair of exchange is:", exchange.GetCurrency())
void main() {
    Log("the current trading pair of exchange is:", exchange.GetCurrency());
}

The trading pair format is uppercase uniformly, using underscores to separate baseCurrency and quoteCurrency, such as BTC_USDT.

{@fun/Account/exchange.SetCurrency exchange.SetCurrency}

exchange.SetCurrency

The exchange.SetCurrency() function is used to switch the current trading pair of the exchange object {@var/EXCHANGE exchange}.

exchange.SetCurrency(currency)

The currency parameter is used to set the trading pair to be switched. The trading pair format is uppercase uniformly, using an underscore to separate baseCurrency from quoteCurrency, such as BTC_USDT. currency true string

function main() {
    var ticker = exchange.GetTicker() 
    Log(ticker)
    Log(exchange.GetAccount())    
    // Switching trading pairs, pay attention to the changes of ticker data and account information after switching
    exchange.SetCurrency("LTC_USDT")
    Log("Switch to LTC_USDT")
    ticker = exchange.GetTicker()
    Log(ticker)
    Log(exchange.GetAccount())
}
def main():
    ticker = exchange.GetTicker()
    Log(ticker)
    Log(exchange.GetAccount())
    exchange.SetCurrency("LTC_USDT")
    Log("Switch to LTC_USDT")
    ticker = exchange.GetTicker()
    Log(ticker)
    Log(exchange.GetAccount())
void main() {
    auto ticker = exchange.GetTicker();
    Log(ticker);
    Log(exchange.GetAccount());
    exchange.SetCurrency("LTC_USDT");
    Log("Switch to LTC_USDT");
    ticker = exchange.GetTicker();
    Log(ticker);
    Log(exchange.GetAccount());
}
  1. Compatible with exchange.IO("currency", "BTC_USDT") switching method, please refer to {@fun excahnge.IO}.
  2. Support switching trading pairs in the backtesting system, the name of the denominated currency cannot be changed when switching trading pairs in the backtesting system. For example: BTC_USDT can be switched to LTC_USDT, not to LTC_BTC.
  3. The number of trading currencies is 0 after switching to the trading pair initially set on the non-backtest page. For example, when backtesting the initial trading pair set on the backtest page is BTC_USDT, the number of BTC is 3, the number of USDT is 10000. At this time, switch to LTC_USDT immediately, the number of trading currencies is 0 after switching, i.e. the number of LTC_USDT in the account is 0. That is, the number of LTC in the account is 0, and the switched trading pair shares the number of USDT, which is 10000.

{@fun/Account/exchange.GetCurrency exchange.GetCurrency}

exchange.GetQuoteCurrency

The exchange.GetQuoteCurrency() function is used to get the name of the denominated currency of the current trading pair, i.e. quoteCurrency.

The exchange.GetQuoteCurrency() function returns the name of the denominated currency of the current trading pair. string

exchange.GetQuoteCurrency()

function main() {
    exchange.SetCurrency("BTC_USDT")
    Log("BTC_USDT denominated currency name:", exchange.GetQuoteCurrency())
    // exchange.SetCurrency("ETH_BTC")
    // Log("ETH_BTC denominated currency name:", exchange.GetQuoteCurrency())
}
def main():
    exchange.SetCurrency("BTC_USDT")
    Log("BTC_USDT denominated currency name:", exchange.GetQuoteCurrency())
    # exchange.SetCurrency("ETH_BTC")
    # Log("ETH_BTC denominated currency name:", exchange.GetQuoteCurrency())
void main() {
    exchange.SetCurrency("BTC_USDT");
    Log("BTC_USDT denominated currency name:", exchange.GetQuoteCurrency());
    // exchange.SetCurrency("ETH_BTC")
    // Log("ETH_BTC denominated currency name:", exchange.GetQuoteCurrency())
}

For example: {@var/EXCHANGE exchange} exchange object’s current transaction pair is BTC_USDT, the exchange.GetQuoteCurrency() function returns USDT. If the current trading pair is ETH_BTC, the exchange.GetQuoteCurrency() function returns BTC.

{@fun/Account/exchange.GetCurrency exchange.GetCurrency}, {@fun/Account/exchange.SetCurrency exchange.SetCurrency}

Trade Futures