Repository: ccxt/ccxt
Pull request: Fix currency in 'fetchTransactions'
- Fix currencies in fetchTransactions
- Replaced a commented lines with correct commenting
[ fixes #11027 ]

Problem statement:
[bitfinex2] Currency always None in transactions
- OS: Ubuntu 21.10
- Programming Language version: Python 3.9
- CCXT version: 1.65.23

The `currency` key is always set to `None` in the transactions returned by `fetch_transactions()`. The `currency` key in `fee` is also `None`.

On a side note, fetching currencies by currency code does not seem to work at all. I have a very recent XLM transactions which does show up as the last transaction (without currency code) in the result of the a `fetch_transactions` call without `code` argument, but it does not show up when I run `fetch_transactions("XLM")`.

```python
import asyncio
from contextlib import asynccontextmanager
from pprint import pprint

import ccxt.async_support as ccxt
from ccxt import AuthenticationError, ExchangeNotAvailable, InvalidNonce, RateLimitExceeded, RequestTimeout


@asynccontextmanager
async def safe_api(api) -> ccxt.Exchange:
    try:
        yield api
    except (
            AuthenticationError,
            ExchangeNotAvailable,
            InvalidNonce,
            RateLimitExceeded,
            RequestTimeout,
    ):
        raise
    finally:
        await api.close()


async def main():
    properties = {...}

    bitfinex = ccxt.bitfinex2(properties)
    await bitfinex.load_markets()

    async with safe_api(bitfinex) as api:
        transactions = await api.fetch_transactions()
        xlm_transactions = await api.fetch_transactions("XLM")
        
    print("Total transactions: ", len(transactions))
    assert all(tx["currency"] is None for tx in transactions)

    print("Last transaction:")
    pprint(transactions[-1])
    print("XLM transactions:")
    pprint(xlm_transactions)


if __name__ == "__main__":
    asyncio.run(main())
```

Output of this script:

```
Total transactions:  10
Last transaction:
{'address': 'abcdefg',
 'addressFrom': None,
 'addressTo': 'abcdefg',
 'amount': 1.00,
 'currency': None,
 'datetime': '2021-12-25T00:00:00.000Z',
 'fee': {'cost': -0.0, 'currency': None, 'rate': None},
 'id': '123456',
 'info': ['123456',
          'XLM',
          'XLM',
          None,
          None,
          '1640390400000',
          '1640390400000',
          None,
          None,
          'COMPLETED',
          None,
          None,
          '1.00',
          '0',
          None,
          None,
          'abcdefg',
          None,
          None,
          None,
          '1234abcdefg',
          None],
 'status': 'COMPLETED',
 'tag': None,
 'tagFrom': None,
 'tagTo': None,
 'timestamp': 1640390400000,
 'txid': '1234abcdefg',
 'type': 'deposit',
 'updated': 1640390400000}
XLM transactions:
[]
```

Hints from issue discussion:

Commit message: indent fix in commented response

Patch to review:
diff --git a/js/bitfinex2.js b/js/bitfinex2.js
index c9636faf17405..8554dfac56804 100644
--- a/js/bitfinex2.js
+++ b/js/bitfinex2.js
@@ -1401,12 +1401,12 @@ module.exports = class bitfinex2 extends bitfinex {
         //         -0.00135, // FEES
         //         null,
         //         null,
-        //         'DESTINATION_ADDRESS',
+        //         '0x38110e0Fc932CB2BE...........', // DESTINATION_ADDRESS
         //         null,
         //         null,
         //         null,
-        //         'TRANSACTION_ID',
-        //         "Purchase of 100 pizzas", // WITHDRAW_TRANSACTION_NOTE
+        //         '0x523ec8945500.....................................', // TRANSACTION_ID
+        //         "Purchase of 100 pizzas", // WITHDRAW_TRANSACTION_NOTE, might also be: null
         //     ]
         //
         const transactionLength = transaction.length;
@@ -1421,7 +1421,7 @@ module.exports = class bitfinex2 extends bitfinex {
         let feeCost = undefined;
         let txid = undefined;
         let addressTo = undefined;
-        if (transactionLength < 9) {
+        if (transactionLength === 8) {
             const data = this.safeValue (transaction, 4, []);
             timestamp = this.safeInteger (transaction, 0);
             if (currency !== undefined) {
@@ -1440,8 +1440,15 @@ module.exports = class bitfinex2 extends bitfinex {
             }
             tag = this.safeString (data, 3);
             type = 'withdrawal';
-        } else {
+        } else if (transactionLength === 22) {
             id = this.safeString (transaction, 0);
+            if (currency !== undefined) {
+                code = currency['code'];
+            } else {
+                const currencyId = this.safeString (transaction, 1);
+                currency = this.safeCurrency (currencyId, currency);
+                code = currency['code'];
+            }
             timestamp = this.safeInteger (transaction, 5);
             updated = this.safeInteger (transaction, 6);
             status = this.parseTransactionStatus (this.safeString (transaction, 9));
@@ -1521,12 +1528,12 @@ module.exports = class bitfinex2 extends bitfinex {
         //             -0.00135, // FEES
         //             null,
         //             null,
-        //             'DESTINATION_ADDRESS',
+        //             '0x38110e0Fc932CB2BE...........', // DESTINATION_ADDRESS
         //             null,
         //             null,
         //             null,
-        //             'TRANSACTION_ID',
-        //             "Purchase of 100 pizzas", // WITHDRAW_TRANSACTION_NOTE
+        //             '0x523ec8945500.....................................', // TRANSACTION_ID
+        //             "Purchase of 100 pizzas", // WITHDRAW_TRANSACTION_NOTE, might also be: null
         //         ]
         //     ]
         //


Code review comments:
diff_hunk: @@ -1440,8 +1440,15 @@ module.exports = class bitfinex2 extends bitfinex {
             }
             tag = this.safeString (data, 3);
             type = 'withdrawal';
-        } else {
+        } else if (transactionLength === 22) {
             id = this.safeString (transaction, 0);
+            if (currency !== undefined) {
+                code = currency['code'];
+            } else {
+                const currencyId = this.safeString (transaction, 1);
+                currency = this.safeCurrency (currencyId, currency);
+                code = currency['code'];
+            }
path: js/bitfinex2.js
text: @user1:
Let's rewrite the above lines 1445-1451, since `if (currency !== undefined)` is already done in `safeCurrency`:

```JavaScript
const currencyId = this.safeString (transaction, 1);
currency = this.safeCurrency (currencyId, currency);
code = currency['code'];
```