Skip to content

Commit dcd9a4a

Browse files
Merge pull request #99 from web3data/hf/price-endpoints
Hf/price endpoints
2 parents df86a78 + c03df14 commit dcd9a4a

File tree

9 files changed

+31950
-9295
lines changed

9 files changed

+31950
-9295
lines changed

dist/web3data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 287 additions & 286 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 30726 additions & 8065 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3data-js",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "A javascript wrapper for accessing amberdata's public API.",
55
"main": "index.js",
66
"browser": "dist/web3data.min.js",
@@ -59,8 +59,6 @@
5959
"docsify-cli": "^4.4.0",
6060
"dotenv": "^8.2.0",
6161
"doxdox": "^3.0.0",
62-
"doxdox-parser-dox": "github:taylorjdawson/doxdox-parser-dox",
63-
"doxdox-plugin-markdown": "taylorjdawson/doxdox-plugin-markdown",
6462
"eslint-plugin-jsdoc": "^24.0.0",
6563
"get-port": "^5.1.1",
6664
"husky": "^4.2.5",

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports.ERROR_MESSAGE_CONTRACT_NO_ADDRESS =
4545
'No contract address supplied'
4646
module.exports.ERROR_MESSAGE_BLOCK_NO_ID = 'No block number or hash supplied'
4747
module.exports.ERROR_MESSAGE_MARKET_NO_PAIR = 'No market pair supplied'
48+
module.exports.ERROR_MESSAGE_MARKET_NO_BASE = 'No market base supplied'
4849
module.exports.ERROR_MESSAGE_MARKET_NO_FEATURE = `Missing or unknown. Features: '${module.exports.MARKET_FEATURES.join(
4950
"', '"
5051
)}'`

src/market.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class Market {
2929
*/
3030
async getEtherPrice() {
3131
return get(this.web3data, {
32-
endpoint: ENDPOINT + '/prices/eth/latest'
33-
}).then((response) => response.payload.eth_usd.price, onError)
32+
endpoint: ENDPOINT + '/spot/prices/pairs/eth_usd/latest'
33+
}).then((response) => response.payload.price, onError)
3434
}
3535

3636
/**
@@ -210,6 +210,7 @@ class Market {
210210
* Retrieves the historical prices for the specified asset.
211211
*
212212
* @param base - The base of a pair to retrieve the price. Example: If pair is "eth_usd", then base is "eth".
213+
* @param pair
213214
* @param [filterOptions] - The filter options. See [docs](https://docs.amberdata.io/reference#market-prices-latest) for more details.
214215
* @returns The latest or historical market prices indexed by pair.
215216
* @example // Latest
@@ -218,13 +219,13 @@ class Market {
218219
* // Historical (1 day ago)
219220
* const histPrices = await web3data.market.getPrices('eth', {startDate: Math.round((Date.now() - 86400000) /1000)})
220221
*/
221-
getPrices(base, filterOptions = {}) {
222-
throwIf(is.undefined(base), NO_MARKET_PAIR)
222+
getPrices(pair, filterOptions = {}) {
223+
throwIf(is.undefined(pair), NO_MARKET_PAIR)
223224
const subendpoint =
224225
filterOptions.startDate || filterOptions.endDate ? 'historical' : 'latest'
225226
return get(this.web3data, {
226-
pathParam: base,
227-
endpoint: `${ENDPOINT}/prices`,
227+
pathParam: pair,
228+
endpoint: `${ENDPOINT}/spot/prices/pairs`,
228229
subendpoint,
229230
filterOptions
230231
}).then(onFulfilled, onError)

test/market.test.js

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
TOKEN_ADDRESS, DATES
44
} from "./constants";
55
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";
77

88
/***********************************
99
* -------- Tests Setup ---------- *
@@ -42,7 +42,7 @@ test('Successfully gets market rankings', async t => {
4242
})
4343

4444
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' })
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 => {
5252
test('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

5858
test('Successfully gets market features - single string param', async t => {
@@ -82,7 +82,7 @@ test('Successfully gets market features - array param', async t => {
8282
})
8383

8484
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' })
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

102102
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' })
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

110110
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"] })
112112
t.true(ohlcv.hasProp('metadata'))
113113
t.regex(Object.values(ohlcv.data)[0].toString(), /\d+\.?\d*/)
114114
})
115115

116116
test('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 => {
147147
test('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

153153
test('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
})
166166
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 })
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 => {
175175
test('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() ***********/
182182
const BASE = 'eth'
183183
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'))
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

192192
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'))
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

202201
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'))
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

212210
test('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

225223
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"] })
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 => {
232230
test('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

245243
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' })
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 => {
254252
test('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

267265
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' })
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

275273
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"] })
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 => {
282280
test('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

296294
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' })
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 => {
303301
test('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() ***********/
310308
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' })
312310
t.true(orderBooks.hasProp('data'))
313311
t.true(orderBooks.hasProp('metadata'))
314312
t.true(orderBooks.metadata.columns.includes('numOrders'))
315313
})
316314

317315
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' })
319317
t.true(orderBooks.hasProp('data'))
320318
t.true(orderBooks.hasProp('metadata'))
321319
t.true(orderBooks.metadata.columns.includes('numOrders'))

0 commit comments

Comments
 (0)