Repository: ccxt/ccxt
Pull request: fix(phemex) - funding fees
fix #22434

Problem statement:
Phemex: fetchFundingHistory -> amount: null
### Operating System

Debian 12

### Programming Languages

Python

### CCXT Version

4.3.18

### Description

Moin,

Method fetchFundingHistory gives "amount: null" on Phemex.
Seems wrong for me.

### Code

```
print(exchange.fetchFundingHistory('BTC/USDT:USDT'))
```
Example Result:
```
    "info": {
      "symbol": "BTCUSDT",
      "currency": "USDT",
      "execQtyRq": "0.001",
      "side": "Buy",
      "execPriceRp": "64905.93672508",
      "execValueRv": "64.90593673",
      "fundingRateRr": "0.00003809",
      "feeRateRr": "0.00003809",
      "execFeeRv": "0.00247227",
      "createTime": "1713744000000"
    },
    "symbol": "BTCUSDT",
    "code": "USDT",
    "timestamp": 1713744000000,
    "datetime": "2024-04-22T00:00:00.000Z",
    "id": null,
    "amount": null
  }
```
Amount should not be null I think,

Hints from issue discussion:
I think amount should be value of "execFeeRv"
@egabosh I think we've added in this commit https://github.com/ccxt/ccxt/commit/c47df4ffd86, could you upgrade and try again?
@sc0Vu Didn't change. Amount is still null/None
did a fresh
git clone https://github.com/ccxt/ccxt.git --depth 1
Is this enough?
Don't understand the code completely but maybe it is a typo execFeeEv should be execFeeRv? Or something changed on Phemex?
@egabosh I think you're right, we have an issue there. Thanks for bringing our attention to this!

Commit message: comments

Patch to review:
diff --git a/ts/src/phemex.ts b/ts/src/phemex.ts
index 47ac568952a74..a2306759fbd77 100644
--- a/ts/src/phemex.ts
+++ b/ts/src/phemex.ts
@@ -3837,6 +3837,7 @@ export default class phemex extends Exchange {
             request['limit'] = limit;
         }
         let response = undefined;
+        this.verbose = true;
         if (market['settle'] === 'USDT') {
             response = await this.privateGetApiDataGFuturesFundingFees (this.extend (request, params));
         } else {
@@ -3851,13 +3852,13 @@ export default class phemex extends Exchange {
         //                 {
         //                     "symbol": "BTCUSD",
         //                     "currency": "BTC",
-        //                     "execQty": 18,
+        //                     "execQty": 18, // "execQty" regular, but "execQtyRq" in hedge
         //                     "side": "Buy",
-        //                     "execPriceEp": 360086455,
-        //                     "execValueEv": 49987,
-        //                     "fundingRateEr": 10000,
-        //                     "feeRateEr": 10000,
-        //                     "execFeeEv": 5,
+        //                     "execPriceEp": 360086455, // "execPriceEp" regular, but "execPriceRp" in hedge
+        //                     "execValueEv": 49987, // "execValueEv" regular, but "execValueRv" in hedge
+        //                     "fundingRateEr": 10000, // "fundingRateEr" regular, but "fundingRateRr" in hedge
+        //                     "feeRateEr": 10000, // "feeRateEr" regular, but "feeRateRr" in hedge
+        //                     "execFeeEv": 5, // "execFeeEv" regular, but "execFeeRv" in hedge
         //                     "createTime": 1651881600000
         //                 }
         //             ]
@@ -3870,6 +3871,7 @@ export default class phemex extends Exchange {
         for (let i = 0; i < rows.length; i++) {
             const entry = rows[i];
             const timestamp = this.safeInteger (entry, 'createTime');
+            const execFee = this.safeString2 (entry, 'execFeeEv', 'execFeeRv');
             result.push ({
                 'info': entry,
                 'symbol': this.safeString (entry, 'symbol'),
@@ -3877,7 +3879,7 @@ export default class phemex extends Exchange {
                 'timestamp': timestamp,
                 'datetime': this.iso8601 (timestamp),
                 'id': undefined,
-                'amount': this.fromEv (this.safeString (entry, 'execFeeEv'), market),
+                'amount': this.fromEv (execFee, market),
             });
         }
         return result as FundingHistory[];


Code review comments:
diff_hunk: @@ -3837,6 +3837,7 @@ export default class phemex extends Exchange {
             request['limit'] = limit;
         }
         let response = undefined;
+        this.verbose = true;
path: ts/src/phemex.ts
text: @user1:
@author leftover

@author:
ohh give me a sec :(