Coder Social home page Coder Social logo

Comments (12)

egabosh avatar egabosh commented on September 22, 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"

from ccxt.

egabosh avatar egabosh commented on September 22, 2024

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

from ccxt.

carlosmiei avatar carlosmiei commented on September 22, 2024

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

from ccxt.

egabosh avatar egabosh commented on September 22, 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?

from ccxt.

carlosmiei avatar carlosmiei commented on September 22, 2024

@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

from ccxt.

egabosh avatar egabosh commented on September 22, 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"
      }
    ]
  },

from ccxt.

carlosmiei avatar carlosmiei commented on September 22, 2024

@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.

from ccxt.

egabosh avatar egabosh commented on September 22, 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?

from ccxt.

carlosmiei avatar carlosmiei commented on September 22, 2024

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

from ccxt.

egabosh avatar egabosh commented on September 22, 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?

from ccxt.

untoreh avatar untoreh commented on September 22, 2024

@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

In merged/oneway mode:
Let's say I am only syncing the last 10 trades, without knowing the position side of the order I would need to know the position state at the date of the first of the 10 trades...after which I can keep track of when the position switches side, so even with posSide it's not possible to reliably reconstruct the position history on phemex

from ccxt.

egabosh avatar egabosh commented on September 22, 2024

In merged/oneway mode: Let's say I am only syncing the last 10 trades, without knowing the position side of the order I would need to know the position state at the date of the first of the 10 trades...after which I can keep track of when the position switches side, so even with posSide it's not possible to reliably reconstruct the position history on phemex

Is this a problem only with phemex or do we have the same issue on other exchanges too?

from ccxt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.