Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ttodua committed Jul 4, 2022
1 parent 540d5d1 commit a7e2338
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions js/wavesexchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const Exchange = require ('./base/Exchange');
const { ArgumentsRequired, AuthenticationError, InsufficientFunds, InvalidOrder, AccountSuspended, ExchangeError, DuplicateOrderId, OrderNotFound, BadSymbol, ExchangeNotAvailable, BadRequest } = require ('./base/errors');
const { TICK_SIZE } = require ('./base/functions/number');
const Precise = require ('./base/Precise');

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -291,8 +292,9 @@ module.exports = class wavesexchange extends Exchange {
],
},
},
'precisionMode': TICK_SIZE,
'currencies': {
'WX': { 'id': 'EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc', 'numericId': undefined, 'code': 'WX', 'precision': 8 },
'WX': { 'id': 'EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc', 'numericId': undefined, 'code': 'WX', 'precision': this.parseNumber ('1e-8') },
},
'options': {
'allowedCandles': 1440,
Expand All @@ -304,7 +306,7 @@ module.exports = class wavesexchange extends Exchange {
'wavesAddress': undefined,
'withdrawFeeUSDN': 7420,
'withdrawFeeWAVES': 100000,
'wavesPrecision': 8,
'wavesPrecision': this.parseNumber ('1e-8'),
'messagePrefix': 'W', // W for production, T for testnet
'networks': {
'ERC20': 'ETH',
Expand Down Expand Up @@ -544,8 +546,8 @@ module.exports = class wavesexchange extends Exchange {
'strike': undefined,
'optionType': undefined,
'precision': {
'amount': this.safeInteger (entry, 'amountAssetDecimals'),
'price': this.safeInteger (entry, 'priceAssetDecimals'),
'amount': this.parseNumber (this.parsePrecision (this.safeString (entry, 'amountAssetDecimals'))),
'price': this.parseNumber (this.parsePrecision (this.safeString (entry, 'priceAssetDecimals'))),
},
'limits': {
'leverage': {
Expand Down Expand Up @@ -603,10 +605,12 @@ module.exports = class wavesexchange extends Exchange {

parseOrderBookSide (bookSide, market = undefined, limit = undefined) {
const precision = market['precision'];
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
const amountPrecision = Math.pow (10, precision['amount']);
const difference = precision['amount'] - precision['price'];
const pricePrecision = Math.pow (10, wavesPrecision - difference);
const precisionAmountDigits = this.precisionFromString (this.safeString (precision, 'amount'));
const precisionPriceDigits = this.precisionFromString (this.safeString (precision, 'price'));
const wavesPrecision = this.safeString (this.options, 'wavesPrecision', '1e-8');
const amountPrecision = Math.pow (10, precisionAmountDigits);
const difference = precisionAmountDigits - precisionPriceDigits;
const pricePrecision = Math.pow (10, this.precisionFromString (wavesPrecision) - difference);
const result = [];
for (let i = 0; i < bookSide.length; i++) {
const entry = bookSide[i];
Expand Down Expand Up @@ -704,13 +708,7 @@ module.exports = class wavesexchange extends Exchange {
}

async signIn (params = {}) {
/**
* @method
* @name wavesexchange#signIn
* @description sign in, must be called prior to using other authenticated methods
* @param {dict} params extra parameters specific to the wavesexchange api endpoint
* @returns response from exchange
*/
this.checkRequiredDependencies ();
if (!this.safeString (this.options, 'accessToken')) {
const prefix = 'ffffff01';
const expiresDelta = 60 * 60 * 24 * 7;
Expand Down Expand Up @@ -1174,17 +1172,22 @@ module.exports = class wavesexchange extends Exchange {

priceToPrecision (symbol, price) {
const market = this.markets[symbol];
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
const difference = market['precision']['amount'] - market['precision']['price'];
return parseInt (parseFloat (this.toPrecision (price, wavesPrecision - difference)));
const precision = market['precision'];
const precisionDigitsAmount = this.precisionFromString (this.safeString (precision, 'amount'));
const precisionDigitsPrice = this.precisionFromString (this.safeString (precision, 'price'));
const wavesPrecision = this.safeString (this.options, 'wavesPrecision', '1e-8');
const difference = precisionDigitsAmount - precisionDigitsPrice;
return parseInt (parseFloat (this.toPrecision (price, this.precisionFromString (wavesPrecision) - difference)));
}

amountToPrecision (symbol, amount) {
return parseInt (parseFloat (this.toPrecision (amount, this.markets[symbol]['precision']['amount'])));
const precisionAmountDigits = this.precisionFromString (this.safeString (this.markets[symbol]['precision'], 'amount'));
return parseInt (parseFloat (this.toPrecision (amount, precisionAmountDigits)));
}

currencyToPrecision (code, amount, networkCode = undefined) {
return parseInt (parseFloat (this.toPrecision (amount, this.currencies[code]['precision'])));
const precisionDigits = this.precisionFromString (this.safeString (this.currencies[code], 'precision'));
return parseInt (parseFloat (this.toPrecision (amount, precisionDigits)));
}

fromPrecision (amount, scale) {
Expand All @@ -1206,14 +1209,17 @@ module.exports = class wavesexchange extends Exchange {
}

currencyFromPrecision (currency, amount) {
const scale = this.currencies[currency]['precision'];
const scale = this.precisionFromString (this.safeString (this.currencies[currency], 'precision'));
return this.fromPrecision (amount, scale);
}

priceFromPrecision (symbol, price) {
const market = this.markets[symbol];
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
const scale = this.sum (wavesPrecision, market['precision']['price']) - market['precision']['amount'];
const precision = market['precision'];
const precisionAmountDigits = this.precisionFromString (this.safeString (precision, 'amount'));
const precisionPriceDigits = this.precisionFromString (this.safeString (precision, 'price'));
const wavesPrecision = this.safeString (this.options, 'wavesPrecision', '1e-8');
const scale = this.precisionFromString (wavesPrecision) - precisionAmountDigits + precisionPriceDigits;
return this.fromPrecision (price, scale);
}

Expand Down Expand Up @@ -1314,12 +1320,11 @@ module.exports = class wavesexchange extends Exchange {
if ((discountFeeAsset in balances) && (balances[discountFeeAsset]['free'] >= floatDiscountMatcherFee)) {
matcherFeeAssetId = discountFeeAssetId;
matcherFee = parseInt (discountMatcherFee);
} else {
throw new InsufficientFunds (this.id + ' not enough funds on none of the eligible asset fees (' + baseFeeAsset + ' or ' + discountFeeAsset + ')');
}
}
}
if (matcherFeeAssetId === undefined) {
throw new InsufficientFunds (this.id + ' not enough funds on none of the eligible asset fees');
}
amount = this.amountToPrecision (symbol, amount);
price = this.priceToPrecision (symbol, price);
const byteArray = [
Expand Down Expand Up @@ -1700,13 +1705,13 @@ module.exports = class wavesexchange extends Exchange {
const currency = this.safeCurrencyCode (this.safeString (order, 'feeAsset'));
fee = {
'currency': currency,
'fee': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'filledFee'))),
'cost': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'filledFee'))),
};
} else {
const currency = this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES'));
fee = {
'currency': currency,
'fee': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'matcherFee'))),
'cost': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'matcherFee'))),
};
}
return this.safeOrder ({
Expand Down

0 comments on commit a7e2338

Please sign in to comment.