Esempio n. 1
0
        public async Task GetAccount()
        {
            AccountInfo.Clear();
            // Account info
            TTAccount account = await _client.GetAccountAsync();

            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Id), account.Id));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Group), account.Group));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.AccountingType), account.AccountingType));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Name), account.Name));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Email), account.Email));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Comment), account.Comment));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Registered), account.Registered.ToString("u")));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.IsBlocked), account.IsBlocked));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.IsReadonly), account.IsReadonly));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.IsValid), account.IsValid));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.IsWebApiEnabled), account.IsWebApiEnabled));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Leverage), account.Leverage));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Balance), account.Balance));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.BalanceCurrency), account.BalanceCurrency));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Equity), account.Equity));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.Margin), account.Margin));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.MarginLevel), account.MarginLevel));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.MarginCallLevel), account.MarginCallLevel));
            AccountInfo.Add(new KeyValuePair <string, object>(nameof(account.StopOutLevel), account.StopOutLevel));

            IsAccountCash = account.AccountingType == TTAccountingTypes.Cash;
            IsAccountNet  = account.AccountingType == TTAccountingTypes.Net;
        }
Esempio n. 2
0
        public async Task <List <Account> > UpdateAccountsAsync(string accountId = "")
        {
            string json = null;

            try
            {
                ProcessLogBroadcast?.Invoke(ApplicationName, MessageType.General, "Updating Account Information.");
                Request request = new Request(ConnectionAdapter.Authentication.EndpointUrl, "GET",
                                              $"/accounts/{accountId}");
                json = await ConnectionAdapter.RequestAsync(request);

                ProcessLogBroadcast?.Invoke(ApplicationName, MessageType.JsonOutput,
                                            $"UpdateAccountsAsync JSON:\r\n{json}");
                //check if we do not have any error messages
                Accounts = JsonSerializer.Deserialize <List <Account> >(json);
                if (Accounts != null)
                {
                    Accounts.ForEach(account =>
                    {
                        AccountInfo ??= new Dictionary <string, decimal>();
                        if (account.Balance.ToDecimal() <= 0)
                        {
                            return;
                        }
                        if (AccountInfo.ContainsKey(account.Currency))
                        {
                            AccountInfo[account.Currency] = account.Balance.ToDecimal();
                        }
                        else
                        {
                            AccountInfo.Add(account.Currency, account.Balance.ToDecimal());
                        }
                    });
                    NotifyAccountInfo?.Invoke(ApplicationName, AccountInfo);
                    Save();
                }
            }
            catch (Exception e)
            {
                ProcessLogBroadcast?.Invoke(ApplicationName, MessageType.Error,
                                            $"Method: UpdateAccountsAsync\r\nException Stack Trace: {e.StackTrace}\r\nJSON: {json}");
            }

            return(Accounts);
        }