Skip to content

Commit

Permalink
feat: use bitmarts v3 ticker endpoint (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 authored Sep 18, 2024
1 parent 17ccd4d commit 5e22de7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "celo-oracle",
"version": "2.0.10-beta",
"version": "2.0.11-beta",
"description": "Oracle application to aggregate and report exchange rates to the Celo network",
"author": "Celo",
"license": "Apache-2.0",
Expand Down
54 changes: 27 additions & 27 deletions src/exchange_adapters/bitmart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,46 @@ export class BitMartAdapter extends BaseExchangeAdapter implements ExchangeAdapt
async fetchTicker(): Promise<Ticker> {
const tickerJson = await this.fetchFromApi(
ExchangeDataType.TICKER,
`spot/v1/ticker_detail?symbol=${this.pairSymbol}`
`spot/quotation/v3/ticker?symbol=${this.pairSymbol}`
)
return this.parseTicker(tickerJson)
}

/**
*
* @param json parsed response from bitmart's ticker endpoint
* @param json parsed response from bitmart's V3 ticker endpoint
* https://api-cloud.bitmart.com/spot/quotation/v3/ticker?symbol=BTC_USDT
* {
* "message":"OK",
* "code":1000,
* "trace":"0f0e93db0eaf472886fbac3dc691c22f.59.16892370225147127",
* "data":{
* "symbol":"EUROC_USDC",
* "last_price":"1.10774487",
* "quote_volume_24h":"91116.51006870",
* "base_volume_24h":"82563.0",
* "high_24h":"1.10872025",
* "low_24h":"1.09666702",
* "open_24h":"1.09737308",
* "close_24h":"1.10774487",
* "best_ask":"1.11144303",
* "best_ask_size":"58.2",
* "best_bid":"1.10795347",
* "best_bid_size":"50.3",
* "fluctuation":"+0.0095",
* "timestamp":1689236985709,
* "url":"https://www.bitmart.com/trade?symbol=EUROC_USDC"}
* "code": 1000,
* "trace":"886fb6ae-456b-4654-b4e0-1231",
* "message": "success",
* "data": {
* "symbol": "BTC_USDT",
* "last": "30000.00",
* "v_24h": "582.08066",
* "qv_24h": "4793098.48",
* "open_24h": "28596.30",
* "high_24h": "31012.44",
* "low_24h": "12.44",
* "fluctuation": "0.04909",
* "bid_px": "30000",
* "bid_sz": "1",
* "ask_px": "31012.44",
* "ask_sz": "69994.75267",
* "ts": "1691671061919"
* }
* }
* @returns Ticker object
*/
parseTicker(json: any): Ticker {
const ticker = {
...this.priceObjectMetadata,
ask: this.safeBigNumberParse(json.data.best_ask)!,
baseVolume: this.safeBigNumberParse(json.data.base_volume_24h)!,
bid: this.safeBigNumberParse(json.data.best_bid)!,
lastPrice: this.safeBigNumberParse(json.data.last_price)!,
quoteVolume: this.safeBigNumberParse(json.data.quote_volume_24h)!,
timestamp: this.safeBigNumberParse(json.data.timestamp)?.toNumber()!,
ask: this.safeBigNumberParse(json.data.ask_px)!,
baseVolume: this.safeBigNumberParse(json.data.v_24h)!,
bid: this.safeBigNumberParse(json.data.bid_px)!,
lastPrice: this.safeBigNumberParse(json.data.last)!,
quoteVolume: this.safeBigNumberParse(json.data.qv_24h)!,
timestamp: this.safeBigNumberParse(json.data.ts)?.toNumber()!,
}
this.verifyTicker(ticker)
return ticker
Expand Down
76 changes: 36 additions & 40 deletions test/exchange_adapters/bitmart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,44 @@ describe('BitMart adapter', () => {
})

const validMockTickerJson = {
message: 'OK',
code: 1000,
trace: '48cff315816f4e1aa26ca72cccb46051.58.16892401718550155',
trace: 'cb71f71e25c3455bb1cb79d0f4a5193f.80.17266561640857171',
message: 'success',
data: {
symbol: 'EURC_USDC',
last_price: '1.10806017',
quote_volume_24h: '91361.42293780',
base_volume_24h: '82758.2',
high_24h: '1.10872025',
low_24h: '1.09676936',
open_24h: '1.09735661',
close_24h: '1.10',
best_ask: '1.11109875',
best_ask_size: '51.1',
best_bid: '1.10756051',
best_bid_size: '55.2',
fluctuation: '+0.0098',
timestamp: 1689239976811,
url: 'https://www.bitmart.com/trade?symbol=EURC_USDC',
symbol: 'EURC_USDT',
last: '1.10865893',
v_24h: '285133.6',
qv_24h: '316205.69052193',
open_24h: '1.10995877',
high_24h: '1.11513918',
low_24h: '1.10571015',
fluctuation: '-0.00117',
bid_px: '1.10865891',
bid_sz: '108.8',
ask_px: '1.11484809',
ask_sz: '57.6',
ts: '1726656163973',
},
}

const inValidMockTickerJson = {
message: 'OK',
code: 1000,
trace: '48cff315816f4e1aa26ca72cccb46051.58.16892401718550155',
trace: 'cb71f71e25c3455bb1cb79d0f4a5193f.80.17266561640857171',
message: 'success',
data: {
symbol: 'EURC_USDC',
last_price: undefined,
quote_volume_24h: '91361.42293780',
base_volume_24h: undefined,
high_24h: '1.10872025',
low_24h: '1.09676936',
open_24h: '1.09735661',
close_24h: '1.10806017',
best_ask: undefined,
best_ask_size: '51.1',
best_bid: undefined,
best_bid_size: '55.2',
fluctuation: '+0.0098',
timestamp: undefined,
url: 'https://www.bitmart.com/trade?symbol=EURC_USDC',
symbol: 'EURC_USDT',
last: undefined,
v_24h: undefined,
qv_24h: '316205.69052193',
open_24h: '1.10995877',
high_24h: '1.11513918',
low_24h: '1.10571015',
fluctuation: '-0.00117',
bid_px: undefined,
bid_sz: '108.8',
ask_px: undefined,
ask_sz: '57.6',
ts: undefined,
},
}

Expand All @@ -75,12 +71,12 @@ describe('BitMart adapter', () => {
expect(ticker).toEqual({
source: Exchange.BITMART,
symbol: bitmartAdapter.standardPairSymbol,
ask: new BigNumber(1.11109875),
baseVolume: new BigNumber(82758.2),
bid: new BigNumber(1.10756051),
lastPrice: new BigNumber(1.10806017),
quoteVolume: new BigNumber(91361.4229378),
timestamp: 1689239976811,
ask: new BigNumber(1.11484809),
baseVolume: new BigNumber(285133.6),
bid: new BigNumber(1.10865891),
lastPrice: new BigNumber(1.10865893),
quoteVolume: new BigNumber(316205.69052193),
timestamp: 1726656163973,
})
})

Expand Down

0 comments on commit 5e22de7

Please sign in to comment.