forked from alexurquhart/qapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
217 lines (156 loc) · 6.31 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package qapi
import (
"time"
)
// Account represents an account associated with the user on behalf
// of which the API client is authorized.
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts
type Account struct {
// Type of the account (e.g., "Cash", "Margin").
Type string `json:"type"`
// Eight-digit account number (e.g., "26598145")
// Stored as a string, it's used for making account-related API calls
Number string `json:"number"`
// Status of the account (e.g., Active).
Status string `json:"status"`
// Whether this is a primary account for the holder.
IsPrimary bool `json:"isPrimary"`
// Whether this account is one that gets billed for various expenses such as inactivity fees, market data, etc.
IsBilling bool `json:"isBilling"`
// Type of client holding the account (e.g., "Individual").
ClientAccountType string `json:"clientAccountType"`
}
// Position belonging to an account
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-positions
type Position struct {
// Position symbol.
Symbol string `json:"symbol"`
// Internal symbol identifier
SymbolID int `json:"symbolId"`
// Position quantity remaining open.
OpenQuantity float32 `json:"openQuantity"`
// Portion of the position that was closed today.
ClosedQuantity float32 `json:"closedQuantity"`
// Market value of the position (quantity x price).
CurrentMarketValue float32 `json:"currentMarketValue"`
// Current price of the position symbol.
CurrentPrice float32 `json:"currentPrice"`
// Average price paid for all executions constituting the position.
AverageEntryPrice float32 `json:"averageEntryPrice"`
// Realized profit/loss on this position.
ClosedPnL float32 `json:"closedPnL"`
// Unrealized profit/loss on this position.
OpenPnL float32 `json:"openPnL"`
// Total cost of the position.
TotalCost float32 `json:"totalCost"`
// Designates whether real-time quote was used to compute PnL.
IsRealTime bool `json:"isRealTime"`
// Designates whether a symbol is currently undergoing a reorg.
IsUnderReorg bool `json:"isUnderReorg"`
}
// Balance belonging to an Account
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
type Balance struct {
// Currency of the balance figure(e.g., "USD" or "CAD").
Currency string `json:"currency"`
// Balance amount.
Cash float32 `json:"cash"`
// Market value of all securities in the account in a given currency.
MarketValue float32 `json:"marketValue"`
// Equity as a difference between cash and marketValue properties.
TotalEquity float32 `json:"totalEquity"`
// Buying power for that particular currency side of the account.
BuyingPower float32 `json:"buyingPower"`
// Maintenance excess for that particular side of the account.
MaintenanceExcess float32 `json:"maintenanceExcess"`
// Whether real-time data was used to calculate the above values.
IsRealTime bool `json:"isRealTime"`
}
// AccountBalances represents per-currency and combined balances for a specified account.
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
type AccountBalances struct {
PerCurrencyBalances []Balance `json:"perCurrencyBalances"`
CombinedBalances []Balance `json:"combinedBalances"`
SODPerCurrencyBalances []Balance `json:"sodPerCurrencyBalances"`
SODCombinedBalances []Balance `json:"sodCombinedBalances"`
}
// Execution belonging to an Account
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-executions
type Execution struct {
// Execution symbol.
Symbol string `json:"symbol"`
// Internal symbol identifier
SymbolID int `json:"symbolId"`
// Execution quantity.
Quantity int `json:"quantity"`
// Client side of the order to which execution belongs.
Side string `json:"side"`
// Execution price.
Price float32 `json:"price"`
// Internal identifier of the execution.
ID int `json:"id"`
// Internal identifier of the order to which the execution belongs.
OrderID int `json:"orderId"`
// Internal identifier of the order chain to which the execution belongs.
OrderChainID int `json:"orderChainId"`
// Identifier of the execution at the market where it originated.
ExchangeExecID string `json:"exchangeExecId"`
// Execution timestamp.
Timestamp time.Time `json:"timestamp"`
// Manual notes that may have been entered by Trade Desk staff
Notes string `json:"notes"`
// Trading venue where execution originated.
Venue string `json:"venue"`
// Execution cost (price x quantity).
TotalCost float32 `json:"totalCost"`
// Questrade commission for orders placed with Trade Desk.
OrderPlacementCommission float32 `json:"orderPlacementCommission"`
// Questrade commission.
Commission float32 `json:"commission"`
// Liquidity fee charged by execution venue.
ExecutionFee float32 `json:"executionFee"`
// SEC fee charged on all sales of US securities.
SecFee float32 `json:"secFee"`
// Additional execution fee charged by TSX (if applicable).
CanadianExecutionFee int `json:"canadianExecutionFee"`
// Internal identifierof the parent order.
ParentID int `json:"parentId"`
}
// Activity belonging to an Account
//
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-activities
type Activity struct {
// Trade timestamp.
TradeDate time.Time `json:"tradeDate"`
// Transaction timestamp.
TransactionDate time.Time `json:"transactionDate"`
// Expected settlement timestamp.
SettlementDate time.Time `json:"settlementDate"`
// Action code (ie: DEP, CON, BUY, SELL, TFI).
Action string `json:"action"`
// Activity symbol (if activity is related to a security).
Symbol string `json:"symbol"`
// Internal symbol identifier.
SymbolID int `json:"symbolId"`
// Notes field describing the activity.
Description string `json:"description"`
// Currency of activity (ie: CAD, USD).
Currency string `json:"currency"`
// Activity quantity (number of shares, etc.).
Quantity float32 `json:"quantity"`
// Price paid.
Price float32 `json:"price"`
// Gross amount.
GrossAmount float32 `json:"grossAmount"`
// Total of any commission paid.
Commission float32 `json:"commission"`
// Net amount.
NetAmount float32 `json:"netAmount"`
// Text description of the action (ie: "Transfers", "Interest").
Type string `json:"type"`
}