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}
Trade exchange.GetAssets