Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phemex: evaluate posSide in fetchMyTrades() and fetch_orders() #22518

Open
egabosh opened this issue May 16, 2024 · 10 comments
Open

Phemex: evaluate posSide in fetchMyTrades() and fetch_orders() #22518

egabosh opened this issue May 16, 2024 · 10 comments
Assignees

Comments

@egabosh
Copy link

egabosh commented May 16, 2024

Operating System

Debian 12

Programming Languages

Python

CCXT Version

4.3.23

Description

Moin,

for an evaluation of all trades or orders of fetchMyTrades() fetch_orders() it would be very helpful to evaluate from Phemex given values posSide as well as Side.
I have not yet found a way to distinguish whether it is a short or long trade/order.

In Phemex Documentation example gives Short (or Long):
https://phemex-docs.github.io/#query-trades-history

[
    {
        "transactTimeNs": 1669407633926215067,
        "symbol": "BTCUSDT",
        "currency": "USDT",
        "action": "New",
        "posSide": "Short",
        "side": "Sell",
        "tradeType": "Trade",
        "execQtyRq": "0.001",
        "execPriceRp": "16600",
        "orderQtyRq": "0.001",
        "priceRp": "16600",
        "execValueRv": "16.6",
        "feeRateRr": "0.0001",
        "execFeeRv": "0.00166",
        "closedSizeRq": "0",
        "closedPnlRv": "0",
        "ordType": "LimitIfTouched",
        "execID": "5c3d96e1-8874-53b6-b6e5-9dcc4d28b4ab",
        "orderID": "fcdfeafa-ed68-45d4-b2bd-7bc27f2b2b0b",
        "clOrdID": "",                                
        "execStatus": "MakerFill",                                                  
    }
]

In CCXT interpretation a value additionally to side like posside would be great!

see also issue #22512

Code

print(exchange.fetch_orders(symbol='BTC/USDT:USDT', limit=200, params={"paginate": True}))
print(exchange.fetchMyTrades(symbol='BTC/USDT:USDT', limit=500, params={'paginate': True}))
@egabosh
Copy link
Author

egabosh commented May 16, 2024

Don't understand the CCXT code completely but looks like posSide is evaluated only if it is set to "Merged" in "python/ccxt/async_support/phemex.py"

@egabosh
Copy link
Author

egabosh commented May 17, 2024

In Phemex WebUI "Contract History -> Trade History" it is called "Direction":
ksnip_20240517-111035

@carlosmiei carlosmiei self-assigned this May 20, 2024
@carlosmiei
Copy link
Collaborator

Hello @egabosh, I think we discussed this earlier, the positionSide differs from the trade/order side.

@egabosh
Copy link
Author

egabosh commented May 20, 2024

Moin @carlosmiei . I understand your point but my problem is that I have no idea how I can find out with CCXT if it is a long or a short trade.
Do you have an idea?

@carlosmiei
Copy link
Collaborator

@egabosh You can infer the direction using the posSide

For instance, if you fetch trades after opening/increase/decrease a position, depending on the positionMode

one way-mode (does not really matter because there's only one side)

  • Open long position:
    • 'posSide:3' and side = buy
  • Increase long position
    • 'posSide:3' and side = buy
  • Decrease long position
    • posSide: '3' and side = sell

hedged-mode

  • Open long position
    • posSide = 1, side = buy
  • Increase long position
    • posSide = 1, side = buy
  • Decrease long position
    • posSide = 1, side = sell # the posSide is = 1 = 'Long' but the side is sell which means you decreased your long exposure

@egabosh
Copy link
Author

egabosh commented May 20, 2024

Moin @carlosmiei,

maybe I misunderstood something but posSide is only under info{} and I understood that we should not use the area in info{} because it is directly values from the exchange and therefore not uniform for each exchange.
That's why I wanted to include it in the CCXT interpreted area.
If there is posSide under info for every exchange and it is best practice to use the value in this way, the problem would be solved for me and I have misunderstood the info area.

Example output here:

    "info": {
      "createdAt": "1714990724076",
      "symbol": "BTCUSDT",
      "currency": "USDT",
      "action": "1",
      "tradeType": "1",
      "execQtyRq": "0.003",
      "execPriceRp": "64935",
      "side": "2",
      "orderQtyRq": "0.003",
      "priceRp": "51600",
      "execValueRv": "194.805",
      "feeRateRr": "0.000495",
      "execFeeRv": "0",
      "ordType": "3",
      "execId": "XXXXXX",
      "execStatus": "7",
      "posSide": "1",
      "ptFeeRv": "0.110012249248",
      "ptPriceRp": "0.876524893"
    },
    "id": "XXXXXX",
    "symbol": "BTC/USDT:USDT",
    "timestamp": 1714990724076,
    "datetime": "2024-05-06T10:18:44.076Z",
    "order": null,
    "type": null,
    "side": "sell",
    "takerOrMaker": null,
    "price": 64935,
    "amount": 0.003,
    "cost": 194.805,
    "fee": {
      "cost": 0.110012249248,
      "rate": 0.000495,
      "currency": "PT"
    },
    "fees": [
      {
        "cost": 0.110012249248,
        "rate": 0.000495,
        "currency": "PT"
      }
    ]
  },

@carlosmiei
Copy link
Collaborator

@egabosh You're right, the values inside info are exchange-specific and will differ from exchange to exchange but unfortunately I don't think there is a way of doing that in a unified way.

@egabosh
Copy link
Author

egabosh commented May 21, 2024

@carlosmiei OK, thanks. At least I've understood that correctly :-)
Is there a reason why this is not possible in a unified way?
It should be similarly visible on other exchanges, right?

@carlosmiei
Copy link
Collaborator

@egabosh Usually we unify behaviors when we detect a pattern across different exchanges, which is not the case here, at least yet.

@egabosh
Copy link
Author

egabosh commented May 21, 2024

@carlosmiei OK, that makes it easier for me to understand.
Wouldn't it be possible to provide this for the exchanges where it is possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants