forked from alpacahq/alpaca-trade-api-go
/
entities.go
278 lines (252 loc) · 8.22 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
package polygon
import "time"
// SymbolsMetadata is the structure that defines symbol
// metadata served through polygon's REST API.
type SymbolsMetadata struct {
Symbols []struct {
Symbol string `json:"symbol"`
Name string `json:"name"`
Type string `json:"type"`
Updated time.Time `json:"updated"`
IsOTC bool `json:"isOTC"`
URL string `json:"url"`
} `json:"symbols"`
}
// HistoricTrades is the structure that defines trade
// data served through polygon's REST API.
type HistoricTrades struct {
Day string `json:"day"`
Map struct {
C1 string `json:"c1"`
C2 string `json:"c2"`
C3 string `json:"c3"`
C4 string `json:"c4"`
E string `json:"e"`
P string `json:"p"`
S string `json:"s"`
T string `json:"t"`
} `json:"map"`
MsLatency int `json:"msLatency"`
Status string `json:"status"`
Symbol string `json:"symbol"`
Ticks []TradeTick `json:"ticks"`
Type string `json:"type"`
}
// TradeTick is the structure that contains the actual
// tick data included in a HistoricTrades response
type TradeTick struct {
Timestamp int64 `json:"t"`
Price float64 `json:"p"`
Size int `json:"s"`
Exchange string `json:"e"`
Condition1 int `json:"c1"`
Condition2 int `json:"c2"`
Condition3 int `json:"c3"`
Condition4 int `json:"c4"`
}
type MapItem struct {
Name string `json:"name"`
Type string `json:"type"`
}
// HistoricTradesV2 is the structure that defines trade
// data served through polygon's REST API.
type HistoricTradesV2 struct {
ResultsCount int64 `json:"results_count"`
Ticker string `json:"ticker"`
Results []TradeTickV2 `json:"results"`
Map map[string]MapItem `json:"map"`
}
// TradeTickV2 is the structure that contains the actual
// tick data included in a HistoricTradesV2 response
type TradeTickV2 struct {
SIPTimestamp *int64 `json:"t"`
ParticipantTimestamp *int64 `json:"y"`
TRFTimestamp *int64 `json:"f"`
SequenceNumber *int `json:"q"`
ID *string `json:"i"`
OrigID *string `json:"I"`
Exchange *int `json:"x"`
TRFID *int `json:"r"`
Size *int `json:"s"`
Conditions *[]int `json:"c"`
Price *float64 `json:"p"`
Tape *int `json:"z"`
Correction *int `json:"e"`
}
// HistoricQuotes is the structure that defines quote
// data served through polygon's REST API.
type HistoricQuotes struct {
Day string `json:"day"`
Map struct {
AE string `json:"aE"`
AP string `json:"aP"`
AS string `json:"aS"`
BE string `json:"bE"`
BP string `json:"bP"`
BS string `json:"bS"`
C string `json:"c"`
T string `json:"t"`
} `json:"map"`
MsLatency int `json:"msLatency"`
Status string `json:"status"`
Symbol string `json:"symbol"`
Ticks []QuoteTick `json:"ticks"`
Type string `json:"type"`
}
// QuoteTick is the structure that contains the actual
// tick data included in a HistoricQuotes response
type QuoteTick struct {
Timestamp int64 `json:"t"`
BidExchange string `json:"bE"`
AskExchange string `json:"aE"`
BidPrice float64 `json:"bP"`
AskPrice float64 `json:"aP"`
BidSize int `json:"bS"`
AskSize int `json:"aS"`
Condition int `json:"c"`
}
// HistoricQuotesV2 is the structure that defines trade
// data served through polygon's REST API.
type HistoricQuotesV2 struct {
ResultsCount int64 `json:"results_count"`
Ticker string `json:"ticker"`
Results []QuoteTickV2 `json:"results"`
Map map[string]MapItem `json:"map"`
}
// QuoteTickV2 is the structure that contains the actual
// tick data included in a HistoricQuotesV2 response
type QuoteTickV2 struct {
SIPTimestamp *int64 `json:"t"`
ParticipantTimestamp *int64 `json:"y"`
TRFTimestamp *int64 `json:"f"`
SequenceNumber *int `json:"q"`
Indicators *[]int `json:"i"`
BidExchange *int `json:"x"`
AskExchange *int `json:"X"`
TRFID *int `json:"r"`
Size *int `json:"s"`
Conditions *[]int `json:"c"`
BidPrice *float64 `json:"p"`
AskPrice *float64 `json:"P"`
BidSize *int `json:"s"`
AskSize *int `json:"S"`
Tape *int `json:"z"`
}
// HistoricAggregates is the structure that defines
// aggregate data served through Polygon's v1 REST API.
type HistoricAggregates struct {
Symbol string `json:"symbol"`
AggregateType AggType `json:"aggType"`
Map struct {
O string `json:"o"`
C string `json:"c"`
H string `json:"h"`
L string `json:"l"`
V string `json:"v"`
D string `json:"d"`
} `json:"map"`
Ticks []AggTick `json:"ticks"`
}
// HistoricAggregatesV2 is the structure that defines
// aggregate data served through Polygon's v2 REST API.
type HistoricAggregatesV2 struct {
Symbol string `json:"ticker"`
Adjusted bool `json:"adjusted"`
QueryCount int `json:"queryCount"`
ResultsCount int `json:"resultsCount"`
Ticks []AggTick `json:"results"`
}
type GetHistoricTradesParams struct {
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}
type HistoricTicksV2Params struct {
Timestamp int64 `json:"timestamp"`
TimestampLimit int64 `json:"timestamp_limit"`
Reverse bool `json:"reverse"`
Limit int64 `json:"limit"`
}
// AggTick is the structure that contains the actual
// tick data included in a HistoricAggregates response
type AggTick struct {
Open float64 `json:"o"`
High float64 `json:"h"`
Low float64 `json:"l"`
Close float64 `json:"c"`
Volume float64 `json:"v"`
EpochMilliseconds int64 `json:"t"`
Items int64 `json:"n"` // v2 response only
}
// AggType used in the HistoricAggregates response
type AggType string
const (
// Minute timeframe aggregates
Minute AggType = "minute"
// Day timeframe aggregates
Day AggType = "day"
)
// polygon stream
// PolygonClientMsg is the standard message sent by clients of the stream interface
type PolygonClientMsg struct {
Action string `json:"action"`
Params string `json:"params"`
}
type PolygonAuthMsg struct {
Event string `json:"ev"`
Status string `json:"status"`
Message string `json:"message"`
}
// PolygonServerMsg contains the field that is present in all responses to identify their type
type PolgyonServerMsg struct {
Event string `json:"ev"`
}
// StreamTrade is the structure that defines a trade that
// polygon transmits via websocket protocol.
type StreamTrade struct {
Symbol string `json:"sym"`
Exchange int `json:"x"`
TradeID string `json:"i"`
Price float64 `json:"p"`
Size int64 `json:"s"`
Timestamp int64 `json:"t"`
Conditions []int `json:"c"`
}
// StreamQuote is the structure that defines a quote that
// polygon transmits via websocket protocol.
type StreamQuote struct {
Symbol string `json:"sym"`
Condition int `json:"c"`
BidExchange int `json:"bx"`
AskExchange int `json:"ax"`
BidPrice float64 `json:"bp"`
AskPrice float64 `json:"ap"`
BidSize int64 `json:"bs"`
AskSize int64 `json:"as"`
Timestamp int64 `json:"t"`
}
// StreamAggregate is the structure that defines an aggregate that
// polygon transmits via websocket protocol.
type StreamAggregate struct {
Event string `json:"ev"`
Symbol string `json:"sym"`
Volume int `json:"v"`
AccumulatedVolume int `json:"av"`
OpeningPrice float64 `json:"op"`
VWAP float64 `json:"vw"`
OpenPrice float64 `json:"o"`
ClosePrice float64 `json:"c"`
HighPrice float64 `json:"h"`
LowPrice float64 `json:"l"`
Average float64 `json:"a"`
StartTimestamp int64 `json:"s"`
EndTimestamp int64 `json:"e"`
}
// Exchange defines the Stocks / Equities "Exchange" endpoint response
type StockExchange struct {
Id int64 `json:"id"`
Type string `json:"type"`
Market string `json:"market"`
Mic string `json:"mic"`
Name string `json:"name"`
Tape string `json:"tape"`
}