-
Notifications
You must be signed in to change notification settings - Fork 12
/
market.go
291 lines (207 loc) · 7.63 KB
/
market.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
package qapi
import (
"time"
)
// Detailed information about a symbol
// Ref: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id
type Symbol struct {
// Symbol that follows Questrade symbology (e.g., "TD.TO").
Symbol string `json:"symbol"`
// Symbol identifier
SymbolID int `json:"symbolId"`
// Closing trade price from the previous trading day.
PrevDayClosePrice float32 `json:"prevDayClosePrice"`
// 52-week high price.
HighPrice52 float32 `json:"highPrice52"`
// 52-week low price.
LowPrice52 float32 `json:"lowPrice52"`
// Average trading volume over trailing 3 months.
AverageVol3Months int `json:"averageVol3Months"`
// Average trading volume over trailing 20 days.
AverageVol20Days int `json:"averageVol20Days"`
// Total number of shares outstanding.
OutstandingShares int `json:"outstandingShares"`
// Trailing 12-month earnings per share.
EPS float32 `json:"eps"`
// Trailing 12-month price to earnings ratio.
PE float32 `json:"pe"`
// Dividend amount per share.
Dividend float32 `json:"dividend"`
// Dividend yield (dividend / prevDayClosePrice).
Yield float32 `json:"yield"`
// Dividend ex-date.
ExDate *time.Time `json:"exDate"`
// Market capitalization (outstandingShares * prevDayClosePrice).
MarketCap float32 `json:"marketCap"`
// Option type (e.g., "Call").
OptionType string `json:"optionType"`
// Option duration type (e.g., "Weekly").
OptionDurationType string `json:"optionDurationType"`
// Option root symbol (e.g., "MSFT").
OptionRoot string `json:"optionRoot"`
// Option contract deliverables.
OptionContractDeliverables OptionContractDeliverables `json:"optionContractDeliverables"`
// Option exercise style (e.g., "American").
OptionExerciseType string `json:"optionExerciseType"`
// Primary listing exchange.
ListingExchange string `json:"listingExchange"`
// Symbol description (e.g., "Microsoft Corp.").
Description string `json:"description"`
// Security type (e.g., "Stock").
SecurityType string `json:"securityType"`
// Option expiry date.
OptionExpiryDate *time.Time `json:"optionExpiryDate"`
// Dividend declaration date.
DividendDate *time.Time `json:"dividendDate"`
// Option strike price.
OptionStrikePrice float32 `json:"optionStrikePrice"`
// Indicates whether the symbol is actively listed.
IsQuotable bool `json:"isQuotable"`
// Indicates whether the symbol is an underlying option.
HasOptions bool `json:"hasOptions"`
// String Currency code (follows ISO format).
Currency string `json:"currency"`
// List of MinTickData records.
MinTicks []MinTickData `json:"minTicks"`
}
type UnderlyingMultiplierPair struct {
Multiplier int `json:"multiplier"`
UnderlyingSymbol string `json:"underlyingSymbol"`
UnderlyingSymbolID string `json:"underlyingSymbolId"`
}
type OptionContractDeliverables struct {
Underlyings []UnderlyingMultiplierPair `json:"underlyings"`
CashInLieu float32 `json:"cashInLieu"`
}
type MinTickData struct {
Pivot float32 `json:"pivot"`
MinTick float32 `json:"minTick"`
}
// Symbol information retreived from search results
// Ref: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-search
type SymbolSearchResult struct {
Symbol string `json:"symbol"`
SymbolID int `json:"symbolId"`
Description string `json:"description"`
SecurityType string `json:"securityType"`
ListingExchange string `json:"listingExchange"`
IsQuotable bool `json:"isQuotable"`
IsTradable bool `json:"isTradable"`
Currency string `json:"currency"`
}
type ChainPerStrikePrice struct {
// Option strike price.
StrikePrice float32 `json:"strikePrice"`
// Internal identifier of the call option symbol.
CallSymbolID int `json:"callSymbolId"`
// Internal identifier of the put option symbol.
PutSymbolID int `json:"putSymbolId"`
}
type ChainPerRoot struct {
// Option root symbol.
Root string `json:"root"`
// Slice of ChainPerStrikePrice elements.
ChainPerStrikePrice []ChainPerStrikePrice `json:"chainPerStrikePrice"`
// NOTE - This value appears in example API response, but is not documented
Multiplier int `json:"multiplier"`
}
// Option Chain
// Ref: www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id-options
type OptionChain struct {
// Option expiry date.
ExpiryDate time.Time `json:"expiryDate"`
// Description of the underlying option.
Description string `json:"description"`
// Primary listing exchange.
ListingExchange string `json:"listingExchange"`
// Option exercise style (e.g., "American").
OptionExerciseType string `json:"optionExerciseType"`
// Slice of ChainPerRoot elements
ChainPerRoot []ChainPerRoot `json:"chainPerRoot"`
}
// Market represents information about supported markets
type Market struct {
// Market name.
Name string `json:"name"`
// List of trading venue codes.
TradingVenues []string `json:"tradingVenues"`
// Default trading venue code.
DefaultTradingVenue string `json:"defaultTradingVenue"`
// List of primary order route codes.
PrimaryOrderRoutes []string `json:"primaryOrderRoutes"`
// List of secondary order route codes.
SecondaryOrderRoutes []string `json:"secondaryOrderRoutes"`
// List of level 1 market data feed codes.
Level1Feeds []string `json:"level1Feeds"`
// List of level 2 market data feed codes.
Level2Feeds []string `json:"level2Feeds"`
// Pre-market opening time for current trading date.
ExtendedStartTime time.Time `json:"extendedStartTime"`
// Regular market opening time for current trading date.
StartTime time.Time `json:"startTime"`
// Regular market closing time for current trading date.
EndTime time.Time `json:"endTime"`
// Extended market closing time for current trading date.
ExtendedEndTime time.Time `json:"extendedEndTime"`
// Currency code (ISO format).
Currency string `json:"currency"`
// Number of snap quotes that the user can retrieve from a market.
SnapQuotesLimit int `json:"snapQuotesLimit"`
}
// Quote represents a Lvl 1 market data quote for a particular symbol
type Quote struct {
// Symbol name following Questrade’s symbology.
Symbol string `json:"symbol"`
// Internal symbol identifier.
SymbolID int `json:"symbolId"`
// Market tier.
Tier string `json:"tier"`
// Bid price.
BidPrice float32 `json:"bidPrice"`
// Bid quantity.
BidSize int `json:"bidSize"`
// Ask price.
AskPrice float32 `json:"askPrice"`
// Ask quantity.
AskSize int `json:"askSize"`
// Price of the last trade during regular trade hours.
LastTradeTrHrs float32 `json:"lastTradeTrHrs"`
// Price of the last trade.
LastTradePrice float32 `json:"lastTradePrice"`
// Quantity of the last trade.
LastTradeSize int `json:"lastTradeSize"`
// Trade direction.
LastTradeTick string `json:"lastTradeTick"`
// Timestamp
LastTtradeTime string `json:"lastTradeTime"`
// Volume.
Volume int `json:"volume"`
// Opening trade price.
OpenPrice float32 `json:"openPrice"`
// Daily high price.
HighPrice float32 `json:"highPrice"`
// Daily low price.
LowPrice float32 `json:"lowPrice"`
// Whether a quote is delayed (true) or real-time.
Delay int `json:"delay"`
// Whether trading in the symbol is currently halted.
IsHalted bool `json:"isHalted"`
}
// Candlestick represents historical market data in the form of OHLC candlesticks
// for a specified symbol.
type Candlestick struct {
// Candlestick start timestamp
Start time.Time `json:"start"`
// Candlestick end timestamp
End time.Time `json:"end"`
// Opening price.
Open float32 `json:"open"`
// High price.
High float32 `json:"high"`
// Low price.
Low float32 `json:"low"`
// Closing price.
Close float32 `json:"close"`
// Trading volume.
Volume int `json:"volume"`
}