Skip to content

Commit

Permalink
Merge pull request #16218 from frosty00/markets_conflict_derived_classes
Browse files Browse the repository at this point in the history
remove markets_by_id deprecated usage in derived classes
  • Loading branch information
frosty00 committed Dec 27, 2022
2 parents c300587 + f18c2a5 commit 9f7d895
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 189 deletions.
19 changes: 13 additions & 6 deletions js/base/Exchange.js
Expand Up @@ -987,12 +987,16 @@ module.exports = class Exchange {
let average = this.omitZero (this.safeString (order, 'average'));
let price = this.omitZero (this.safeString (order, 'price'));
let lastTradeTimeTimestamp = this.safeInteger (order, 'lastTradeTimestamp');
let symbol = this.safeString (order, 'symbol');
let side = this.safeString (order, 'side');
const parseFilled = (filled === undefined);
const parseCost = (cost === undefined);
const parseLastTradeTimeTimestamp = (lastTradeTimeTimestamp === undefined);
const fee = this.safeValue (order, 'fee');
const parseFee = (fee === undefined);
const parseFees = this.safeValue (order, 'fees') === undefined;
const parseSymbol = symbol === undefined;
const parseSide = side === undefined;
const shouldParseFees = parseFee || parseFees;
const fees = this.safeValue (order, 'fees', []);
let trades = [];
Expand All @@ -1001,12 +1005,7 @@ module.exports = class Exchange {
const oldNumber = this.number;
// we parse trades as strings here!
this.number = String;
trades = this.parseTrades (rawTrades, market, undefined, undefined, {
'symbol': order['symbol'],
'side': order['side'],
'type': order['type'],
'order': order['id'],
});
trades = this.parseTrades (rawTrades, market);
this.number = oldNumber;
let tradesLength = 0;
const isArray = Array.isArray (trades);
Expand Down Expand Up @@ -1043,6 +1042,12 @@ module.exports = class Exchange {
if (parseCost && (tradeCost !== undefined)) {
cost = Precise.stringAdd (cost, tradeCost);
}
if (parseSymbol) {
symbol = this.safeString (trade, 'symbol');
}
if (parseSide) {
side = this.safeString (trade, 'side');
}
const tradeTimestamp = this.safeValue (trade, 'timestamp');
if (parseLastTradeTimeTimestamp && (tradeTimestamp !== undefined)) {
if (lastTradeTimeTimestamp === undefined) {
Expand Down Expand Up @@ -1182,6 +1187,8 @@ module.exports = class Exchange {
postOnly = timeInForce === 'PO';
}
return this.extend (order, {
'symbol': symbol,
'side': side,
'lastTradeTimestamp': lastTradeTimeTimestamp,
'price': this.parseNumber (price),
'amount': this.parseNumber (amount),
Expand Down
21 changes: 3 additions & 18 deletions js/bitfinex.js
Expand Up @@ -880,24 +880,9 @@ module.exports = class bitfinex extends Exchange {

parseTicker (ticker, market = undefined) {
const timestamp = this.safeTimestamp (ticker, 'timestamp');
let symbol = undefined;
if (market !== undefined) {
symbol = market['symbol'];
} else if ('pair' in ticker) {
const marketId = this.safeString (ticker, 'pair');
if (marketId !== undefined) {
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
symbol = market['symbol'];
} else {
const baseId = marketId.slice (0, 3);
const quoteId = marketId.slice (3, 6);
const base = this.safeCurrencyCode (baseId);
const quote = this.safeCurrencyCode (quoteId);
symbol = base + '/' + quote;
}
}
}
const marketId = this.safeString (market, 'pair');
market = this.safeMarket (marketId, market);
const symbol = market['symbol'];
const last = this.safeString (ticker, 'last_price');
return this.safeTicker ({
'symbol': symbol,
Expand Down
34 changes: 7 additions & 27 deletions js/bitfinex2.js
Expand Up @@ -1153,12 +1153,10 @@ module.exports = class bitfinex2 extends Exchange {
const result = {};
for (let i = 0; i < tickers.length; i++) {
const ticker = tickers[i];
const id = ticker[0];
if (id in this.markets_by_id) {
const market = this.markets_by_id[id];
const symbol = market['symbol'];
result[symbol] = this.parseTicker (ticker, market);
}
const marketId = this.safeString (ticker, 0);
const market = this.safeMarket (marketId);
const symbol = market['symbol'];
result[symbol] = this.parseTicker (ticker, market);
}
return this.filterByArray (result, 'symbol', symbols);
}
Expand Down Expand Up @@ -1252,12 +1250,7 @@ module.exports = class bitfinex2 extends Exchange {
const timestamp = this.safeInteger (trade, timestampIndex);
if (isPrivate) {
const marketId = trade[1];
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
symbol = market['symbol'];
} else {
symbol = this.parseSymbol (marketId);
}
symbol = this.parseSymbol (marketId);
orderId = this.safeString (trade, 3);
const maker = this.safeInteger (trade, 8);
takerOrMaker = (maker === 1) ? 'maker' : 'taker';
Expand All @@ -1272,11 +1265,6 @@ module.exports = class bitfinex2 extends Exchange {
const orderType = trade[6];
type = this.safeString (this.options['exchangeTypes'], orderType);
}
if (symbol === undefined) {
if (market !== undefined) {
symbol = market['symbol'];
}
}
return this.safeTrade ({
'id': id,
'timestamp': timestamp,
Expand Down Expand Up @@ -1441,16 +1429,8 @@ module.exports = class bitfinex2 extends Exchange {

parseOrder (order, market = undefined) {
const id = this.safeString (order, 0);
let symbol = undefined;
const marketId = this.safeString (order, 3);
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
} else {
symbol = this.parseSymbol (marketId);
}
if ((symbol === undefined) && (market !== undefined)) {
symbol = market['symbol'];
}
const symbol = this.parseSymbol (marketId);
// https://github.com/ccxt/ccxt/issues/6686
// const timestamp = this.safeTimestamp (order, 5);
const timestamp = this.safeInteger (order, 5);
Expand All @@ -1477,7 +1457,7 @@ module.exports = class bitfinex2 extends Exchange {
price = undefined;
stopPrice = this.safeNumber (order, 16);
if (orderType === 'EXCHANGE STOP LIMIT') {
price = this.safeNumber (order, 19);
price = this.safeString (order, 19);
}
}
let status = undefined;
Expand Down
5 changes: 1 addition & 4 deletions js/bitget.js
Expand Up @@ -1531,10 +1531,7 @@ module.exports = class bitget extends Exchange {
// usdtVolume: '5552388715.9215'
// }
//
let marketId = this.safeString (ticker, 'symbol');
if (!(marketId in this.markets_by_id)) {
marketId += '_SPBL';
}
const marketId = this.safeString (ticker, 'symbol');
const symbol = this.safeSymbol (marketId, market);
const high = this.safeString (ticker, 'high24h');
const low = this.safeString (ticker, 'low24h');
Expand Down
33 changes: 9 additions & 24 deletions js/bitstamp.js
Expand Up @@ -767,11 +767,11 @@ module.exports = class bitstamp extends Exchange {
if (numCurrencyIds === 2) {
let marketId = currencyIds[0] + currencyIds[1];
if (marketId in this.markets_by_id) {
return this.markets_by_id[marketId];
return this.safeMarket (marketId);
}
marketId = currencyIds[1] + currencyIds[0];
if (marketId in this.markets_by_id) {
return this.markets_by_id[marketId];
return this.safeMarket (marketId);
}
}
return undefined;
Expand Down Expand Up @@ -825,24 +825,14 @@ module.exports = class bitstamp extends Exchange {
const orderId = this.safeString (trade, 'order_id');
const type = undefined;
let costString = this.safeString (trade, 'cost');
let rawBaseId = undefined;
let rawQuoteId = undefined;
let rawMarketId = undefined;
if (market === undefined) {
const keys = Object.keys (trade);
for (let i = 0; i < keys.length; i++) {
const currentKey = keys[i];
if (currentKey !== 'order_id' && currentKey.indexOf ('_') >= 0) {
const marketId = currentKey.replace ('_', '');
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
} else {
rawMarketId = currentKey;
const parts = currentKey.split ('_');
rawBaseId = this.safeString (parts, 0);
rawQuoteId = this.safeString (parts, 1);
market = this.safeMarket (marketId);
}
rawMarketId = currentKey;
market = this.safeMarket (rawMarketId, market, '_');
}
}
}
Expand All @@ -852,13 +842,10 @@ module.exports = class bitstamp extends Exchange {
market = this.getMarketFromTrade (trade);
}
const feeCostString = this.safeString (trade, 'fee');
const feeCurrency = (market['quote'] !== undefined) ? market['quote'] : rawQuoteId;
const baseId = (market['baseId'] !== undefined) ? market['baseId'] : rawBaseId;
const quoteId = (market['quoteId'] !== undefined) ? market['quoteId'] : rawQuoteId;
const priceId = (rawMarketId !== undefined) ? rawMarketId : market['marketId'];
priceString = this.safeString (trade, priceId, priceString);
amountString = this.safeString (trade, baseId, amountString);
costString = this.safeString (trade, quoteId, costString);
const feeCurrency = market['quote'];
priceString = this.safeString (trade, rawMarketId, priceString);
amountString = this.safeString (trade, market['baseId'], amountString);
costString = this.safeString (trade, market['quoteId'], costString);
symbol = market['symbol'];
const datetimeString = this.safeString2 (trade, 'date', 'datetime');
let timestamp = undefined;
Expand Down Expand Up @@ -1813,9 +1800,7 @@ module.exports = class bitstamp extends Exchange {
for (let i = 0; i < keys.length; i++) {
if (keys[i].indexOf ('_') >= 0) {
const marketId = keys[i].replace ('_', '');
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
}
market = this.safeMarket (marketId, market);
}
}
// if the market is still not defined
Expand Down
4 changes: 2 additions & 2 deletions js/huobi.js
Expand Up @@ -5215,8 +5215,8 @@ module.exports = class huobi extends Exchange {
'datetime': this.iso8601 (timestamp),
};
}
const market = this.markets_by_id[this.safeString (rate, 'symbol')];
const symbol = market['symbol'];
const marketId = this.safeString (rate, 'symbol');
const symbol = this.safeSymbol (marketId);
rates[symbol] = symbolRates;
}
return rates;
Expand Down
2 changes: 1 addition & 1 deletion js/indodax.js
Expand Up @@ -662,7 +662,7 @@ module.exports = class indodax extends Exchange {
for (let i = 0; i < marketIds.length; i++) {
const marketId = marketIds[i];
const marketOrders = rawOrders[marketId];
market = this.markets_by_id[marketId];
market = this.safeMarket (marketId);
const parsedOrders = this.parseOrders (marketOrders, market, since, limit);
exchangeOrders = this.arrayConcat (exchangeOrders, parsedOrders);
}
Expand Down
40 changes: 19 additions & 21 deletions js/pro/bitfinex.js
Expand Up @@ -113,30 +113,28 @@ module.exports = class bitfinex extends bitfinexRest {
const marketId = this.safeString (subscription, 'pair');
const messageHash = channel + ':' + marketId;
const tradesLimit = this.safeInteger (this.options, 'tradesLimit', 1000);
if (marketId in this.markets_by_id) {
const market = this.markets_by_id[marketId];
const symbol = market['symbol'];
const data = this.safeValue (message, 1);
let stored = this.safeValue (this.trades, symbol);
if (stored === undefined) {
stored = new ArrayCache (tradesLimit);
this.trades[symbol] = stored;
const market = this.safeMarket (marketId);
const symbol = market['symbol'];
const data = this.safeValue (message, 1);
let stored = this.safeValue (this.trades, symbol);
if (stored === undefined) {
stored = new ArrayCache (tradesLimit);
this.trades[symbol] = stored;
}
if (Array.isArray (data)) {
const trades = this.parseTrades (data, market);
for (let i = 0; i < trades.length; i++) {
stored.append (trades[i]);
}
if (Array.isArray (data)) {
const trades = this.parseTrades (data, market);
for (let i = 0; i < trades.length; i++) {
stored.append (trades[i]);
}
} else {
const second = this.safeString (message, 1);
if (second !== 'tu') {
return;
}
const trade = this.parseTrade (message, market);
stored.append (trade);
} else {
const second = this.safeString (message, 1);
if (second !== 'tu') {
return;
}
client.resolve (stored, messageHash);
const trade = this.parseTrade (message, market);
stored.append (trade);
}
client.resolve (stored, messageHash);
return message;
}

Expand Down
23 changes: 7 additions & 16 deletions js/pro/bitstamp.js
Expand Up @@ -257,23 +257,14 @@ module.exports = class bitstamp extends bitstampRest {
}
const id = this.safeString (trade, 'id');
const timestamp = parseInt (microtimestamp / 1000);
const price = this.safeFloat (trade, 'price');
const amount = this.safeFloat (trade, 'amount');
let cost = undefined;
if ((price !== undefined) && (amount !== undefined)) {
cost = price * amount;
}
let symbol = undefined;
const price = this.safeString (trade, 'price');
const amount = this.safeString (trade, 'amount');
const marketId = this.safeString (trade, 's');
if (marketId in this.markets_by_id) {
market = this.markets_by_id[marketId];
}
if ((symbol === undefined) && (market !== undefined)) {
symbol = market['symbol'];
}
market = this.safeMarket (marketId, market);
const symbol = market['symbol'];
let side = this.safeInteger (trade, 'type');
side = (side === 0) ? 'buy' : 'sell';
return {
return this.safeTrade ({
'info': trade,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
Expand All @@ -285,9 +276,9 @@ module.exports = class bitstamp extends bitstampRest {
'side': side,
'price': price,
'amount': amount,
'cost': cost,
'cost': undefined,
'fee': undefined,
};
}, market);
}

handleTrade (client, message) {
Expand Down

0 comments on commit 9f7d895

Please sign in to comment.