MCPcopy Index your code
hub / github.com/ccxt/ccxt / safePosition

Method safePosition

java/lib/src/main/java/io/github/ccxt/Exchange.java:8211–8240  ·  view source on GitHub ↗
(Object position)

Source from the content-addressed store, hash-verified

8209 }
8210
8211 public Object safePosition(Object position)
8212 {
8213 // simplified version of: /pull/12765/
8214 Object unrealizedPnlString = this.safeString(position, "unrealisedPnl");
8215 Object initialMarginString = this.safeString(position, "initialMargin");
8216 //
8217 // PERCENTAGE
8218 //
8219 Object percentage = this.safeValue(position, "percentage");
8220 if (Helpers.isTrue(Helpers.isTrue(Helpers.isTrue((Helpers.isEqual(percentage, null))) && Helpers.isTrue((!Helpers.isEqual(unrealizedPnlString, null)))) && Helpers.isTrue((!Helpers.isEqual(initialMarginString, null)))))
8221 {
8222 // as it was done in all implementations ( aax, btcex, bybit, deribit, gate, kucoinfutures, phemex )
8223 Object percentageString = Precise.stringMul(Precise.stringDiv(unrealizedPnlString, initialMarginString, 4), "100");
8224 Helpers.addElementToObject(position, "percentage", this.parseNumber(percentageString));
8225 }
8226 // if contractSize is undefined get from market
8227 Object contractSize = this.safeNumber(position, "contractSize");
8228 Object symbol = this.safeString(position, "symbol");
8229 Object market = null;
8230 if (Helpers.isTrue(!Helpers.isEqual(symbol, null)))
8231 {
8232 market = this.safeValue(this.markets, symbol);
8233 }
8234 if (Helpers.isTrue(Helpers.isTrue(Helpers.isEqual(contractSize, null)) && Helpers.isTrue(!Helpers.isEqual(market, null))))
8235 {
8236 contractSize = this.safeNumber(market, "contractSize");
8237 Helpers.addElementToObject(position, "contractSize", contractSize);
8238 }
8239 return position;
8240 }
8241
8242 public Object parsePositions(Object positions, Object... optionalArgs)
8243 {

Callers 15

parsePositionRiskMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45
parsePositionMethod · 0.45

Calls 9

safeStringMethod · 0.95
safeValueMethod · 0.95
isTrueMethod · 0.95
isEqualMethod · 0.95
stringMulMethod · 0.95
stringDivMethod · 0.95
addElementToObjectMethod · 0.95
parseNumberMethod · 0.95
safeNumberMethod · 0.95

Tested by

no test coverage detected