Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11926 from Dan-krm/mexcParsePosition
Mexc parsePosition, parsePositions
  • Loading branch information
kroitor committed Feb 11, 2022
2 parents 6a6664b + d440127 commit 8058956
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions js/mexc.js
Expand Up @@ -1548,7 +1548,7 @@ module.exports = class mexc extends Exchange {
};
const response = await this.fetchPositions (this.extend (request, params));
const firstPosition = this.safeValue (response, 0);
return firstPosition;
return this.parsePosition (firstPosition, market);
}

async fetchPositions (symbols = undefined, params = {}) {
Expand Down Expand Up @@ -1584,9 +1584,78 @@ module.exports = class mexc extends Exchange {
// ]
// }
//
// todo add parsePositions, parsePosition
const data = this.safeValue (response, 'data', []);
return data;
return this.parsePositions (data);
}

parsePosition (position, market = undefined) {
//
// {
// "positionId": 1394650,
// "symbol": "ETH_USDT",
// "positionType": 1,
// "openType": 1,
// "state": 1,
// "holdVol": 1,
// "frozenVol": 0,
// "closeVol": 0,
// "holdAvgPrice": 1217.3,
// "openAvgPrice": 1217.3,
// "closeAvgPrice": 0,
// "liquidatePrice": 1211.2,
// "oim": 0.1290338,
// "im": 0.1290338,
// "holdFee": 0,
// "realised": -0.0073,
// "leverage": 100,
// "createTime": 1609991676000,
// "updateTime": 1609991676000,
// "autoAddIm": false
// }
//
market = this.safeMarket (this.safeString (position, 'symbol'), market);
const symbol = market['symbol'];
const contracts = this.safeString (position, 'holdVol');
const entryPrice = this.safeNumber (position, 'openAvgPrice');
const initialMargin = this.safeString (position, 'im');
const rawSide = this.safeString (position, 'positionType');
const side = (rawSide === '1') ? 'long' : 'short';
const openType = this.safeString (position, 'margin_mode');
const marginType = (openType === '1') ? 'isolated' : 'cross';
const leverage = this.safeString (position, 'leverage');
const liquidationPrice = this.safeNumber (position, 'liquidatePrice');
const timestamp = this.safeNumber (position, 'updateTime');
return {
'info': position,
'symbol': symbol,
'contracts': this.parseNumber (contracts),
'contractSize': undefined,
'entryPrice': entryPrice,
'collateral': undefined,
'side': side,
'unrealizedProfit': undefined,
'leverage': this.parseNumber (leverage),
'percentage': undefined,
'marginType': marginType,
'notional': undefined,
'markPrice': undefined,
'liquidationPrice': liquidationPrice,
'initialMargin': this.parseNumber (initialMargin),
'initialMarginPercentage': undefined,
'maintenanceMargin': undefined,
'maintenanceMarginPercentage': undefined,
'marginRatio': undefined,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
};
}

parsePositions (positions) {
const result = [];
for (let i = 0; i < positions.length; i++) {
result.push (this.parsePosition (positions[i]));
}
return result;
}

async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
Expand Down

0 comments on commit 8058956

Please sign in to comment.