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 exchange. The member functions (methods) of the exchange object are only related to exchange, which will not be repeated in subsequent documentation.
exchange.GetAccount()Examples
Set trading pair and contract code, get current account information.
javascript
function main(){
// 切换交易对
exchange.IO("currency", "BTC_USDT")
// 以OKX期货为例,设置合约为当周合约,当前交易对为BTC_USDT,所以当前合约为BTC的U本位当周合约
exchange.SetContractType("this_week")
// 获取当前账户资产数据
var account = exchange.GetAccount()
// USDT作为保证金的可用余额
Log(account.Balance)
// USDT作为保证金的冻结金额
Log(account.FrozenBalance)
// 当前资产权益
Log(account.Equity)
// 当前资产作为保证金的所有持仓的未实现盈亏
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"])
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 |
| Query account asset information. Returns |
See Also
Remarks
If the exchange object is set to a cryptocurrency futures contract exchange and switched to contracts using USDT as margin (for switching methods, please refer to exchange.SetCurrency, exchange.SetContractType functions), assets are margined in USDT 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 coin-margined contracts, assets are margined in coins and recorded in the Stocks and FrozenStocks properties of the Account structure.
When using Binance Futures unified account, when calling the exchange.GetAccount() function to request account information, the encapsulated data is the amount of all assets converted to **USD**, displayed in the Balance field of the Account structure. To calculate the converted amount of other assets, divide the USD converted amount by the index price (of the asset to be converted) and then divide by the collateral rate (of the asset to be converted).
exchange.GetAssets
The exchange.GetAssets function is used to request asset information from the exchange account.
exchange.GetAssets()Examples
Get exchange account asset information, exchange.GetAssets() returns an array with Asset structure elements.
javascript
function main() {
// exchange.SetCurrency("BTC_USDT") // 可以设置交易对
// exchange.SetContractType("swap") // 可以设置合约
var assets = exchange.GetAssets()
Log(assets)
}
python
def main():
# exchange.SetCurrency("BTC_USDT") # 可以设置交易对
# exchange.SetContractType("swap") # 可以设置合约
assets = exchange.GetAssets()
Log(assets)
c++
void main() {
// exchange.SetCurrency("BTC_USDT"); // 可以设置交易对
// exchange.SetContractType("swap"); // 可以设置合约
auto assets = exchange.GetAssets();
Log(assets);
}Returns
| Type | Description |
| The |
See Also
Remarks
The GetAssets() function of futures exchange objects returns margin asset information under the current trading pair (coin-margined, USDT-margined, USDC-margined, etc.).
exchange.GetName
The exchange.GetName() function is used to get the exchange name 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")
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 commonly used to identify exchange objects such as exchange or exchanges[1], exchanges[2] etc. in strategy code. Cryptocurrency futures contract exchange names have a fixed prefix Futures_.
exchange.GetLabel
The exchange.GetLabel() function is used to get 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())
c++
void main() {
Log("exchange label:", exchange.GetLabel());
}Returns
| Type | Description |
string | The |
See Also
Remarks
Identify exchange objects such as exchange or exchanges[1], exchanges[2] etc. in the strategy code through the set labels.
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())
c++
void main() {
Log("Current trading pair:", exchange.GetCurrency());
}Returns
| Type | Description |
string | The |
See Also
Remarks
The trading pair format is uniformly in uppercase, using underscore to separate 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 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())
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
exchange.IO("currency", "BTC_USDT")switching method, refer toexcahnge.IO. -
Supports switching trading pairs in the backtesting system. When switching trading pairs in the backtesting system, the quote currency name cannot be changed. For example:
BTC_USDTcan be switched toLTC_USDT, but cannot be switched toLTC_BTC. -
After switching to a trading pair that is not initially set on the backtesting page, the amount of the base currency is 0. For example: during backtesting, the initially set trading pair on the backtesting page is
BTC_USDT, with 3BTCand 10000USDT. When immediately switching toLTC_USDT, after switching, the base currency amount is 0, meaning theLTCamount in the account is 0, and the switched trading pair shares theUSDTamount, which remains 10000.
exchange.GetQuoteCurrency
The exchange.GetQuoteCurrency() function is used to get the quote currency name 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())
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: if 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, the exchange.GetQuoteCurrency() function returns BTC.