Account Class

View as Markdown

Definition

The Account class can be used to subscribe to account-related events as well as access account-related information.

Also happens when rewinding/fast forwarding Playback connections.

Static Account Class Properties

PropertyDescription
AllA collection of Account objects
AccountStatusUpdateEvent handler for account status updates
SimulationAccountResetEvent handler for resets on sim accounts

Methods and Properties From Account instances

PropertyDescription
AccountItemRepresents various account variables used to reflect values the status of the account
AccountItemUpdateEvent handler for changes to account values
Cancel()Cancels specified order(s) on the account
CancelAllOrders()Cancels all orders of an instrument on the account
Change()Changes specified order(s) on the account
ConnectionA Connection representing the connection this account is associated with
CreateOrder()Creates orders for the account that need to be submitted via Submit()
DenominationA Currency representing the denomination currency of this connection
ExecutionsA collection of executions on this account
ExecutionUpdateEvent handler for when new executions come in, an existing execution is amended, or an execution is removed
Flatten()Flattens the account on specified instrument(s)
Get()Returns the value of an AccountItem
NameA string representing the name of this account
OrdersA collection of orders on this account
OrderUpdateEvent handler for changes to orders
PositionsA collection of positions on this account
PositionUpdateEvent handler for changes to positions
StrategiesA collection of strategies on this account
Submit()Submits specified order(s)

Example

1private Account myAccount;
2
3protected override void OnStateChange()
4{
5 if (State == State.SetDefaults)
6 {
7 // Find our Sim101 account
8 lock (Account.All)
9 myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
10
11 // Subscribe to static events. Remember to unsubscribe with -= when you are done
12 Account.AccountStatusUpdate += OnAccountStatusUpdate;
13
14 if (myAccount != null)
15 {
16 // Print some information about our account using the AccountItem indexer
17 Print(string.Format("Account Name: {0} Connection Name: {1} Cash Value {2}",
18 myAccount.Name,
19 myAccount.Connection.Options.Name,
20 myAccount.Get(AccountItem.CashValue, Currency.UsDollar)));
21
22 // Print the prices of the executions on our account
23 lock (myAccount.Executions)
24 foreach (Execution execution in myAccount.Executions)
25 Print("Price: " + execution.Price);
26
27 // Subscribe to events. Remember to unsubscribe with -= when you are done
28 myAccount.AccountItemUpdate += OnAccountItemUpdate;
29 myAccount.ExecutionUpdate += OnExecutionUpdate;
30 }
31 }
32 else if (State == State.Terminated)
33 {
34 // Unsubscribe to events
35 myAccount.AccountItemUpdate -= OnAccountItemUpdate;
36 myAccount.ExecutionUpdate -= OnExecutionUpdate;
37 Account.AccountStatusUpdate -= OnAccountStatusUpdate;
38 }
39}
40
41private void OnAccountStatusUpdate(object sender, AccountStatusEventArgs e)
42{
43 // Do something with the account status update
44}
45
46private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
47{
48 // Do something with the account item update
49}
50
51private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
52{
53 // Do something with the execution update
54}