Skip to content

Commit

Permalink
improvement: gate io futures mapper handles now ticker result that is…
Browse files Browse the repository at this point in the history
… not an array
  • Loading branch information
thaaddeus committed Mar 17, 2022
1 parent 878a7f2 commit 9ddb1c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/mappers/gateiofutures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export class GateIOFuturesDerivativeTickerMapper implements Mapper<'gate-io-futu
}

*map(message: GateIOFuturesTicker, localTimestamp: Date): IterableIterator<DerivativeTicker> {
for (const futuresTicker of message.result) {
const tickers = Array.isArray(message.result) ? message.result : [message.result]

for (const futuresTicker of tickers) {
if (futuresTicker.contract === undefined) {
return
}
Expand Down Expand Up @@ -179,14 +181,23 @@ type GateIOFuturesTicker = {
channel: 'futures.tickers'
event: 'update'

result: [
{
contract: string
last: string
funding_rate: string
mark_price: string
index_price: string
funding_rate_indicative: string
}
]
result:
| [
{
contract: string
last: string
funding_rate: string
mark_price: string
index_price: string
funding_rate_indicative: string
}
]
| {
contract: string
last: string
funding_rate: string
mark_price: string
index_price: string
funding_rate_indicative: string
}
}
19 changes: 19 additions & 0 deletions test/__snapshots__/mappers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4712,6 +4712,25 @@ Array [

exports[`mappers map gate-io-futures messages 15`] = `Array []`;

exports[`mappers map gate-io-futures messages 16`] = `
Array [
Object {
"exchange": "gate-io-futures",
"fundingRate": 0.0001,
"fundingTimestamp": undefined,
"indexPrice": 26.9291,
"lastPrice": 25.595,
"localTimestamp": 2020-07-01T00:00:01.275Z,
"markPrice": 26.929,
"openInterest": undefined,
"predictedFundingRate": 0.0001,
"symbol": "ETC_USD",
"timestamp": 2022-03-17T07:13:26.000Z,
"type": "derivative_ticker",
},
]
`;

exports[`mappers map gemini messages 1`] = `
Array [
Object {
Expand Down
22 changes: 22 additions & 0 deletions test/mappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5843,6 +5843,28 @@ describe('mappers', () => {
}
]
]
},
{
time: 1647501206,
channel: 'futures.tickers',
event: 'update',
result: {
contract: 'ETC_USD',
last: '25.595',
change_percentage: '0',
total_size: '14',
volume_24h: '0',
volume_24h_base: '0',
volume_24h_quote: '0',
volume_24h_settle: '0',
mark_price: '26.929',
funding_rate: '0.0001',
funding_rate_indicative: '0.0001',
index_price: '26.9291',
quanto_base_rate: '0.0006594',
volume_24_usd: '0',
volume_24_btc: '0'
}
}
]
const gateIOFuturesMapper = createMapper('gate-io-futures')
Expand Down

0 comments on commit 9ddb1c6

Please sign in to comment.