-
Notifications
You must be signed in to change notification settings - Fork 83
/
entities.go
322 lines (286 loc) · 11.4 KB
/
entities.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package alpaca
import (
"time"
"cloud.google.com/go/civil"
"github.com/shopspring/decimal"
)
type Account struct {
ID string `json:"id"`
AccountNumber string `json:"account_number"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at"`
Status string `json:"status"`
Currency string `json:"currency"`
Cash decimal.Decimal `json:"cash"`
CashWithdrawable decimal.Decimal `json:"cash_withdrawable"`
TradingBlocked bool `json:"trading_blocked"`
TransfersBlocked bool `json:"transfers_blocked"`
AccountBlocked bool `json:"account_blocked"`
ShortingEnabled bool `json:"shorting_enabled"`
BuyingPower decimal.Decimal `json:"buying_power"`
PatternDayTrader bool `json:"pattern_day_trader"`
DaytradeCount int64 `json:"daytrade_count"`
DaytradingBuyingPower decimal.Decimal `json:"daytrading_buying_power"`
RegTBuyingPower decimal.Decimal `json:"regt_buying_power"`
Equity decimal.Decimal `json:"equity"`
LastEquity decimal.Decimal `json:"last_equity"`
Multiplier string `json:"multiplier"`
InitialMargin decimal.Decimal `json:"initial_margin"`
MaintenanceMargin decimal.Decimal `json:"maintenance_margin"`
LastMaintenanceMargin decimal.Decimal `json:"last_maintenance_margin"`
LongMarketValue decimal.Decimal `json:"long_market_value"`
ShortMarketValue decimal.Decimal `json:"short_market_value"`
PortfolioValue decimal.Decimal `json:"portfolio_value"`
}
type Order struct {
ID string `json:"id"`
ClientOrderID string `json:"client_order_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
SubmittedAt time.Time `json:"submitted_at"`
FilledAt *time.Time `json:"filled_at"`
ExpiredAt *time.Time `json:"expired_at"`
CanceledAt *time.Time `json:"canceled_at"`
FailedAt *time.Time `json:"failed_at"`
ReplacedAt *time.Time `json:"replaced_at"`
Replaces *string `json:"replaces"`
ReplacedBy *string `json:"replaced_by"`
AssetID string `json:"asset_id"`
Symbol string `json:"symbol"`
Class string `json:"asset_class"`
OrderClass OrderClass `json:"order_class"`
Qty *decimal.Decimal `json:"qty"`
Notional *decimal.Decimal `json:"notional"`
FilledQty decimal.Decimal `json:"filled_qty"`
Type OrderType `json:"type"`
Side Side `json:"side"`
TimeInForce TimeInForce `json:"time_in_force"`
LimitPrice *decimal.Decimal `json:"limit_price"`
FilledAvgPrice *decimal.Decimal `json:"filled_avg_price"`
StopPrice *decimal.Decimal `json:"stop_price"`
TrailPrice *decimal.Decimal `json:"trail_price"`
TrailPercent *decimal.Decimal `json:"trail_percent"`
Hwm *decimal.Decimal `json:"hwm"`
Status string `json:"status"`
ExtendedHours bool `json:"extended_hours"`
Legs *[]Order `json:"legs"`
}
type Position struct {
AssetID string `json:"asset_id"`
Symbol string `json:"symbol"`
Exchange string `json:"exchange"`
Class string `json:"asset_class"`
AccountID string `json:"account_id"`
EntryPrice decimal.Decimal `json:"avg_entry_price"`
Qty decimal.Decimal `json:"qty"`
Side string `json:"side"`
MarketValue *decimal.Decimal `json:"market_value"`
CostBasis decimal.Decimal `json:"cost_basis"`
UnrealizedPL *decimal.Decimal `json:"unrealized_pl"`
UnrealizedPLPC *decimal.Decimal `json:"unrealized_plpc"`
CurrentPrice *decimal.Decimal `json:"current_price"`
LastdayPrice *decimal.Decimal `json:"lastday_price"`
ChangeToday *decimal.Decimal `json:"change_today"`
}
type Asset struct {
ID string `json:"id"`
Name string `json:"name"`
Exchange string `json:"exchange"`
Class string `json:"class"`
Symbol string `json:"symbol"`
Status string `json:"status"`
Tradable bool `json:"tradable"`
Marginable bool `json:"marginable"`
Shortable bool `json:"shortable"`
EasyToBorrow bool `json:"easy_to_borrow"`
Fractionable bool `json:"fractionable"`
}
type Fundamental struct {
AssetID string `json:"asset_id"`
Symbol string `json:"symbol"`
FullName string `json:"full_name"`
IndustryName string `json:"industry_name"`
IndustryGroup string `json:"industry_group"`
Sector string `json:"sector"`
PERatio float32 `json:"pe_ratio"`
PEGRatio float32 `json:"peg_ratio"`
Beta float32 `json:"beta"`
EPS float32 `json:"eps"`
MarketCap int64 `json:"market_cap"`
SharesOutstanding int64 `json:"shares_outstanding"`
AvgVol int64 `json:"avg_vol"`
DivRate float32 `json:"div_rate"`
ROE float32 `json:"roe"`
ROA float32 `json:"roa"`
PS float32 `json:"ps"`
PC float32 `json:"pc"`
GrossMargin float32 `json:"gross_margin"`
FiftyTwoWeekHigh decimal.Decimal `json:"fifty_two_week_high"`
FiftyTwoWeekLow decimal.Decimal `json:"fifty_two_week_low"`
ShortDescription string `json:"short_description"`
LongDescription string `json:"long_description"`
}
type CalendarDay struct {
Date string `json:"date"`
Open string `json:"open"`
Close string `json:"close"`
}
type Clock struct {
Timestamp time.Time `json:"timestamp"`
IsOpen bool `json:"is_open"`
NextOpen time.Time `json:"next_open"`
NextClose time.Time `json:"next_close"`
}
type AccountConfigurations struct {
DtbpCheck DtbpCheck `json:"dtbp_check"`
NoShorting bool `json:"no_shorting"`
TradeConfirmEmail TradeConfirmEmail `json:"trade_confirm_email"`
TradeSuspendedByUser bool `json:"trade_suspended_by_user"`
}
type AccountActivity struct {
ID string `json:"id"`
ActivityType string `json:"activity_type"`
TransactionTime time.Time `json:"transaction_time"`
Type string `json:"type"`
Price decimal.Decimal `json:"price"`
Qty decimal.Decimal `json:"qty"`
Side string `json:"side"`
Symbol string `json:"symbol"`
LeavesQty decimal.Decimal `json:"leaves_qty"`
CumQty decimal.Decimal `json:"cum_qty"`
Date civil.Date `json:"date"`
NetAmount decimal.Decimal `json:"net_amount"`
Description string `json:"description"`
PerShareAmount decimal.Decimal `json:"per_share_amount"`
}
type PortfolioHistory struct {
BaseValue decimal.Decimal `json:"base_value"`
Equity []decimal.Decimal `json:"equity"`
ProfitLoss []decimal.Decimal `json:"profit_loss"`
ProfitLossPct []decimal.Decimal `json:"profit_loss_pct"`
Timeframe RangeFreq `json:"timeframe"`
Timestamp []int64 `json:"timestamp"`
}
type PlaceOrderRequest struct {
AccountID string `json:"-"`
AssetKey *string `json:"symbol"`
Qty *decimal.Decimal `json:"qty"`
Notional *decimal.Decimal `json:"notional"`
Side Side `json:"side"`
Type OrderType `json:"type"`
TimeInForce TimeInForce `json:"time_in_force"`
LimitPrice *decimal.Decimal `json:"limit_price"`
ExtendedHours bool `json:"extended_hours"`
StopPrice *decimal.Decimal `json:"stop_price"`
ClientOrderID string `json:"client_order_id"`
OrderClass OrderClass `json:"order_class"`
TakeProfit *TakeProfit `json:"take_profit"`
StopLoss *StopLoss `json:"stop_loss"`
TrailPrice *decimal.Decimal `json:"trail_price"`
TrailPercent *decimal.Decimal `json:"trail_percent"`
}
type TakeProfit struct {
LimitPrice *decimal.Decimal `json:"limit_price"`
}
type StopLoss struct {
LimitPrice *decimal.Decimal `json:"limit_price"`
StopPrice *decimal.Decimal `json:"stop_price"`
}
type OrderAttributes struct {
TakeProfitLimitPrice *decimal.Decimal `json:"take_profit_limit_price,omitempty"`
StopLossStopPrice *decimal.Decimal `json:"stop_loss_stop_price,omitempty"`
StopLossLimitPrice *decimal.Decimal `json:"stop_loss_limit_price,omitempty"`
}
type ReplaceOrderRequest struct {
Qty *decimal.Decimal `json:"qty"`
LimitPrice *decimal.Decimal `json:"limit_price"`
StopPrice *decimal.Decimal `json:"stop_price"`
Trail *decimal.Decimal `json:"trail"`
TimeInForce TimeInForce `json:"time_in_force"`
ClientOrderID string `json:"client_order_id"`
}
type AccountConfigurationsRequest struct {
DtbpCheck *string `json:"dtbp_check"`
NoShorting *bool `json:"no_shorting"`
TradeConfirmEmail *string `json:"trade_confirm_email"`
TradeSuspendedByUser *bool `json:"trade_suspended_by_user"`
}
type AccountActivitiesRequest struct {
ActivityTypes *[]string `json:"activity_types"`
Date *time.Time `json:"date"`
Until *time.Time `json:"until"`
After *time.Time `json:"after"`
Direction *string `json:"direction"`
PageSize *int `json:"page_size"`
}
type ListOrdersRequest struct {
Status *string `json:"status"`
After *time.Time `json:"after"`
Until *time.Time `json:"until"`
Limit *int `json:"limit"`
Direction *string `json:"direction"`
Nested *bool `json:"nested"`
Symbols *string `json:"symbols"`
Side *string `json:"side"`
}
type Side string
const (
Buy Side = "buy"
Sell Side = "sell"
)
type OrderType string
const (
Market OrderType = "market"
Limit OrderType = "limit"
Stop OrderType = "stop"
StopLimit OrderType = "stop_limit"
TrailingStop OrderType = "trailing_stop"
)
type OrderClass string
const (
Bracket OrderClass = "bracket"
Oto OrderClass = "oto"
Oco OrderClass = "oco"
Simple OrderClass = "simple"
)
type TimeInForce string
const (
Day TimeInForce = "day"
GTC TimeInForce = "gtc"
OPG TimeInForce = "opg"
IOC TimeInForce = "ioc"
FOK TimeInForce = "fok"
GTX TimeInForce = "gtx"
GTD TimeInForce = "gtd"
CLS TimeInForce = "cls"
)
type DtbpCheck string
const (
Entry DtbpCheck = "entry"
Exit DtbpCheck = "exit"
Both DtbpCheck = "both"
)
type TradeConfirmEmail string
const (
None TradeConfirmEmail = "none"
All TradeConfirmEmail = "all"
)
type RangeFreq string
const (
Min1 RangeFreq = "1Min"
Min5 RangeFreq = "5Min"
Min15 RangeFreq = "15Min"
Hour1 RangeFreq = "1H"
Day1 RangeFreq = "1D"
)
// stream
type TradeUpdate struct {
Event string `json:"event"`
ExecutionID string `json:"execution_id"`
Order Order `json:"order"`
PositionQty *decimal.Decimal `json:"position_qty"`
Price *decimal.Decimal `json:"price"`
Qty *decimal.Decimal `json:"qty"`
Timestamp *time.Time `json:"timestamp"`
}