Comments (12)
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.
In Phemex WebUI "Contract History -> Trade History" it is called "Direction":
from ccxt.
Hello @egabosh, I think we discussed this earlier, the positionSide
differs from the trade/order side.
from ccxt.
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.
@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
- posSide = 1, side = sell # the posSide is = 1 = 'Long' but the side is
from ccxt.
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.
@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.
@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.
@egabosh Usually we unify behaviors when we detect a pattern across different exchanges, which is not the case here, at least yet.
from ccxt.
@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.
@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.
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)
- binance: fetch_funding_rate_history return [] value HOT 4
- Gateio futures does not work with CCXT Pro HOT 8
- Bybit bad symbol `NEIROETHUSDT` HOT 2
- crypto.com access denied HOT 5
- hyperliquid unable to use/debug "set_margin_mode" and "set_leverage" HOT 9
- GateIO Futures - Time/bid/ask is not saved in watch_tickers (also bid, ask). HOT 2
- New Exchange: Biconomy CEX - https://www.biconomy.com/en
- New Exchange: KoinBX CEX - https://koinbx.com/ HOT 1
- bitget .markets doesn't include margin markets HOT 1
- Error: self is not defined in Deno HOT 4
- Bitmart bid or ask getting stuck
- okx watchPositions extra parameters not working HOT 1
- hyperliquid create_order params are being ignored HOT 2
- binance fetch_open_interest_history params['paginate'] is overriden to False HOT 1
- kucoinfutures fetch_my_trades only returns 50 trades regardless of limit or pagination attempts HOT 1
- Bitmart - uid should be renamed to memo HOT 3
- How to place a spot marker order using base currency amount for Gate? HOT 3
- how log all ccxt calls? HOT 1
- ccxt.pro watch_ohlcv for multiple symbols from binance futures HOT 2
- CurrencyCom OHLCV fetch returning empty values HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ccxt.