From 9ddb1c64fb1f4b8fd740122160764d6cd03be8b6 Mon Sep 17 00:00:00 2001
From: Thaddeus <thad@tardis.dev>
Date: Thu, 17 Mar 2022 14:44:22 +0100
Subject: [PATCH] improvement: gate io futures mapper handles now ticker result
 that is not an array

---
 src/mappers/gateiofutures.ts            | 33 ++++++++++++++++---------
 test/__snapshots__/mappers.test.ts.snap | 19 ++++++++++++++
 test/mappers.test.ts                    | 22 +++++++++++++++++
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/src/mappers/gateiofutures.ts b/src/mappers/gateiofutures.ts
index 110823c..f9d6914 100644
--- a/src/mappers/gateiofutures.ts
+++ b/src/mappers/gateiofutures.ts
@@ -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
       }
@@ -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
+      }
 }
diff --git a/test/__snapshots__/mappers.test.ts.snap b/test/__snapshots__/mappers.test.ts.snap
index 0be1e55..423f140 100644
--- a/test/__snapshots__/mappers.test.ts.snap
+++ b/test/__snapshots__/mappers.test.ts.snap
@@ -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 {
diff --git a/test/mappers.test.ts b/test/mappers.test.ts
index 628b2d4..8233966 100644
--- a/test/mappers.test.ts
+++ b/test/mappers.test.ts
@@ -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')