33 TOKEN_ADDRESS , DATES
44} from "./constants" ;
55import { 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" ;
77
88/***********************************
99 * -------- Tests Setup ---------- *
@@ -42,7 +42,7 @@ test('Successfully gets market rankings', async t => {
4242} )
4343
4444test ( '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' } )
4646 t . true ( rankings . hasProp ( 'data' ) )
4747 t . true ( Array . isArray ( rankings . data ) )
4848 t . regex ( rankings . data [ 0 ] . changeInPriceDaily , / \d + \. ? \d * / )
@@ -52,7 +52,7 @@ test('Successfully gets market rankings - with filters', async t => {
5252test ( 'Successfully gets market features - all' , async t => {
5353 const features = await t . context . web3data . market . getFeatures ( )
5454 // 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 ) ) )
5656} )
5757
5858test ( 'Successfully gets market features - single string param' , async t => {
@@ -82,7 +82,7 @@ test('Successfully gets market features - array param', async t => {
8282} )
8383
8484test ( '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' } )
8686 t . true ( features . hasProp ( 'ohlcv' ) )
8787
8888 // Check that filtered exchange exists
@@ -100,23 +100,23 @@ test('Successfully gets latest ohlcv', async t => {
100100} )
101101
102102test ( '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' } )
104104 t . is ( ohlcv . values ( ) . length , 1 )
105105 t . true ( ohlcv . hasProp ( 'bitfinex' ) )
106106 t . true ( ohlcv . bitfinex . hasProp ( 'open' ) )
107107 t . regex ( ohlcv . bitfinex . open . toString ( ) , / \d + \. ? \d * / )
108108} )
109109
110110test ( '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" ] } )
112112 t . true ( ohlcv . hasProp ( 'metadata' ) )
113113 t . regex ( Object . values ( ohlcv . data ) [ 0 ] . toString ( ) , / \d + \. ? \d * / )
114114} )
115115
116116test ( 'throws exception when calling getOhlcv without pair param' , async t => {
117117 await t . throwsAsync ( async ( ) => {
118118 await t . context . web3data . market . getOrders ( )
119- } , { instanceOf : Error , message : NO_PAIR } )
119+ } , { instanceOf : Error , message : NO_PAIR } )
120120} )
121121
122122/*********** Test getOrders() ***********/
@@ -147,13 +147,13 @@ test('Successfully gets orders - with filters', async t => {
147147test ( 'throws exception when calling getOrders without pair param' , async t => {
148148 await t . throwsAsync ( async ( ) => {
149149 await t . context . web3data . market . getOrders ( )
150- } , { instanceOf : Error , message : NO_PAIR } )
150+ } , { instanceOf : Error , message : NO_PAIR } )
151151} )
152152
153153test ( 'throws exception when calling getOrders without exchange param' , async t => {
154154 await t . throwsAsync ( async ( ) => {
155155 await t . context . web3data . market . getOrders ( 'eth_btc' )
156- } , { instanceOf : Error , message : 'No exchange specified' } )
156+ } , { instanceOf : Error , message : 'No exchange specified' } )
157157} )
158158
159159/*********** Test getBbos() ***********/
@@ -164,7 +164,7 @@ test.skip('Successfully gets latest bbos', async t => {
164164 t . true ( exchangePairBbo . hasProp ( 'price' ) )
165165} )
166166test ( '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 } )
168168
169169 // Check existence of historical data properties
170170 t . true ( bbos . hasProp ( 'metadata' ) )
@@ -175,44 +175,42 @@ test('Successfully gets historical bbos', async t => {
175175test ( 'throws exception when calling getBbos without pair param' , async t => {
176176 await t . throwsAsync ( async ( ) => {
177177 await t . context . web3data . market . getBbos ( )
178- } , { instanceOf : Error , message : NO_PAIR } )
178+ } , { instanceOf : Error , message : NO_PAIR } )
179179} )
180180
181181/*********** Test getPrices() ***********/
182182const BASE = 'eth'
183183test ( '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' ) )
185187
186188 // 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 * / )
190190} )
191191
192192test ( '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' ) )
197196
198197 // 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 * / )
200199} )
201200
202201test ( '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' ) )
207205
208206 // 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 * / )
210208} )
211209
212210test ( 'throws exception when calling getPrices without base param' , async t => {
213211 await t . throwsAsync ( async ( ) => {
214212 await t . context . web3data . market . getPrices ( )
215- } , { instanceOf : Error , message : NO_PAIR } )
213+ } , { instanceOf : Error , message : NO_PAIR } )
216214} )
217215
218216/*********** Test getTokenPrices() ***********/
@@ -223,7 +221,7 @@ test('Successfully gets current token price', async t => {
223221} )
224222
225223test ( '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" ] } )
227225 t . true ( tokenPrices . hasProp ( 'metadata' ) )
228226 t . true ( tokenPrices . hasProp ( 'data' ) )
229227 t . true ( tokenPrices . metadata . columns . includes ( 'priceUSD' ) )
@@ -232,7 +230,7 @@ test('Successfully gets historical token price', async t => {
232230test ( 'throws exception when calling getTokenPrices without pair param' , async t => {
233231 await t . throwsAsync ( async ( ) => {
234232 await t . context . web3data . market . getTokenPrices ( )
235- } , { instanceOf : Error , message : NO_PAIR } )
233+ } , { instanceOf : Error , message : NO_PAIR } )
236234} )
237235
238236/*********** Test getVwap() ***********/
@@ -243,7 +241,7 @@ test('Successfully gets current vwap prices', async t => {
243241} )
244242
245243test ( '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' } )
247245
248246 // check that it returns data for a single pair
249247 t . is ( Object . keys ( vwap ) . length , 1 )
@@ -254,7 +252,7 @@ test('Successfully gets current vwap prices - with filters', async t => {
254252test ( 'throws exception when calling getVwap without base param' , async t => {
255253 await t . throwsAsync ( async ( ) => {
256254 await t . context . web3data . market . getVwap ( )
257- } , { instanceOf : Error , message : NO_PAIR } )
255+ } , { instanceOf : Error , message : NO_PAIR } )
258256} )
259257
260258/*********** Test getTickers() ***********/
@@ -265,15 +263,15 @@ test('Successfully gets latest market tickers', async t => {
265263} )
266264
267265test ( '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' } )
269267 // check that it returns data for a single exchange
270268 t . is ( Object . keys ( tickers ) . length , 1 )
271269 t . true ( tickers . hasProp ( 'gdax' ) )
272270 t . true ( tickers . gdax . hasProp ( 'bid' ) )
273271} )
274272
275273test ( '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" ] } )
277275 t . true ( tickers . hasProp ( 'metadata' ) )
278276 t . true ( tickers . hasProp ( 'data' ) )
279277 t . true ( tickers . metadata . columns . includes ( 'bid' ) )
@@ -282,7 +280,7 @@ test('Successfully gets historical market tickers', async t => {
282280test ( 'throws exception when calling getTickers without pair param' , async t => {
283281 await t . throwsAsync ( async ( ) => {
284282 await t . context . web3data . market . getTickers ( )
285- } , { instanceOf : Error , message : NO_PAIR } )
283+ } , { instanceOf : Error , message : NO_PAIR } )
286284} )
287285
288286/*********** Test getTrades() ***********/
@@ -294,7 +292,7 @@ test('Successfully gets market trades', async t => {
294292} )
295293
296294test ( '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' } )
298296 t . true ( trades . hasProp ( 'metadata' ) )
299297 t . true ( trades . hasProp ( 'data' ) )
300298 t . true ( trades . data [ 0 ] . includes ( 'bitstamp' ) )
@@ -303,19 +301,19 @@ test('Successfully gets market trades - with filters', async t => {
303301test ( 'throws exception when calling getTrades without pair param' , async t => {
304302 await t . throwsAsync ( async ( ) => {
305303 await t . context . web3data . market . getTrades ( )
306- } , { instanceOf : Error , message : NO_PAIR } )
304+ } , { instanceOf : Error , message : NO_PAIR } )
307305} )
308306
309307/*********** Test getOrderBooks() ***********/
310308test ( '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' } )
312310 t . true ( orderBooks . hasProp ( 'data' ) )
313311 t . true ( orderBooks . hasProp ( 'metadata' ) )
314312 t . true ( orderBooks . metadata . columns . includes ( 'numOrders' ) )
315313} )
316314
317315test ( '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' } )
319317 t . true ( orderBooks . hasProp ( 'data' ) )
320318 t . true ( orderBooks . hasProp ( 'metadata' ) )
321319 t . true ( orderBooks . metadata . columns . includes ( 'numOrders' ) )
0 commit comments