1
- import axios , { AxiosRequestConfig , AxiosResponse } from 'axios' ;
1
+ import { AxiosRequestConfig , AxiosResponse , AxiosStatic } from 'axios' ;
2
2
3
3
import { TradierHistoryInterval , TradierSessionFilter , TradierTimeSalesInterval } from './tradier-market.models' ;
4
- import { TradierConfig } from '../tradier-config ' ;
4
+ import { TradierUtil } from '../tradier-util ' ;
5
5
6
6
interface TradierMarketEndpoints {
7
7
quotes : string ;
@@ -34,7 +34,8 @@ const endponts: TradierMarketEndpoints = {
34
34
export class TradierMarketClient {
35
35
36
36
public constructor (
37
- private readonly tradierConfig : TradierConfig ,
37
+ private readonly tradierUtil : TradierUtil ,
38
+ private readonly axios : AxiosStatic = axios ,
38
39
) { }
39
40
40
41
/**
@@ -43,12 +44,12 @@ export class TradierMarketClient {
43
44
* @param symbols Comma-delimited list of symbols (equity or option)
44
45
*/
45
46
public async getQuotes ( symbols : string [ ] ) {
46
- const url : string = this . tradierConfig . buildUrl ( endponts . quotes ) ;
47
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
47
+ const url : string = this . tradierUtil . buildUrl ( endponts . quotes ) ;
48
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
48
49
symbols : symbols . join ( ',' )
49
50
} ) ;
50
51
51
- const response : AxiosResponse = await axios . get ( url , config ) ;
52
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
52
53
return response . data ;
53
54
}
54
55
@@ -58,13 +59,13 @@ export class TradierMarketClient {
58
59
* @param expiration Expiration for the chain (format 2019-05-17)
59
60
*/
60
61
public async getOptionChains ( symbol : string , expiration : string ) {
61
- const url : string = this . tradierConfig . buildUrl ( endponts . option_chains ) ;
62
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
62
+ const url : string = this . tradierUtil . buildUrl ( endponts . option_chains ) ;
63
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
63
64
symbol,
64
65
expiration
65
66
} ) ;
66
67
67
- const response : AxiosResponse = await axios . get ( url , config ) ;
68
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
68
69
return response . data ;
69
70
}
70
71
@@ -74,13 +75,13 @@ export class TradierMarketClient {
74
75
* @param expiration Expiration for the chain (format 2019-05-17)
75
76
*/
76
77
public async getOptionStrikes ( symbol : string , expiration : string ) {
77
- const url : string = this . tradierConfig . buildUrl ( endponts . option_strikes ) ;
78
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
78
+ const url : string = this . tradierUtil . buildUrl ( endponts . option_strikes ) ;
79
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
79
80
symbol,
80
81
expiration
81
82
} ) ;
82
83
83
- const response : AxiosResponse = await axios . get ( url , config ) ;
84
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
84
85
return response . data ;
85
86
}
86
87
@@ -95,14 +96,14 @@ export class TradierMarketClient {
95
96
* @param strikes Add strike prices to each expiration
96
97
*/
97
98
public async getOptionExpirations ( symbol : string , includeAllRoots : boolean = false , strikes : boolean = false ) {
98
- const url : string = this . tradierConfig . buildUrl ( endponts . option_expirations ) ;
99
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
99
+ const url : string = this . tradierUtil . buildUrl ( endponts . option_expirations ) ;
100
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
100
101
symbol,
101
102
includeAllRoots,
102
103
strikes
103
104
} ) ;
104
105
105
- const response : AxiosResponse = await axios . get ( url , config ) ;
106
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
106
107
return response . data ;
107
108
}
108
109
@@ -115,15 +116,15 @@ export class TradierMarketClient {
115
116
* @param end End date represented as YYYY-MM-DD
116
117
*/
117
118
public async getHistoricalPricing ( symbol : string , interval ?: TradierHistoryInterval , start ?: string , end ?: string ) {
118
- const url : string = this . tradierConfig . buildUrl ( endponts . historical_quotes ) ;
119
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
119
+ const url : string = this . tradierUtil . buildUrl ( endponts . historical_quotes ) ;
120
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
120
121
symbol,
121
122
interval,
122
123
start,
123
124
end
124
125
} ) ;
125
126
126
- const response : AxiosResponse = await axios . get ( url , config ) ;
127
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
127
128
return response . data ;
128
129
}
129
130
@@ -141,16 +142,16 @@ export class TradierMarketClient {
141
142
public async getTimeAndSales (
142
143
symbol : string , interval ?: TradierTimeSalesInterval , start ?: string , end ?: string , session_filter ?: TradierSessionFilter ,
143
144
) {
144
- const url : string = this . tradierConfig . buildUrl ( endponts . time_and_sales ) ;
145
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
145
+ const url : string = this . tradierUtil . buildUrl ( endponts . time_and_sales ) ;
146
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
146
147
symbol,
147
148
interval,
148
149
start,
149
150
end,
150
151
session_filter
151
152
} ) ;
152
153
153
- const response : AxiosResponse = await axios . get ( url , config ) ;
154
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
154
155
return response . data ;
155
156
}
156
157
@@ -159,10 +160,10 @@ export class TradierMarketClient {
159
160
* The list is quite comprehensive and can result in a long download response time.
160
161
*/
161
162
public async getETBSecurities ( ) {
162
- const url : string = this . tradierConfig . buildUrl ( endponts . etb_securities ) ;
163
- const config : AxiosRequestConfig = this . tradierConfig . buildBaseConfig ( ) ;
163
+ const url : string = this . tradierUtil . buildUrl ( endponts . etb_securities ) ;
164
+ const config : AxiosRequestConfig = this . tradierUtil . buildBaseConfig ( ) ;
164
165
165
- const response : AxiosResponse = await axios . get ( url , config ) ;
166
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
166
167
return response . data ;
167
168
}
168
169
@@ -171,10 +172,10 @@ export class TradierMarketClient {
171
172
* If programming logic on whether the market is open/closed – this API call should be used to determine the current state.
172
173
*/
173
174
public async getClock ( ) {
174
- const url : string = this . tradierConfig . buildUrl ( endponts . clock ) ;
175
- const config : AxiosRequestConfig = this . tradierConfig . buildBaseConfig ( ) ;
175
+ const url : string = this . tradierUtil . buildUrl ( endponts . clock ) ;
176
+ const config : AxiosRequestConfig = this . tradierUtil . buildBaseConfig ( ) ;
176
177
177
- const response : AxiosResponse = await axios . get ( url , config ) ;
178
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
178
179
return response . data ;
179
180
}
180
181
@@ -185,13 +186,13 @@ export class TradierMarketClient {
185
186
* @param indexes Whether to include indexes in the results
186
187
*/
187
188
public async searchForCompanies ( q : string , indexes ?: boolean ) {
188
- const url : string = this . tradierConfig . buildUrl ( endponts . search_companies ) ;
189
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
189
+ const url : string = this . tradierUtil . buildUrl ( endponts . search_companies ) ;
190
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
190
191
q,
191
192
indexes,
192
193
} ) ;
193
194
194
- const response : AxiosResponse = await axios . get ( url , config ) ;
195
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
195
196
return response . data ;
196
197
}
197
198
@@ -204,14 +205,14 @@ export class TradierMarketClient {
204
205
* @param types Which security types to include in lookup
205
206
*/
206
207
public async searchForSymbols ( q : string , exchanges : string [ ] = [ ] , types ?: string ) {
207
- const url : string = this . tradierConfig . buildUrl ( endponts . lookup_symbol ) ;
208
- const config : AxiosRequestConfig = this . tradierConfig . buildConfigWithParams ( {
208
+ const url : string = this . tradierUtil . buildUrl ( endponts . lookup_symbol ) ;
209
+ const config : AxiosRequestConfig = this . tradierUtil . buildConfigWithParams ( {
209
210
q,
210
211
exchanges : exchanges . join ( ',' ) ,
211
212
types
212
213
} ) ;
213
214
214
- const response : AxiosResponse = await axios . get ( url , config ) ;
215
+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
215
216
return response . data ;
216
217
}
217
218
0 commit comments