Coder Social home page Coder Social logo

Comments (13)

carlosmiei avatar carlosmiei commented on September 21, 2024 1

@egabosh No problem let us know if anything!

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

Hello @egabosh,
Thanks for reporting it.

Just to make sure I understood, are you saying that if you made a buy that impacted the short position (reducing it for instance), then the trade should contain sell as the side?

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

Moin @carlosmiei,

not quite. Sorry, I'll try to describe it again in more detail:

If I invest in a short position (buy), then Phemex sets “side”: “2”, which is interpreted by CCXT as “sell”.
However, Phemex also sets the variable “posSide”: “2”, which is set to 1 for a long trade.

Short is basically an inverse long. This therefore makes sense in terms of Phemex logic.

This does not seem to be taken into account in the CCXT processed output.
Therefore, in my opinion, it would be necessary in CCXT either to specify whether it is a long or short trade, which as far as I know is evident from “posSide”, or to switch sides in the case of a short trade.
Depending on what fits better in CCXT.

It would only be important for me to be able to recognize in the CCXT output whether it is a short or long trade, as otherwise misinterpretations would occur.

So currently the output of CCXT is incorrect because it is incomplete.

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

@egabosh This is confusing me a bit

If I invest in a short position (buy)

Upon trading futures, we don't say we bought a short, we say you sold/shorted X amount of the Y contract, so usually we don't mix buy+short terminology

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

The posSide in that case can be used for inferring if the trade increased/reduced the exposure of the position, but the side should still be sell

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

The posSide in that case can be used for inferring if the trade increased/reduced the exposure of the position, but the side should still be sell

Yes, exactly. It would only be important to know whether the trade is a short or a long trade.
fetchMyTrades() outputs all short and long trades and it is not clear from the CCXT output whether the trade in question is a short or long position.
This information is only available in the variable posSide (not to be confused with Side) provided by Phemex.

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

@egabosh I'm afraid that information does not belong to trade, a trade is a execution report and should state if that particular trade bought or sold some X amount of contracts, regardless of the position impacted.

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

Without this information, I cannot recognize from the CCXT output whether I have opened a short or long position in the trade.
So whether I clicked on “Open Long” or “Open Short”.
See screenshot:
ksnip_20240516-123910
In the json output of phemex this is indicated by posSide.
So I need this information about the CCXT output.

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

@egabosh That information should be available as you intend inside the Order structure, but not in the Trade

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

@carlosmiei OK. but then should the the side in CCXT be switched from "buy" to "sell" and "sell" to "buy" if Phemex posSide is 2 I think.

from ccxt.

carlosmiei avatar carlosmiei commented on September 21, 2024

@egabosh Now that I'm thinking, not sure if even in Order we should apply that logic, because one buy order can be used to shrink a short position and one sell order to shrink a buy but the order was indeed a buy/sell. I think you would have to use the Position + Order to determine the impact the order had on your current position.

Besides that, upon placing the order, depending on the positionMode you know in advance if the order will impact the short/long leg, if you're in the one-way mode you can use things like reduceOnly to ensure that the order produces the desired effect.

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

@carlosmiei Ah. I'll give it some more thought but the more I think about it, I think you're right.
Sorry for the confusion.

from ccxt.

egabosh avatar egabosh commented on September 21, 2024

@egabosh That information should be available as you intend inside the Order structure, but not in the Trade

@carlosmiei: Didn't find the Information in any order got by fetch_orders() interpreted by CCXT too (only information is posSide from Phemex. Example:

    "info": {
      "createdAt": "1715818144087",
      "symbol": "BTCUSDT",
      "orderQtyRq": "0.01",
      "side": "1",
      "posSide": "2",
      "priceRp": "75326.2",
      "execQtyRq": "0.01",
      "leavesQtyRq": "0",
      "execPriceRp": "66573.7",
      "orderValueRv": "665.737",
      "leavesValueRv": "0",
      "cumValueRv": "665.737",
      "stopDirection": "1",
      "stopPxRp": "66500",
      "trigger": "1",
      "actionBy": "4",
      "execFeeRv": "0.36615535",
      "ordType": "3",
      "ordStatus": "7",
      "clOrdId": "XXXXXXXXXXXXXXXX",
      "orderId": "XXXXXXXXXXXXXXXX",
      "execStatus": "7",
      "bizError": "0",
      "totalPnlRv": null,
      "avgTransactPriceRp": null,
      "orderDetailsVos": null,
      "tradeType": "1",
      "updatedAt": "1715818144091"
    },
    "id": "XXXXXXXXXXXXXXXX",
    "clientOrderId": "XXXXXXXXXXXXXXXX",
    "datetime": "2024-05-16T00:09:04.087Z",
    "timestamp": 1715818144087,
    "lastTradeTimestamp": null,
    "symbol": "BTC/USDT:USDT",
    "type": null,
    "timeInForce": null,
    "postOnly": false,
    "reduceOnly": null,
    "side": "buy",
    "price": 75326.2,
    "stopPrice": 66500,
    "triggerPrice": 66500,
    "takeProfitPrice": null,
    "stopLossPrice": null,
    "amount": 0.01,
    "filled": 0.01,
    "remaining": 0,
    "cost": 665.737,
    "average": 66573.7,
    "status": "closed",
    "fee": null,
    "trades": [],
    "fees": [],
    "lastUpdateTimestamp": null

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.