Repository: ccxt/ccxt
Pull request: Bitfinex v2 fetchTransactions / movements endpoint issue fix
This specific endpoint  ( https://docs.bitfinex.com/reference#rest-auth-movements ) requires the currency code without prepended chars.
( Also, I've added a temporary reference link to the partial code i've stared, but atm cant proceed with it, and will return to it later. )

[ fixes #10172 ]

Problem statement:
bitfinex2 throws currency: invalid on fetchTransactions
- OS: MacOS
- Programming Language version: node v16.8.0
- CCXT version: ccxt@1.57.68

Basically `bitfinex2` fetchTransactions does not seem to work. 

```js
const exchange = new ccxt.bitfinex2({
  // ...
})
const currencies = await exchange.fetchCurrencies()
for (const currency in currencies) {
	const code = currencies[currency].code
	await exchange.fetch(code, since, limit)
}
```

Throws this, e.g. with parameter AAVE or BTC or really any currency code:

```
Bitfinex fetchTransactions BTC 1420070400000 2015-01-01T00:00:00.000Z 100 BadRequest: bitfinex2 currency: invalid
    at bitfinex2.throwExactlyMatchedException (/Users/luca/projects/exchanges/node_modules/ccxt/js/base/Exchange.js:595:19)
    at bitfinex2.handleErrors (/Users/luca/projects/exchanges/node_modules/ccxt/js/bitfinex2.js:1648:18)
    at /Users/luca/projects/exchanges/node_modules/ccxt/js/base/Exchange.js:657:18
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async timeout (/Users/luca/projects/exchanges/node_modules/ccxt/js/base/functions/time.js:195:24)
    at async bitfinex2.fetchTransactions (/Users/luca/projects/exchanges/node_modules/ccxt/js/bitfinex2.js:1476:26) {
  constructor: [class BadRequest extends ExchangeError]
}

```

I'm using `bitfinex2` as it seems that the opposite behaviour applies to `bitfinex` as I can fetch the transactions but not the trades. Is this a known issue? Or am I doing something wrong? The same code works for other exchanges.

Hints from issue discussion:
```JavaScript
const exchange = new ccxt.bitfinex2({
  // ...
})
const currencies = await exchange.fetchCurrencies()
for (const currency in currencies) {
	const code = currencies[currency].code
	await exchange.fetch(code, since, limit) // <- this line looks wrong to me, no fetchTransactions here
}
```
@steebchen can you please paste your request+response output in verbose mode?

- https://github.com/ccxt/ccxt/wiki/FAQ#what-is-required-to-get-help

```JavaScript
const exchange = new ccxt.bitfinex2({
  // ...
})
await exchange.loadMarkets()
const currencies = await exchange.fetchCurrencies()
exchange.verbose = true
// your code here...
```
I'll remember to use the verbose mode next time.

I meant to write `exchange.fetchTransactions` of course, I just adapted the code (as my code is more complex and wanted to simplify what I'm doing for this issue) and did not get it right.

Anyway, here you go:

```
fetching transactions via fetchTransactions
transaction request Bitfinex fetchTransactions BTC 1633626000000 2021-10-07T17:00:00.000Z 100
fetch:
 bitfinex2 POST https://api.bitfinex.com/v2/auth/r/movements/fBTC/hist
Request:
 {
  'bfx-nonce': '1633678142232',
  'bfx-apikey': 'redacted',
  'bfx-signature': '6e825c497e30e2e7927b69e5ea02b18de828aeca218f6aac96e17dc5d9083279ae904f3bfae8fd6be39b14b14c0c0fff',
  'Content-Type': 'application/json'
}
 {"start":1633626000000,"limit":100}

handleRestResponse:
 bitfinex2 POST https://api.bitfinex.com/v2/auth/r/movements/fBTC/hist 500 Internal Server Error
Response:
 {
  'Cf-Cache-Status': 'DYNAMIC',
  'Cf-Ray': '69ada7e538384f5d-BKK',
  Connection: 'keep-alive',
  'Content-Length': '35',
  'Content-Type': 'application/json; charset=utf-8',
  Date: 'Fri, 08 Oct 2021 07:29:02 GMT',
  'Expect-Ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  'Referrer-Policy': 'same-origin',
  Server: 'cloudflare',
  'Strict-Transport-Security': 'max-age=31536000; includeSubdomains;',
  'X-Content-Type-Options': 'nosniff',
  'X-Download-Options': 'noopen',
  'X-Frame-Options': 'sameorigin',
  'X-Permitted-Cross-Domain-Policies': 'none',
  'X-Xss-Protection': '1; mode=block'
}
 ["error",10020,"currency: invalid"]

Bitfinex fetchTransactions BTC 1633626000000 2021-10-07T17:00:00.000Z 100 BadRequest: bitfinex2 currency: invalid
    at bitfinex2.throwExactlyMatchedException (/Users/luca/projects/exchanges/node_modules/ccxt/js/base/Exchange.js:595:19)
    at bitfinex2.handleErrors (/Users/luca/projects/exchanges/node_modules/ccxt/js/bitfinex2.js:1648:18)
    at /Users/luca/projects/exchanges/node_modules/ccxt/js/base/Exchange.js:657:18
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async timeout (/Users/luca/projects/exchanges/node_modules/ccxt/js/base/functions/time.js:195:24)
    at async bitfinex2.fetchTransactions (/Users/luca/projects/exchanges/node_modules/ccxt/js/bitfinex2.js:1476:26) {
  constructor: [class BadRequest extends ExchangeError]
}
```
@steebchen thank you! Will investigate and will fix it.
I've reproduced the issue. It's bug in ccxt and fix will be submitted shortly.

Commit message: typo

Patch to review:
diff --git a/js/bitfinex2.js b/js/bitfinex2.js
index 23dc78f1ac640..ad12381406951 100644
--- a/js/bitfinex2.js
+++ b/js/bitfinex2.js
@@ -361,7 +361,7 @@ module.exports = class bitfinex2 extends bitfinex {
     }
 
     async fetchMarkets (params = {}) {
-        // todo drop v1 in favor of v2 configs
+        // todo drop v1 in favor of v2 configs  ( temp-reference for v2update: https://pastebin.com/raw/S8CmqSHQ )
         // pub:list:pair:exchange,pub:list:pair:margin,pub:list:pair:futures,pub:info:pair
         const v2response = await this.publicGetConfPubListPairFutures (params);
         const v1response = await this.v1GetSymbolsDetails (params);
@@ -1491,7 +1491,7 @@ module.exports = class bitfinex2 extends bitfinex {
         let method = 'privatePostAuthRMovementsHist';
         if (code !== undefined) {
             currency = this.currency (code);
-            request['currency'] = currency['id'];
+            request['currency'] = currency['code'].toUpper ();
             method = 'privatePostAuthRMovementsCurrencyHist';
         }
         if (since !== undefined) {


Code review comments:
diff_hunk: @@ -1491,7 +1491,7 @@ module.exports = class bitfinex2 extends bitfinex {
         let method = 'privatePostAuthRMovementsHist';
         if (code !== undefined) {
             currency = this.currency (code);
-            request['currency'] = currency['id'];
+            request['currency'] = currency['code'].toUpper ();
path: js/bitfinex2.js
text: @user1:
This is a bit wrong – we should never send unified CCXT codes and CCXT symbols to the exchange as is.
Also, the code of the currency must always be uppercase, if that's not the case, it has to be fixed as well.
We send out exchange-specific ids, and we receive exchange-specific ids, so, it should be `currency['id']` here. We use unified symbols internally. Also, it does not make much sense to uppercase it every single time, instead I suggest adding `uppercaseId` to the currency structure once upon parsing it, if that is absolutely necessary.