3
3
TOKEN_ADDRESS , DATES
4
4
} from "./constants" ;
5
5
import { setUpPolly , isISOFormat , getNewWeb3DataInstance } from "./utils" ;
6
- import { ERROR_MESSAGE_MARKET_NO_PAIR as NO_PAIR , MARKET_FEATURES } from "../src/constants" ;
6
+ import { ERROR_MESSAGE_MARKET_NO_PAIR as NO_PAIR , MARKET_FEATURES } from "../src/constants" ;
7
7
8
8
/***********************************
9
9
* -------- Tests Setup ---------- *
@@ -42,7 +42,7 @@ test('Successfully gets market rankings', async t => {
42
42
} )
43
43
44
44
test ( 'Successfully gets market rankings - with filters' , async t => {
45
- const rankings = await t . context . web3data . market . getRankings ( { sortType : 'uniqueAddresses' } )
45
+ const rankings = await t . context . web3data . market . getRankings ( { sortType : 'uniqueAddresses' } )
46
46
t . true ( rankings . hasProp ( 'data' ) )
47
47
t . true ( Array . isArray ( rankings . data ) )
48
48
t . regex ( rankings . data [ 0 ] . changeInPriceDaily , / \d + \. ? \d * / )
@@ -52,7 +52,7 @@ test('Successfully gets market rankings - with filters', async t => {
52
52
test ( 'Successfully gets market features - all' , async t => {
53
53
const features = await t . context . web3data . market . getFeatures ( )
54
54
// Check each features name spacing
55
- MARKET_FEATURES . forEach ( feature => t . true ( features . hasProp ( feature ) ) )
55
+ MARKET_FEATURES . forEach ( feature => t . true ( features . hasProp ( feature ) ) )
56
56
} )
57
57
58
58
test ( 'Successfully gets market features - single string param' , async t => {
@@ -82,7 +82,7 @@ test('Successfully gets market features - array param', async t => {
82
82
} )
83
83
84
84
test ( 'Successfully gets market features - with filters' , async t => {
85
- const features = await t . context . web3data . market . getFeatures ( 'ohlcv' , { exchange : 'gdax' } )
85
+ const features = await t . context . web3data . market . getFeatures ( 'ohlcv' , { exchange : 'gdax' } )
86
86
t . true ( features . hasProp ( 'ohlcv' ) )
87
87
88
88
// Check that filtered exchange exists
@@ -100,23 +100,23 @@ test('Successfully gets latest ohlcv', async t => {
100
100
} )
101
101
102
102
test ( 'Successfully gets latest ohlcv - with filters' , async t => {
103
- const ohlcv = await t . context . web3data . market . getOhlcv ( 'eth_btc' , { exchange : 'bitfinex' } )
103
+ const ohlcv = await t . context . web3data . market . getOhlcv ( 'eth_btc' , { exchange : 'bitfinex' } )
104
104
t . is ( ohlcv . values ( ) . length , 1 )
105
105
t . true ( ohlcv . hasProp ( 'bitfinex' ) )
106
106
t . true ( ohlcv . bitfinex . hasProp ( 'open' ) )
107
107
t . regex ( ohlcv . bitfinex . open . toString ( ) , / \d + \. ? \d * / )
108
108
} )
109
109
110
110
test ( 'Successfully gets historical ohlcv' , async t => {
111
- const ohlcv = await t . context . web3data . market . getOhlcv ( 'eth_btc' , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
111
+ const ohlcv = await t . context . web3data . market . getOhlcv ( 'eth_btc' , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
112
112
t . true ( ohlcv . hasProp ( 'metadata' ) )
113
113
t . regex ( Object . values ( ohlcv . data ) [ 0 ] . toString ( ) , / \d + \. ? \d * / )
114
114
} )
115
115
116
116
test ( 'throws exception when calling getOhlcv without pair param' , async t => {
117
117
await t . throwsAsync ( async ( ) => {
118
118
await t . context . web3data . market . getOrders ( )
119
- } , { instanceOf : Error , message : NO_PAIR } )
119
+ } , { instanceOf : Error , message : NO_PAIR } )
120
120
} )
121
121
122
122
/*********** Test getOrders() ***********/
@@ -147,13 +147,13 @@ test('Successfully gets orders - with filters', async t => {
147
147
test ( 'throws exception when calling getOrders without pair param' , async t => {
148
148
await t . throwsAsync ( async ( ) => {
149
149
await t . context . web3data . market . getOrders ( )
150
- } , { instanceOf : Error , message : NO_PAIR } )
150
+ } , { instanceOf : Error , message : NO_PAIR } )
151
151
} )
152
152
153
153
test ( 'throws exception when calling getOrders without exchange param' , async t => {
154
154
await t . throwsAsync ( async ( ) => {
155
155
await t . context . web3data . market . getOrders ( 'eth_btc' )
156
- } , { instanceOf : Error , message : 'No exchange specified' } )
156
+ } , { instanceOf : Error , message : 'No exchange specified' } )
157
157
} )
158
158
159
159
/*********** Test getBbos() ***********/
@@ -164,7 +164,7 @@ test.skip('Successfully gets latest bbos', async t => {
164
164
t . true ( exchangePairBbo . hasProp ( 'price' ) )
165
165
} )
166
166
test ( 'Successfully gets historical bbos' , async t => {
167
- const bbos = await t . context . web3data . market . getBbos ( 'eth_btc' , { startDate : 1583708400000 , endDate : 1583712000000 } )
167
+ const bbos = await t . context . web3data . market . getBbos ( 'eth_btc' , { startDate : 1583708400000 , endDate : 1583712000000 } )
168
168
169
169
// Check existence of historical data properties
170
170
t . true ( bbos . hasProp ( 'metadata' ) )
@@ -175,44 +175,42 @@ test('Successfully gets historical bbos', async t => {
175
175
test ( 'throws exception when calling getBbos without pair param' , async t => {
176
176
await t . throwsAsync ( async ( ) => {
177
177
await t . context . web3data . market . getBbos ( )
178
- } , { instanceOf : Error , message : NO_PAIR } )
178
+ } , { instanceOf : Error , message : NO_PAIR } )
179
179
} )
180
180
181
181
/*********** Test getPrices() ***********/
182
182
const BASE = 'eth'
183
183
test ( 'Successfully gets latest market prices' , async t => {
184
- const prices = await t . context . web3data . market . getPrices ( BASE )
184
+ const prices = await t . context . web3data . market . getPrices ( `${ BASE } _usd` )
185
+ t . true ( prices . hasProp ( 'price' ) )
186
+ t . true ( prices . hasProp ( 'volume' ) )
185
187
186
188
// Test the there is a price property that has a float value
187
- t . true ( Array . isArray ( prices . values ( ) ) )
188
- t . true ( prices . values ( ) [ 0 ] . hasProp ( 'price' ) )
189
- t . regex ( prices . values ( ) [ 0 ] . price . toString ( ) , / \d + \. ? \d * / )
189
+ t . regex ( prices . price . toString ( ) , / \d + \. ? \d * / )
190
190
} )
191
191
192
192
test ( 'Successfully gets latest market prices - with filters' , async t => {
193
- const prices = await t . context . web3data . market . getPrices ( BASE , { quote : 'eur' } )
194
- t . true ( prices . hasProp ( 'eth_eur' ) )
195
- t . true ( Array . isArray ( Object . values ( prices ) ) )
196
- t . true ( Object . values ( prices ) [ 0 ] . hasProp ( 'price' ) )
193
+ const prices = await t . context . web3data . market . getPrices ( `${ BASE } _eur` )
194
+ t . true ( prices . hasProp ( 'price' ) )
195
+ t . true ( prices . hasProp ( 'volume' ) )
197
196
198
197
// Test the there is a price property that has a float value
199
- t . regex ( Object . values ( prices ) [ 0 ] . price . toString ( ) , / \d + \. ? \d * / )
198
+ t . regex ( prices . price . toString ( ) , / \d + \. ? \d * / )
200
199
} )
201
200
202
201
test ( 'Successfully gets historical market prices' , async t => {
203
- const prices = await t . context . web3data . market . getPrices ( BASE , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
204
- t . true ( prices . hasProp ( 'eth_usd' ) )
205
- t . true ( Array . isArray ( prices . eth_usd ) )
206
- t . true ( prices . values ( ) [ 0 ] [ 0 ] . hasProp ( 'price' ) )
202
+ const prices = await t . context . web3data . market . getPrices ( `${ BASE } _usd` , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
203
+ t . true ( Array . isArray ( prices . data ) )
204
+ t . true ( prices . data [ 0 ] . hasProp ( 'price' ) )
207
205
208
206
// Test there is a price property that has a float value
209
- t . regex ( prices . values ( ) [ 0 ] [ 0 ] . price . toString ( ) , / \d + \. ? \d * / )
207
+ t . regex ( prices . data [ 0 ] . price . toString ( ) , / \d + \. ? \d * / )
210
208
} )
211
209
212
210
test ( 'throws exception when calling getPrices without base param' , async t => {
213
211
await t . throwsAsync ( async ( ) => {
214
212
await t . context . web3data . market . getPrices ( )
215
- } , { instanceOf : Error , message : NO_PAIR } )
213
+ } , { instanceOf : Error , message : NO_PAIR } )
216
214
} )
217
215
218
216
/*********** Test getTokenPrices() ***********/
@@ -223,7 +221,7 @@ test('Successfully gets current token price', async t => {
223
221
} )
224
222
225
223
test ( 'Successfully gets historical token price' , async t => {
226
- const tokenPrices = await t . context . web3data . market . getTokenPrices ( TOKEN_ADDRESS , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
224
+ const tokenPrices = await t . context . web3data . market . getTokenPrices ( TOKEN_ADDRESS , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
227
225
t . true ( tokenPrices . hasProp ( 'metadata' ) )
228
226
t . true ( tokenPrices . hasProp ( 'data' ) )
229
227
t . true ( tokenPrices . metadata . columns . includes ( 'priceUSD' ) )
@@ -232,7 +230,7 @@ test('Successfully gets historical token price', async t => {
232
230
test ( 'throws exception when calling getTokenPrices without pair param' , async t => {
233
231
await t . throwsAsync ( async ( ) => {
234
232
await t . context . web3data . market . getTokenPrices ( )
235
- } , { instanceOf : Error , message : NO_PAIR } )
233
+ } , { instanceOf : Error , message : NO_PAIR } )
236
234
} )
237
235
238
236
/*********** Test getVwap() ***********/
@@ -243,7 +241,7 @@ test('Successfully gets current vwap prices', async t => {
243
241
} )
244
242
245
243
test ( 'Successfully gets current vwap prices - with filters' , async t => {
246
- const vwap = await t . context . web3data . market . getVwap ( 'eth' , { quote : 'usd' } )
244
+ const vwap = await t . context . web3data . market . getVwap ( 'eth' , { quote : 'usd' } )
247
245
248
246
// check that it returns data for a single pair
249
247
t . is ( Object . keys ( vwap ) . length , 1 )
@@ -254,7 +252,7 @@ test('Successfully gets current vwap prices - with filters', async t => {
254
252
test ( 'throws exception when calling getVwap without base param' , async t => {
255
253
await t . throwsAsync ( async ( ) => {
256
254
await t . context . web3data . market . getVwap ( )
257
- } , { instanceOf : Error , message : NO_PAIR } )
255
+ } , { instanceOf : Error , message : NO_PAIR } )
258
256
} )
259
257
260
258
/*********** Test getTickers() ***********/
@@ -265,15 +263,15 @@ test('Successfully gets latest market tickers', async t => {
265
263
} )
266
264
267
265
test ( 'Successfully gets latest market tickers - with filters' , async t => {
268
- const tickers = await t . context . web3data . market . getTickers ( 'eth_btc' , { exchange : 'gdax' } )
266
+ const tickers = await t . context . web3data . market . getTickers ( 'eth_btc' , { exchange : 'gdax' } )
269
267
// check that it returns data for a single exchange
270
268
t . is ( Object . keys ( tickers ) . length , 1 )
271
269
t . true ( tickers . hasProp ( 'gdax' ) )
272
270
t . true ( tickers . gdax . hasProp ( 'bid' ) )
273
271
} )
274
272
275
273
test ( 'Successfully gets historical market tickers' , async t => {
276
- const tickers = await t . context . web3data . market . getTickers ( 'eth_btc' , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
274
+ const tickers = await t . context . web3data . market . getTickers ( 'eth_btc' , { startDate : DATES [ "2019-10-14" ] , endDate : DATES [ "2019-10-15" ] } )
277
275
t . true ( tickers . hasProp ( 'metadata' ) )
278
276
t . true ( tickers . hasProp ( 'data' ) )
279
277
t . true ( tickers . metadata . columns . includes ( 'bid' ) )
@@ -282,7 +280,7 @@ test('Successfully gets historical market tickers', async t => {
282
280
test ( 'throws exception when calling getTickers without pair param' , async t => {
283
281
await t . throwsAsync ( async ( ) => {
284
282
await t . context . web3data . market . getTickers ( )
285
- } , { instanceOf : Error , message : NO_PAIR } )
283
+ } , { instanceOf : Error , message : NO_PAIR } )
286
284
} )
287
285
288
286
/*********** Test getTrades() ***********/
@@ -294,7 +292,7 @@ test('Successfully gets market trades', async t => {
294
292
} )
295
293
296
294
test ( 'Successfully gets market trades - with filters' , async t => {
297
- const trades = await t . context . web3data . market . getTrades ( 'eth_usd' , { exchange : 'bitstamp' } )
295
+ const trades = await t . context . web3data . market . getTrades ( 'eth_usd' , { exchange : 'bitstamp' } )
298
296
t . true ( trades . hasProp ( 'metadata' ) )
299
297
t . true ( trades . hasProp ( 'data' ) )
300
298
t . true ( trades . data [ 0 ] . includes ( 'bitstamp' ) )
@@ -303,19 +301,19 @@ test('Successfully gets market trades - with filters', async t => {
303
301
test ( 'throws exception when calling getTrades without pair param' , async t => {
304
302
await t . throwsAsync ( async ( ) => {
305
303
await t . context . web3data . market . getTrades ( )
306
- } , { instanceOf : Error , message : NO_PAIR } )
304
+ } , { instanceOf : Error , message : NO_PAIR } )
307
305
} )
308
306
309
307
/*********** Test getOrderBooks() ***********/
310
308
test ( 'Successfully gets order book updates' , async t => {
311
- const orderBooks = await t . context . web3data . market . getOrderBooks ( 'btc_usd' , { exchange : 'gdax' } )
309
+ const orderBooks = await t . context . web3data . market . getOrderBooks ( 'btc_usd' , { exchange : 'gdax' } )
312
310
t . true ( orderBooks . hasProp ( 'data' ) )
313
311
t . true ( orderBooks . hasProp ( 'metadata' ) )
314
312
t . true ( orderBooks . metadata . columns . includes ( 'numOrders' ) )
315
313
} )
316
314
317
315
test ( 'Successfully gets order book updates - with filters' , async t => {
318
- const orderBooks = await t . context . web3data . market . getOrderBooks ( 'btc_usd' , { exchange : 'gdax' } )
316
+ const orderBooks = await t . context . web3data . market . getOrderBooks ( 'btc_usd' , { exchange : 'gdax' } )
319
317
t . true ( orderBooks . hasProp ( 'data' ) )
320
318
t . true ( orderBooks . hasProp ( 'metadata' ) )
321
319
t . true ( orderBooks . metadata . columns . includes ( 'numOrders' ) )
0 commit comments