Skip to content

Commit

Permalink
Merge pull request #11154 from frosty00/contractSizeNumber fix #11123
Browse files Browse the repository at this point in the history
Contract size number
  • Loading branch information
kroitor committed Jan 7, 2022
2 parents 1e9c9aa + f41fe0c commit 46ebfce
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion js/aax.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ module.exports = class aax extends Exchange {
if (swap) {
symbol = symbol + ':' + settle;
type = 'swap';
contractSize = this.safeString (market, 'multiplier');
contractSize = this.safeNumber (market, 'multiplier');
}
result.push ({
'id': id,
Expand Down
2 changes: 1 addition & 1 deletion js/ascendex.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ module.exports = class ascendex extends Exchange {
const type = swap ? 'swap' : 'spot';
const margin = this.safeValue (market, 'marginTradable', false);
const linear = swap ? true : undefined;
const contractSize = swap ? '1' : undefined;
const contractSize = swap ? this.parseNumber ('1') : undefined;
let minQty = this.safeNumber (market, 'minQty');
let maxQty = this.safeNumber (market, 'maxQty');
let minPrice = this.safeNumber (market, 'tickSize');
Expand Down
2 changes: 1 addition & 1 deletion js/base/functions/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const precisionConstants = {

function numberToString (x) { // avoids scientific notation for too large and too small numbers

if (typeof x === 'string') return x
if (typeof x !== 'number') return x.toString ()

const s = x.toString ()
if (Math.abs (x) < 1.0) {
Expand Down
14 changes: 9 additions & 5 deletions js/binance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ module.exports = class binance extends Exchange {
let contractSize = undefined;
let fees = this.fees;
if (future || delivery) {
contractSize = this.safeString (market, 'contractSize', '1');
contractSize = this.safeNumber (market, 'contractSize', this.parseNumber ('1'));
fees = this.fees[type];
}
const maker = fees['trading']['maker'];
Expand Down Expand Up @@ -4426,6 +4426,8 @@ module.exports = class binance extends Exchange {
let percentage = undefined;
let liquidationPriceStringRaw = undefined;
let liquidationPrice = undefined;
const contractSize = this.safeValue (market, 'contractSize');
const contractSizeString = this.numberToString (contractSize);
if (notionalFloat === 0.0) {
entryPrice = undefined;
} else {
Expand Down Expand Up @@ -4464,7 +4466,7 @@ module.exports = class binance extends Exchange {
onePlusMaintenanceMarginPercentageString = Precise.stringSub ('-1', maintenanceMarginPercentageString);
entryPriceSignString = Precise.stringMul ('-1', entryPriceSignString);
}
const size = Precise.stringMul (contractsStringAbs, market['contractSize']);
const size = Precise.stringMul (contractsStringAbs, contractSizeString);
const leftSide = Precise.stringMul (size, onePlusMaintenanceMarginPercentageString);
const rightSide = Precise.stringSub (Precise.stringMul (Precise.stringDiv ('1', entryPriceSignString), size), walletBalance);
liquidationPriceStringRaw = Precise.stringDiv (leftSide, rightSide);
Expand Down Expand Up @@ -4500,7 +4502,7 @@ module.exports = class binance extends Exchange {
'leverage': this.parseNumber (leverageString),
'unrealizedPnl': unrealizedPnl,
'contracts': contracts,
'contractSize': this.parseNumber (market['contractSize']),
'contractSize': contractSize,
'marginRatio': marginRatio,
'liquidationPrice': liquidationPrice,
'markPrice': undefined,
Expand Down Expand Up @@ -4587,6 +4589,8 @@ module.exports = class binance extends Exchange {
}
const entryPriceString = this.safeString (position, 'entryPrice');
const entryPrice = this.parseNumber (entryPriceString);
const contractSize = this.safeValue (market, 'contractSize');
const contractSizeString = this.numberToString (contractSize);
// as oppose to notionalValue
const linear = ('notional' in position);
if (marginType === 'cross') {
Expand Down Expand Up @@ -4614,7 +4618,7 @@ module.exports = class binance extends Exchange {
onePlusMaintenanceMarginPercentageString = Precise.stringSub ('-1', maintenanceMarginPercentageString);
entryPriceSignString = Precise.stringMul ('-1', entryPriceSignString);
}
const leftSide = Precise.stringMul (contractsAbs, market['contractSize']);
const leftSide = Precise.stringMul (contractsAbs, contractSizeString);
const rightSide = Precise.stringSub (Precise.stringDiv ('1', entryPriceSignString), Precise.stringDiv (onePlusMaintenanceMarginPercentageString, liquidationPriceString));
collateralString = Precise.stringDiv (Precise.stringMul (leftSide, rightSide), '1', market['precision']['base']);
}
Expand Down Expand Up @@ -4651,7 +4655,7 @@ module.exports = class binance extends Exchange {
'info': position,
'symbol': symbol,
'contracts': contracts,
'contractSize': this.parseNumber (market['contractSize']),
'contractSize': contractSize,
'unrealizedPnl': unrealizedPnl,
'leverage': this.parseNumber (leverageString),
'liquidationPrice': liquidationPrice,
Expand Down
2 changes: 1 addition & 1 deletion js/bitmart.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ module.exports = class bitmart extends Exchange {
'inverse': undefined,
'taker': this.safeNumber (feeConfig, 'taker_fee'),
'maker': this.safeNumber (feeConfig, 'maker_fee'),
'contractSize': this.safeString (market, 'contract_size'),
'contractSize': this.safeNumber (market, 'contract_size'),
'active': undefined,
'expiry': expiry,
'expiryDatetime': this.iso8601 (expiry),
Expand Down
2 changes: 1 addition & 1 deletion js/cryptocom.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ module.exports = class cryptocom extends Exchange {
type = 'future';
symbol = symbol + '-' + this.yymmdd (expiry);
}
const contractSize = this.safeString (market, 'contract_size');
const contractSize = this.safeNumber (market, 'contract_size');
const marketId = this.safeString (market, 'symbol');
const maxLeverage = this.safeNumber (market, 'max_leverage');
const active = this.safeValue (market, 'tradable');
Expand Down
2 changes: 1 addition & 1 deletion js/deribit.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ module.exports = class deribit extends Exchange {
'inverse': true,
'taker': this.safeNumber (market, 'taker_commission'),
'maker': this.safeNumber (market, 'maker_commission'),
'contractSize': this.safeString (market, 'contract_size'),
'contractSize': this.safeNumber (market, 'contract_size'),
'active': this.safeValue (market, 'is_active'),
'expiry': expiry,
'expiryDatetime': this.iso8601 (expiry),
Expand Down
4 changes: 2 additions & 2 deletions js/ftx.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ module.exports = class ftx extends Exchange {
'contract': contract,
'linear': true,
'inverse': false,
'contractSize': 1,
'contractSize': this.parseNumber ('1'),
'expiry': expiry,
'expiryDatetime': this.iso8601 (expiry),
'strike': undefined,
Expand Down Expand Up @@ -1975,7 +1975,7 @@ module.exports = class ftx extends Exchange {
'leverage': leverage,
'unrealizedPnl': this.parseNumber (unrealizedPnlString),
'contracts': this.parseNumber (contractsString),
'contractSize': this.parseNumber ('1'),
'contractSize': this.safeValue (market, 'contractSize'),
'marginRatio': marginRatio,
'liquidationPrice': this.parseNumber (liquidationPriceString),
'markPrice': this.parseNumber (markPriceString),
Expand Down
4 changes: 2 additions & 2 deletions js/gateio.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ module.exports = class gateio extends Exchange {
'inverse': inverse,
'taker': taker,
'maker': maker,
'contractSize': this.safeString (market, 'quanto_multiplier'),
'contractSize': this.safeNumber (market, 'quanto_multiplier'),
'expiry': expiry,
'expiryDatetime': this.iso8601 (expiry),
'strike': undefined,
Expand Down Expand Up @@ -2951,7 +2951,7 @@ module.exports = class gateio extends Exchange {
'leverage': this.safeNumber (position, 'leverage'),
'unrealizedPnl': this.parseNumber (unrealisedPnl),
'contracts': this.parseNumber (size),
'contractSize': this.safeNumber (market, 'contractSize'),
'contractSize': this.safeValue (market, 'contractSize'),
// realisedPnl: position['realised_pnl'],
'marginRatio': undefined,
'liquidationPrice': this.safeNumber (position, 'liq_price'),
Expand Down
2 changes: 1 addition & 1 deletion js/hitbtc3.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ module.exports = class hitbtc3 extends Exchange {
let linear = undefined;
let inverse = undefined;
if (contract) {
contractSize = '1';
contractSize = this.parseNumber ('1');
settleId = feeCurrencyId;
settle = this.safeCurrencyCode (settleId);
linear = ((quote !== undefined) && (quote === settle));
Expand Down
9 changes: 5 additions & 4 deletions js/huobi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ module.exports = class huobi extends Exchange {
symbol += '-' + this.yymmdd (expiry);
}
}
const contractSize = this.safeString (market, 'contract_size');
const contractSize = this.safeNumber (market, 'contract_size');
let pricePrecision = undefined;
let amountPrecision = undefined;
let costPrecision = undefined;
Expand Down Expand Up @@ -4775,7 +4775,8 @@ module.exports = class huobi extends Exchange {
market = this.safeMarket (this.safeString (position, 'contract_code'));
const symbol = market['symbol'];
const contracts = this.safeString (position, 'volume');
const contractSize = this.safeString (market, 'contractSize');
const contractSize = this.safeValue (market, 'contractSize');
const contractSizeString = this.numberToString (contractSize);
const entryPrice = this.safeNumber (position, 'cost_hold');
const initialMargin = this.safeString (position, 'position_margin');
const rawSide = this.safeString (position, 'direction');
Expand All @@ -4785,7 +4786,7 @@ module.exports = class huobi extends Exchange {
const leverage = this.safeString (position, 'lever_rate');
const percentage = Precise.stringMul (this.safeString (position, 'profit_rate'), '100');
const lastPrice = this.safeString (position, 'last_price');
const faceValue = Precise.stringMul (contracts, contractSize);
const faceValue = Precise.stringMul (contracts, contractSizeString);
let notional = undefined;
if (market['linear']) {
notional = Precise.stringMul (faceValue, lastPrice);
Expand All @@ -4804,7 +4805,7 @@ module.exports = class huobi extends Exchange {
'info': position,
'symbol': symbol,
'contracts': this.parseNumber (contracts),
'contractSize': this.parseNumber (contractSize),
'contractSize': contractSize,
'entryPrice': entryPrice,
'collateral': this.parseNumber (collateral),
'side': side,
Expand Down
4 changes: 2 additions & 2 deletions js/kucoinfutures.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ module.exports = class kucoinfutures extends kucoin {
'inverse': inverse,
'taker': this.safeNumber (market, 'takerFeeRate'),
'maker': this.safeNumber (market, 'makerFeeRate'),
'contractSize': Precise.stringAbs (this.safeString (market, 'multiplier')),
'contractSize': this.parseNumber (Precise.stringAbs (this.safeString (market, 'multiplier'))),
'expiry': expiry,
'expiryDatetime': this.iso8601 (expiry),
'precision': {
Expand Down Expand Up @@ -914,7 +914,7 @@ module.exports = class kucoinfutures extends kucoin {
'leverage': this.safeNumber (position, 'realLeverage'),
'unrealizedPnl': this.parseNumber (unrealisedPnl),
'contracts': this.parseNumber (Precise.stringAbs (size)),
'contractSize': this.safeNumber (market, 'contractSize'),
'contractSize': this.safeValue (market, 'contractSize'),
// realisedPnl: position['realised_pnl'],
'marginRatio': undefined,
'liquidationPrice': this.safeNumber (position, 'liquidationPrice'),
Expand Down
2 changes: 1 addition & 1 deletion js/mexc.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ module.exports = class mexc extends Exchange {
'inverse': false,
'taker': this.safeNumber (market, 'takerFeeRate'),
'maker': this.safeNumber (market, 'makerFeeRate'),
'contractSize': this.safeString (market, 'contractSize'),
'contractSize': this.safeNumber (market, 'contractSize'),
'active': (state === '0'),
'expiry': undefined,
'expiryDatetime': undefined,
Expand Down
4 changes: 2 additions & 2 deletions js/okex.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ module.exports = class okex extends Exchange {
const fees = this.safeValue2 (this.fees, type, 'trading', {});
let contractSize = undefined;
if (contract) {
contractSize = this.safeString (market, 'ctVal');
contractSize = this.safeNumber (market, 'ctVal');
}
const leverage = this.safeNumber (market, 'lever', 1);
return this.extend (fees, {
Expand Down Expand Up @@ -3171,7 +3171,7 @@ module.exports = class okex extends Exchange {
'unrealizedPnl': this.parseNumber (unrealizedPnlString),
'percentage': percentage,
'contracts': contracts,
'contractSize': this.parseNumber (market['contractSize']),
'contractSize': this.safeValue (market, 'contractSize'),
'markPrice': this.parseNumber (markPriceString),
'side': side,
'hedged': hedged,
Expand Down
2 changes: 1 addition & 1 deletion js/phemex.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ module.exports = class phemex extends Exchange {
};
const status = this.safeString (market, 'status');
const active = status === 'Listed';
const contractSize = this.safeString (market, 'contractSize');
const contractSize = this.safeNumber (market, 'contractSize');
return {
'id': id,
'symbol': symbol,
Expand Down
4 changes: 4 additions & 0 deletions php/Exchange.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46ebfce

Please sign in to comment.