-
-
Notifications
You must be signed in to change notification settings - Fork 14
Using Account methods
Fetch positions, balances, and other account-related details.
For all the account-related usages, make sure you include the Account Model namespace:
using Tradier.Client.Models.Account;
The user’s profile contains information pertaining to the user and his/her accounts. In addition to listing all the accounts a user has, this call should be used to create a personalized experience for your customers (i.e. displaying their name when they log in).
Profile userProfile = await client.Account.GetUserProfile();
Get balances information for a specific user account. Account balances are calculated on each request during market hours. Each night, balance figures are reconciled with our clearing firm and used as starting point for the following market session.
The account number is found in the Profile model.
Balances balance = await client.Account.GetBalances(accountNumber);
Get the current positions being held in an account. These positions are updated intraday via trading.
The account number is found in the Profile model.
Positions positions = await client.Account.GetPositions(accountNumber);
Get historical activity for an account. This data originates with our clearing firm and inherently has a few limitations:
- Updated nightly (not intraday)
- Will not include specific time (hours/minutes) a position or order was created or closed
- Will not include order numbers
The account number is found in the Profile model.
History history = await client.Account.GetHistory(accountNumber);
Get cost basis information for a specific user account. This includes information for all closed positions. Cost basis information is updated through a nightly batch reconciliation process with our clearing firm.
The account number is found in the Profile model.
GainLoss gainLoss = await client.Account.GetGainLoss(accountNumber);
Retrieve orders placed within an account. Without additional parameters, this API will return orders placed for the market session of the present calendar day.
The account number is found in the Profile model.
Orders orders = await client.Account.GetOrders(accountNumber);
Get detailed information about a previously placed order.
The account number is found in the Profile model.
Order order = await client.Account.GetOrder(accountNumber, orderId);
using System;
using System.Linq;
using System.Threading.Tasks;
using Tradier.Client;
using Tradier.Client.Models.Account;
namespace MyConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
TradierClient client = new TradierClient("<TOKEN>");
Profile userProfile = await client.Account.GetUserProfile();
string accountNumber = userProfile.Account.FirstOrDefault()?.AccountNumber;
Balances balance = await client.Account.GetBalances(accountNumber);
Console.WriteLine($"Cash: {balance.Cash}");
Positions positions = await client.Account.GetPositions(accountNumber);
Console.WriteLine($"Symbols: {String.Join(",",positions.Position.Select(x => x.Symbol))}");
History history = await client.Account.GetHistory(accountNumber);
Console.WriteLine($"History events: {history.Event.Count}");
GainLoss gainLoss = await client.Account.GetGainLoss(accountNumber);
Console.WriteLine($"Positions: {gainLoss.ClosedPosition.Count}");
Orders orders = await client.Account.GetOrders(accountNumber);
Console.WriteLine($"Orders: {orders.Order.Count}");
}
}
}
Created by Henrique Tedeschi and Vitali Karmanov. See our Disclaimer. Check the API documentation on Tradier API.