Skip to content

Commit

Permalink
remove bitstamp markets_by_id incorrect usage
Browse files Browse the repository at this point in the history
  • Loading branch information
frosty00 committed Dec 27, 2022
1 parent ea4919d commit 1cdb2af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 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
29 changes: 8 additions & 21 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

0 comments on commit 1cdb2af

Please sign in to comment.