Account
exchange.GetAccount
The exchange.GetAccount() function is used to request the exchange account information. The GetAccount() function is a member function of the exchange object exchange. The member functions (methods) of the exchange object are only related to exchange, which will not be repeated in the subsequent documentation.
exchange.GetAccount()Examples
Set the trading pair and contract code, and get the current account information.
javascript
function main(){
// Switch the trading pair
exchange.IO("currency", "BTC_USDT")
// Taking OKX Futures as an example, set the contract to the current-week contract. The current trading pair is BTC_USDT, so the current contract is the USDT-margined current-week contract of BTC
exchange.SetContractType("this_week")
// Get the current account asset data
var account = exchange.GetAccount()
// Available balance with USDT as margin
Log(account.Balance)
// Frozen amount with USDT as margin
Log(account.FrozenBalance)
// Current asset equity
Log(account.Equity)
// Unrealized profit and loss of all positions with the current assets as margin
Log(account.UPnL)
}
python
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"])
rust
fn main() {
// Switch the trading pair
exchange.IO(("currency", "BTC_USDT")).unwrap();
// Taking OKX Futures as an example, set the contract to the current-week contract. The current trading pair is BTC_USDT, so the current contract is the USDT-margined current-week contract of BTC
exchange.SetContractType("this_week").unwrap();
// Get the current account asset data
let account = exchange.GetAccount().unwrap();
// Available balance with USDT as margin
Log!(account.Balance);
// Frozen amount with USDT as margin
Log!(account.FrozenBalance);
// Current asset equity
Log!(account.Equity);
// Unrealized profit and loss of all positions with the current assets as margin
Log!(account.UPnL);
}
c++
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);
}Returns
| Type | Description |
| Queries the account asset information. Returns the |
See Also
Remarks
If the exchange object is set to a cryptocurrency futures contract exchange and switched to a contract that uses USDT as margin (for the switching method, please refer to the exchange.SetCurrency and exchange.SetContractType functions), the assets are then denominated in USDT as margin and recorded in the Balance and FrozenBalance properties of the Account structure.
If the exchange object is set to a cryptocurrency futures contract exchange and switched to a coin-margined contract, the assets are then denominated in the coin as margin and recorded in the Stocks and FrozenStocks properties of the Account structure.
When using a Binance Futures unified account, calling the exchange.GetAccount() function to request account information returns encapsulated data where all assets are converted into their value in **USD**, displayed in the Balance field of the Account structure. If you need to calculate the converted value of other assets, you can divide the USD-converted amount by the index price (of the asset to be converted), and then divide by the collateral ratio (of the asset to be converted).
exchange.GetAssets
The exchange.GetAssets function is used to request the asset information of the exchange account.
exchange.GetAssets()Examples
Get the asset information of the exchange account. The exchange.GetAssets() function returns an array with Asset structures as elements.
javascript
function main() {
// exchange.SetCurrency("BTC_USDT") // You can set the trading pair
// exchange.SetContractType("swap") // You can set the contract
var assets = exchange.GetAssets()
Log(assets)
}
python
def main():
# exchange.SetCurrency("BTC_USDT") # You can set the trading pair
# exchange.SetContractType("swap") # You can set the contract
assets = exchange.GetAssets()
Log(assets)
rust
fn main() {
// exchange.SetCurrency("BTC_USDT"); // You can set the trading pair
// exchange.SetContractType("swap").unwrap(); // You can set the contract
let assets = exchange.GetAssets().unwrap();
Log!(assets);
}
c++
void main() {
// exchange.SetCurrency("BTC_USDT"); // You can set the trading pair
// exchange.SetContractType("swap"); // You can set the contract
auto assets = exchange.GetAssets();
Log(assets);
}Returns
| Type | Description |
| The |
See Also
Remarks
The GetAssets() function of a futures exchange object returns the margin assets under the current trading pair (coin-margined, USDT-margined, USDC-margined, etc.).
exchange.GetName
The exchange.GetName() function is used to get the name of the exchange bound to the current exchange object.
exchange.GetName()Examples
javascript
function main() {
Log("Check if exchange object is Binance spot, result:", exchange.GetName() == "Binance")
}
python
def main():
Log("Check if exchange object is Binance spot, result:", exchange.GetName() == "Binance")
rust
fn main() {
Log!("Check if exchange object is Binance spot, result:", exchange.GetName() == "Binance");
}
c++
void main() {
Log("Check if exchange object is Binance spot, result:", exchange.GetName() == "Binance");
}Returns
| Type | Description |
string | The |
See Also
Remarks
The exchange.GetName() function is typically used to identify the exchange or exchanges[1], exchanges[2], and other exchange objects in the strategy code. The name of a cryptocurrency futures contract exchange carries the fixed prefix Futures_.
exchange.GetLabel
The exchange.GetLabel() function is used to obtain the custom label set when configuring the exchange object.
exchange.GetLabel()Examples
javascript
function main() {
Log("exchange label:", exchange.GetLabel())
}
python
def main():
Log("exchange label:", exchange.GetLabel())
rust
fn main() {
Log!("exchange label:", exchange.GetLabel());
}
c++
void main() {
Log("exchange label:", exchange.GetLabel());
}Returns
| Type | Description |
string | The |
See Also
Remarks
By means of the label that was set, you can identify the exchange or exchanges[1], exchanges[2] and other exchange objects in the strategy code.
exchange.GetCurrency
The exchange.GetCurrency() function is used to get the currently set trading pair.
exchange.GetCurrency()Examples
javascript
function main() {
Log("Current trading pair:", exchange.GetCurrency())
}
python
def main():
Log("Current trading pair:", exchange.GetCurrency())
rust
fn main() {
Log!("Current trading pair:", exchange.GetCurrency());
}
c++
void main() {
Log("Current trading pair:", exchange.GetCurrency());
}Returns
| Type | Description |
string | The |
See Also
Remarks
The trading pair format uniformly uses uppercase, with an underscore separating baseCurrency and quoteCurrency, for example: BTC_USDT.
exchange.SetCurrency
The exchange.SetCurrency() function is used to switch the current trading pair of the exchange object exchange.
exchange.SetCurrency(currency)Examples
javascript
function main() {
var ticker = exchange.GetTicker()
Log(ticker)
Log(exchange.GetAccount())
// Switch the trading pair, note the changes in market data and account information after switching
exchange.SetCurrency("LTC_USDT")
Log("Switched to LTC_USDT")
ticker = exchange.GetTicker()
Log(ticker)
Log(exchange.GetAccount())
}
python
def main():
ticker = exchange.GetTicker()
Log(ticker)
Log(exchange.GetAccount())
exchange.SetCurrency("LTC_USDT")
Log("Switched to LTC_USDT")
ticker = exchange.GetTicker()
Log(ticker)
Log(exchange.GetAccount())
rust
fn main() {
let ticker = exchange.GetTicker(None).unwrap();
Log!(ticker);
Log!(exchange.GetAccount());
// Switch the trading pair, note the changes in market data and account information after switching
exchange.SetCurrency("LTC_USDT");
Log!("Switched to LTC_USDT");
let ticker = exchange.GetTicker(None).unwrap();
Log!(ticker);
Log!(exchange.GetAccount());
}
c++
void main() {
auto ticker = exchange.GetTicker();
Log(ticker);
Log(exchange.GetAccount());
exchange.SetCurrency("LTC_USDT");
Log("Switched to LTC_USDT");
ticker = exchange.GetTicker();
Log(ticker);
Log(exchange.GetAccount());
}Arguments
| Name | Type | Required | Description |
currency | string | Yes | The |
See Also
Remarks
-
Compatible with the
exchange.IO("currency", "BTC_USDT")switching method, seeexcahnge.IOfor details. -
Switching trading pairs is supported in the backtesting system, but when switching trading pairs in the backtesting system, the name of the quote currency cannot be changed. For example:
BTC_USDTcan be switched toLTC_USDT, but cannot be switched toLTC_BTC. -
After switching to a trading pair other than the one initially set on the backtesting page, the amount of the base currency is 0. For example: during backtesting, the trading pair initially set on the backtesting page is
BTC_USDT, with 3BTCand 10000USDT. If you immediately switch toLTC_USDTat this point, the amount of the base currency after switching is 0, i.e., the amount ofLTCin the account is 0; the amount ofUSDTis shared after switching, i.e., the amount remains 10000.
exchange.GetQuoteCurrency
The exchange.GetQuoteCurrency() function is used to get the name of the quote currency of the current trading pair, i.e. quoteCurrency.
exchange.GetQuoteCurrency()Examples
javascript
function main() {
exchange.SetCurrency("BTC_USDT")
Log("Quote currency for BTC_USDT:", exchange.GetQuoteCurrency())
// exchange.SetCurrency("ETH_BTC")
// Log("Quote currency for ETH_BTC:", exchange.GetQuoteCurrency())
}
python
def main():
exchange.SetCurrency("BTC_USDT")
Log("Quote currency for BTC_USDT:", exchange.GetQuoteCurrency())
# exchange.SetCurrency("ETH_BTC")
# Log("Quote currency for ETH_BTC:", exchange.GetQuoteCurrency())
rust
fn main() {
exchange.SetCurrency("BTC_USDT");
Log!("Quote currency for BTC_USDT:", exchange.GetQuoteCurrency());
// exchange.SetCurrency("ETH_BTC");
// Log!("Quote currency for ETH_BTC:", exchange.GetQuoteCurrency());
}
c++
void main() {
exchange.SetCurrency("BTC_USDT");
Log("Quote currency for BTC_USDT:", exchange.GetQuoteCurrency());
// exchange.SetCurrency("ETH_BTC")
// Log("Quote currency for ETH_BTC:", exchange.GetQuoteCurrency())
}Returns
| Type | Description |
string | The |
See Also
Remarks
For example: when the current trading pair of the exchange exchange object is BTC_USDT, the exchange.GetQuoteCurrency() function returns USDT; if the current trading pair is ETH_BTC, then the exchange.GetQuoteCurrency() function returns BTC.