1- import axios , { AxiosRequestConfig , AxiosResponse } from 'axios' ;
1+ import { AxiosRequestConfig , AxiosResponse , AxiosStatic } from 'axios' ;
22
33import { TradierHistoryInterval , TradierSessionFilter , TradierTimeSalesInterval } from './tradier-market.models' ;
4- import { TradierConfig } from '../tradier-config ' ;
4+ import { TradierUtil } from '../tradier-util ' ;
55
66interface TradierMarketEndpoints {
77 quotes : string ;
@@ -34,7 +34,8 @@ const endponts: TradierMarketEndpoints = {
3434export class TradierMarketClient {
3535
3636 public constructor (
37- private readonly tradierConfig : TradierConfig ,
37+ private readonly tradierUtil : TradierUtil ,
38+ private readonly axios : AxiosStatic = axios ,
3839 ) { }
3940
4041 /**
@@ -43,12 +44,12 @@ export class TradierMarketClient {
4344 * @param symbols Comma-delimited list of symbols (equity or option)
4445 */
4546 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 ( {
4849 symbols : symbols . join ( ',' )
4950 } ) ;
5051
51- const response : AxiosResponse = await axios . get ( url , config ) ;
52+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
5253 return response . data ;
5354 }
5455
@@ -58,13 +59,13 @@ export class TradierMarketClient {
5859 * @param expiration Expiration for the chain (format 2019-05-17)
5960 */
6061 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 ( {
6364 symbol,
6465 expiration
6566 } ) ;
6667
67- const response : AxiosResponse = await axios . get ( url , config ) ;
68+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
6869 return response . data ;
6970 }
7071
@@ -74,13 +75,13 @@ export class TradierMarketClient {
7475 * @param expiration Expiration for the chain (format 2019-05-17)
7576 */
7677 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 ( {
7980 symbol,
8081 expiration
8182 } ) ;
8283
83- const response : AxiosResponse = await axios . get ( url , config ) ;
84+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
8485 return response . data ;
8586 }
8687
@@ -95,14 +96,14 @@ export class TradierMarketClient {
9596 * @param strikes Add strike prices to each expiration
9697 */
9798 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 ( {
100101 symbol,
101102 includeAllRoots,
102103 strikes
103104 } ) ;
104105
105- const response : AxiosResponse = await axios . get ( url , config ) ;
106+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
106107 return response . data ;
107108 }
108109
@@ -115,15 +116,15 @@ export class TradierMarketClient {
115116 * @param end End date represented as YYYY-MM-DD
116117 */
117118 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 ( {
120121 symbol,
121122 interval,
122123 start,
123124 end
124125 } ) ;
125126
126- const response : AxiosResponse = await axios . get ( url , config ) ;
127+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
127128 return response . data ;
128129 }
129130
@@ -141,16 +142,16 @@ export class TradierMarketClient {
141142 public async getTimeAndSales (
142143 symbol : string , interval ?: TradierTimeSalesInterval , start ?: string , end ?: string , session_filter ?: TradierSessionFilter ,
143144 ) {
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 ( {
146147 symbol,
147148 interval,
148149 start,
149150 end,
150151 session_filter
151152 } ) ;
152153
153- const response : AxiosResponse = await axios . get ( url , config ) ;
154+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
154155 return response . data ;
155156 }
156157
@@ -159,10 +160,10 @@ export class TradierMarketClient {
159160 * The list is quite comprehensive and can result in a long download response time.
160161 */
161162 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 ( ) ;
164165
165- const response : AxiosResponse = await axios . get ( url , config ) ;
166+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
166167 return response . data ;
167168 }
168169
@@ -171,10 +172,10 @@ export class TradierMarketClient {
171172 * If programming logic on whether the market is open/closed – this API call should be used to determine the current state.
172173 */
173174 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 ( ) ;
176177
177- const response : AxiosResponse = await axios . get ( url , config ) ;
178+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
178179 return response . data ;
179180 }
180181
@@ -185,13 +186,13 @@ export class TradierMarketClient {
185186 * @param indexes Whether to include indexes in the results
186187 */
187188 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 ( {
190191 q,
191192 indexes,
192193 } ) ;
193194
194- const response : AxiosResponse = await axios . get ( url , config ) ;
195+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
195196 return response . data ;
196197 }
197198
@@ -204,14 +205,14 @@ export class TradierMarketClient {
204205 * @param types Which security types to include in lookup
205206 */
206207 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 ( {
209210 q,
210211 exchanges : exchanges . join ( ',' ) ,
211212 types
212213 } ) ;
213214
214- const response : AxiosResponse = await axios . get ( url , config ) ;
215+ const response : AxiosResponse = await this . axios . get ( url , config ) ;
215216 return response . data ;
216217 }
217218
0 commit comments