Access to crypto account and balances
Get access to current crypto account information.
public class TestStrategy : Strategy
{
[InputParameter("Selected account", 10)]
public Account inputAccount;
protected override void OnRun()
{
if (inputAccount != null)
{
Log("Currency name: " + inputAccount.AccountCurrency);
Log("Balance: " + inputAccount.Balance);
}
}
}CryptoAccount class
public class TestStrategy : Strategy
{
[InputParameter("Selected account", 10)]
public Account inputAccount;
private CryptoAccount cryptoAccount;
public TestStrategy()
: base()
{
// Defines strategy's name and description.
this.Name = "TestStrategy";
this.Description = "My strategy's annotation";
}
protected override void OnRun()
{
//
if (inputAccount == null)
{
Log("Input account is null", StrategyLoggingLevel.Error);
Stop();
return;
}
// check if selected account implements 'CryptoAccount' class
if (inputAccount is CryptoAccount)
{
// cast to 'CryptoAccount' type and store as a variable
cryptoAccount = (CryptoAccount)inputAccount;
// subscribe to 'BalanceUpdated' event
cryptoAccount.BalanceUpdated += CryptoAccount_BalanceUpdated;
// log coin name and available balance
foreach (CryptoAssetBalances coin in cryptoAccount.Balances)
{
Log($"Coin name: " + coin.AssetId);
Log($"Avalilable balance: " + coin.AvailableBalance);
}
}
}
protected override void OnStop()
{
// unsubscribe from 'BalanceUpdated' event
if (cryptoAccount != null)
{
cryptoAccount.BalanceUpdated -= CryptoAccount_BalanceUpdated;
cryptoAccount = null;
}
}
private void CryptoAccount_BalanceUpdated(object sender, CryptoAccountEventArgs e)
{
if (e.Reason == AccountBalanceEventReason.Update)
{
Log("Updated coin name: " + e.Balances.AssetId);
Log("Updated available balance: " + e.Balances.AvailableBalance);
}
}
}CryptoAssetBalances class
If crypto connection doesn't support CryptoAccount class

Last updated