@@ -104,7 +104,10 @@ describe('orderbook-mid-prices-cache', () => {
104
104
describe ( 'getMedianPrice' , ( ) => {
105
105
106
106
it ( 'returns null when no prices are set' , async ( ) => {
107
- const result = await getMedianPrices ( client , [ defaultTicker ] ) ;
107
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
108
+ client ,
109
+ [ defaultTicker ] ,
110
+ ) ;
108
111
expect ( result ) . toEqual ( { 'BTC-USD' : undefined } ) ;
109
112
} ) ;
110
113
@@ -113,7 +116,10 @@ describe('orderbook-mid-prices-cache', () => {
113
116
setPrice ( defaultTicker , '50000' ) ;
114
117
setPrice ( defaultTicker , '49000' ) ;
115
118
116
- const result = await getMedianPrices ( client , [ defaultTicker ] ) ;
119
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
120
+ client ,
121
+ [ defaultTicker ] ,
122
+ ) ;
117
123
expect ( result ) . toEqual ( { 'BTC-USD' : '50000' } ) ;
118
124
} ) ;
119
125
@@ -123,14 +129,17 @@ describe('orderbook-mid-prices-cache', () => {
123
129
setPrice ( defaultTicker , '49000' ) ;
124
130
setPrice ( defaultTicker , '52000' ) ;
125
131
126
- const result = await getMedianPrices ( client , [ defaultTicker ] ) ;
132
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
133
+ client ,
134
+ [ defaultTicker ] ,
135
+ ) ;
127
136
expect ( result ) . toEqual ( { 'BTC-USD' : '50500' } ) ;
128
137
} ) ;
129
138
130
139
it ( 'returns the correct median price after 30 seconds' , async ( ) => {
131
140
jest . useFakeTimers ( ) ;
132
141
// Mock the getOrderBookMidPrice function for the ticker
133
- const mockPrices = [ '50000' , '51000' , '49000' , '48000' , '52000' , '53000' ] ;
142
+ const mockPrices : string [ ] = [ '50000' , '51000' , '49000' , '48000' , '52000' , '53000' ] ;
134
143
135
144
( OrderbookLevelsCache . getOrderBookMidPrice as jest . Mock )
136
145
. mockResolvedValueOnce ( mockPrices [ 0 ] )
@@ -160,7 +169,10 @@ describe('orderbook-mid-prices-cache', () => {
160
169
expect ( OrderbookLevelsCache . getOrderBookMidPrice ) . toHaveBeenCalledTimes ( 6 ) ;
161
170
162
171
// Check the median price
163
- const result = await getMedianPrices ( client , [ defaultTicker ] ) ;
172
+ const result :{ [ ticker : string ] : string | undefined } = await getMedianPrices (
173
+ client ,
174
+ [ defaultTicker ] ,
175
+ ) ;
164
176
// Median of last 4 prices, as first two should have expired after moving clock forward
165
177
expect ( result ) . toEqual ( { 'BTC-USD' : '50500' } ) ;
166
178
@@ -171,7 +183,10 @@ describe('orderbook-mid-prices-cache', () => {
171
183
setPrice ( defaultTicker , '0.00000000002345' ) ;
172
184
setPrice ( defaultTicker , '0.00000000002346' ) ;
173
185
174
- const midPrice1 = await getMedianPrices ( client , [ defaultTicker ] ) ;
186
+ const midPrice1 : { [ ticker : string ] : string | undefined } = await getMedianPrices (
187
+ client ,
188
+ [ defaultTicker ] ,
189
+ ) ;
175
190
expect ( midPrice1 ) . toEqual ( { 'BTC-USD' : '0.000000000023455' } ) ;
176
191
} ) ;
177
192
@@ -182,7 +197,10 @@ describe('orderbook-mid-prices-cache', () => {
182
197
setPrice ( defaultTicker , '0.00000000004' ) ;
183
198
setPrice ( defaultTicker , '0.00000000005' ) ;
184
199
185
- const midPrice1 = await getMedianPrices ( client , [ defaultTicker ] ) ;
200
+ const midPrice1 : { [ ticker : string ] : string | undefined } = await getMedianPrices (
201
+ client ,
202
+ [ defaultTicker ] ,
203
+ ) ;
186
204
expect ( midPrice1 ) . toEqual ( { 'BTC-USD' : '0.00000000003' } ) ;
187
205
188
206
await deleteAllAsync ( client ) ;
@@ -191,7 +209,10 @@ describe('orderbook-mid-prices-cache', () => {
191
209
setPrice ( defaultTicker , '0.00000847006' ) ;
192
210
setPrice ( defaultTicker , '0.00000847008' ) ;
193
211
194
- const midPrice2 = await getMedianPrices ( client , [ defaultTicker ] ) ;
212
+ const midPrice2 : { [ ticker : string ] : string | undefined } = await getMedianPrices (
213
+ client ,
214
+ [ defaultTicker ] ,
215
+ ) ;
195
216
expect ( midPrice2 ) . toEqual ( { 'BTC-USD' : '0.00000847007' } ) ;
196
217
} ) ;
197
218
} ) ;
@@ -221,7 +242,10 @@ describe('orderbook-mid-prices-cache', () => {
221
242
setPrice ( solUsdTicker , '102' ) ;
222
243
setPrice ( solUsdTicker , '98' ) ;
223
244
224
- const result = await getMedianPrices ( client , [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ) ;
245
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
246
+ client ,
247
+ [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ,
248
+ ) ;
225
249
expect ( result ) . toEqual ( {
226
250
'BTC-USD' : '50000' ,
227
251
'ETH-USD' : '3000' ,
@@ -242,7 +266,10 @@ describe('orderbook-mid-prices-cache', () => {
242
266
setPrice ( ethUsdTicker , '2900' ) ;
243
267
setPrice ( ethUsdTicker , '3200' ) ;
244
268
245
- const result = await getMedianPrices ( client , [ btcUsdTicker , ethUsdTicker ] ) ;
269
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
270
+ client ,
271
+ [ btcUsdTicker , ethUsdTicker ] ,
272
+ ) ;
246
273
expect ( result ) . toEqual ( {
247
274
'BTC-USD' : '50500' ,
248
275
'ETH-USD' : '3050' ,
@@ -263,7 +290,10 @@ describe('orderbook-mid-prices-cache', () => {
263
290
264
291
// Set no prices for SOL-USD
265
292
266
- const result = await getMedianPrices ( client , [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ) ;
293
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
294
+ client ,
295
+ [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ,
296
+ ) ;
267
297
expect ( result ) . toEqual ( {
268
298
'BTC-USD' : '50000' ,
269
299
'ETH-USD' : '3050' ,
@@ -287,7 +317,10 @@ describe('orderbook-mid-prices-cache', () => {
287
317
setPrice ( solUsdTicker , '0.00000125' ) ;
288
318
setPrice ( solUsdTicker , '0.00000126' ) ;
289
319
290
- const result = await getMedianPrices ( client , [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ) ;
320
+ const result : { [ ticker : string ] : string | undefined } = await getMedianPrices (
321
+ client ,
322
+ [ btcUsdTicker , ethUsdTicker , solUsdTicker ] ,
323
+ ) ;
291
324
expect ( result ) . toEqual ( {
292
325
'BTC-USD' : '50000.123455' ,
293
326
'ETH-USD' : '3000.6' ,
0 commit comments