Repository: ccxt/ccxt
Pull request: woo: update watchOrders price & filled ccxt/ccxt#17652
fix ccxt/ccxt#17652

Problem statement:
WooX parse_ws_order incorrect filled quantity
### Operating System

Ubuntu 22.04.1 LTS

### Programming Languages

Python

### CCXT Version

3.0.73

### Description

Here is a quick example from what I received from the watch_orders method (don't mind the json formatting):

```
{
  "info": {
    "symbol": "PERP_ETH_USDT",
    "clientOrderId": 7056249211750191000,
    "orderId": 299266282,
    "type": "LIMIT",
    "side": "BUY",
    "quantity": 0.034,
    "price": 1850.2,
    "tradeId": 276909456,
    "executedPrice": 1850.2,
    "executedQuantity": 0.014,
    "fee": 0.01036112,
    "feeAsset": "USDT",
    "totalExecutedQuantity": 0.034,
    "avgPrice": 1850.2,
    "status": "FILLED",
    "reason": "",
    "orderTag": "default",
    "totalFee": 0.02516272,
    "visible": 0.034,
    "timestamp": 1682340916380,
    "reduceOnly": false,
    "maker": true
  },
  "symbol": "ETH/USDT:USDT",
  "id": "299266282",
  "clientOrderId": "7056249211750191104",
  "timestamp": 1682340911529,
  "datetime": "2023-04-24T12:55:11.529Z",
  "lastTradeTimestamp": 1682340916380,
  "type": "limit",
  "timeInForce": null,
  "postOnly": null,
  "side": "buy",
  "price": 1850.2,
  "stopPrice": null,
  "triggerPrice": null,
  "amount": 0.034,
  "cost": "0.02516272",
  "average": null,
  "filled": 0.014,
  "remaining": 0,
  "status": "closed",
  "fee": {
    "cost": "0.0",
    "currency": "USDT"
  },
  "trades": null
}
```

See how filled quantity, remaining quantity and amount do not align?

I think that comes from this part of the code 

```
        price = self.safe_float(order, 'price')
        amount = self.safe_float(order, 'quantity')
        side = self.safe_string_lower(order, 'side')
        type = self.safe_string_lower(order, 'type')
        filled = self.safe_float(order, 'executedQuantity')
        totalExecQuantity = self.safe_float(order, 'totalExecutedQuantity')
        remaining = amount
        if amount >= totalExecQuantity:
            remaining -= totalExecQuantity
```
I would think that `price` should be `avgPrice`, and `filled` should be `totalExecutedQuantity`

if not, I think remaining should not be 0 in that case

Hope this help, if you have any question, I can send more infos

Thanks a lot !

### Code

```
  

```

Hints from issue discussion:
Additional info:

```
{'info': {'symbol': 'PERP_ETH_USDT', 'clientOrderId': 7056249211750191104, 'orderId': 299266282, 'type': 'LIMIT', 'side': 'BUY', 'quantity': 0.034, 'price': 1850.2, 'tradeId': 276909453, 'executedPrice': 1850.2, 'executedQuantity': 0.02, 'fee': 0.0148016, 'feeAsset': 'USDT', 'totalExecutedQuantity': 0.02, 'avgPrice': 1850.2, 'status': 'PARTIAL_FILLED', 'reason': '', 'orderTag': 'default', 'totalFee': 0.0148016, 'visible': 0.034, 'timestamp': 1682340913058, 'reduceOnly': False, 'maker': True}, 'symbol': 'ETH/USDT:USDT', 'id': '299266282', 'clientOrderId': '7056249211750191104', 'timestamp': 1682340911529, 'datetime': '2023-04-24T12:55:11.529Z', 'lastTradeTimestamp': 1682340913058, 'type': 'limit', 'timeInForce': None, 'postOnly': None, 'side': 'buy', 'price': 1850.2, 'stopPrice': None, 'triggerPrice': None, 'amount': 0.034, 'cost': '0.0148016', 'average': None, 'filled': 0.02, 'remaining': 0.014000000000000002, 'status': 'open', 'fee': {'cost': '0.0', 'currency': 'USDT'}, 'trades': None}
```
This was received earlier, those are the missing 0.02

I still think we should use totalExecutedQuantity for filled field :)

Commit message: woo: update watchOrders price & filled

Patch to review:
diff --git a/ts/src/pro/woo.ts b/ts/src/pro/woo.ts
index bd34f44558e6c..289aa22cb9163 100644
--- a/ts/src/pro/woo.ts
+++ b/ts/src/pro/woo.ts
@@ -517,11 +517,15 @@ export default class woo extends wooRest {
             'cost': cost,
             'currency': this.safeString (order, 'feeAsset'),
         };
-        const price = this.safeFloat (order, 'price');
+        let price = this.safeFloat (order, 'price');
+        const avgPrice = this.safeFloat (order, 'avgPrice');
+        if (price === 0 && avgPrice !== undefined) {
+            price = avgPrice;
+        }
         const amount = this.safeFloat (order, 'quantity');
         const side = this.safeStringLower (order, 'side');
         const type = this.safeStringLower (order, 'type');
-        const filled = this.safeFloat (order, 'executedQuantity');
+        const filled = this.safeFloat (order, 'totalExecutedQuantity');
         const totalExecQuantity = this.safeFloat (order, 'totalExecutedQuantity');
         let remaining = amount;
         if (amount >= totalExecQuantity) {


Code review comments:
diff_hunk: @@ -517,11 +517,15 @@ export default class woo extends wooRest {
             'cost': cost,
             'currency': this.safeString (order, 'feeAsset'),
         };
-        const price = this.safeFloat (order, 'price');
+        let price = this.safeFloat (order, 'price');
path: ts/src/pro/woo.ts
text: @user1:
@author we should avoid `safeFloat` usage, can you replace it with `safeNumber` ?