Skip to content

Commit

Permalink
BitBay fetchTrades rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ndubel authored Oct 6, 2019
1 parent ea91f5f commit 307365d
Showing 1 changed file with 30 additions and 87 deletions.
117 changes: 30 additions & 87 deletions js/bitbay.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,16 +740,7 @@ module.exports = class bitbay extends Exchange {
return this.safeString (types, type, type);
}

parseTrade (trade, market) {
if ('tid' in trade) {
return this.parsePublicTrade (trade, market);
} else {
return this.parseMyTrade (trade, market);
}
}

parseMyTrade (trade, market = undefined) {
//
parseTrade (trade, market = undefined) {
// {
// amount: "0.29285199",
// commissionValue: "0.00125927",
Expand All @@ -762,14 +753,23 @@ module.exports = class bitbay extends Exchange {
// userAction: "Buy",
// wasTaker: true,
// }
//
const timestamp = this.safeInteger (trade, 'time');
// Public trades
// { id: 'df00b0da-e5e0-11e9-8c19-0242ac11000a',
// t: '1570108958831',
// a: '0.04776653',
// r: '0.02145854',
// ty: 'Sell'
// }
const timestamp = this.safeInteger2 (trade, 'time', 't');
const userAction = this.safeString (trade, 'userAction');
const side = (userAction === 'Buy') ? 'buy' : 'sell';
const wasTaker = this.safeValue (trade, 'wasTaker');
const takerOrMaker = wasTaker ? 'taker' : 'maker';
const price = this.safeFloat (trade, 'rate');
const amount = this.safeFloat (trade, 'amount');
let takerOrMaker = undefined;
if (wasTaker !== undefined) {
takerOrMaker = wasTaker ? 'taker' : 'maker';
}
const price = this.safeFloat2 (trade, 'rate', 'r');
const amount = this.safeFloat2 (trade, 'amount', 'a');
let cost = undefined;
if (amount !== undefined) {
if (price !== undefined) {
Expand Down Expand Up @@ -809,7 +809,10 @@ module.exports = class bitbay extends Exchange {
}
const order = this.safeString (trade, 'offerId');
// todo: check this logic
const type = order ? 'limit' : 'market';
let type = undefined;
if (order !== undefined) {
type = order ? 'limit' : 'market';
}
return {
'id': this.safeString (trade, 'id'),
'order': order,
Expand All @@ -827,82 +830,22 @@ module.exports = class bitbay extends Exchange {
};
}

parsePublicTrade (trade, market = undefined) {
//
// {
// "date":1459608665,
// "price":0.02722571,
// "type":"sell",
// "amount":1.08112001,
// "tid":"0"
// }
//
const timestamp = this.safeTimestamp (trade, 'date');
const id = this.safeString (trade, 'tid');
const type = undefined;
const side = this.safeString (trade, 'type');
const price = this.safeFloat (trade, 'price');
const amount = this.safeFloat (trade, 'amount');
let cost = undefined;
if (amount !== undefined) {
if (price !== undefined) {
cost = price * amount;
}
}
let symbol = undefined;
if (market !== undefined) {
symbol = market['symbol'];
}
return {
'id': id,
'info': trade,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': symbol,
'type': type,
'side': side,
'order': undefined,
'takerOrMaker': undefined,
'price': price,
'amount': amount,
'cost': cost,
'fee': undefined,
};
}

async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
const market = this.market (symbol);
const tradingSymbol = market['baseId'] + '-' + market['quoteId'];
const request = {
'id': market['id'],
'symbol': tradingSymbol,
};
const response = await this.publicGetIdTrades (this.extend (request, params));
//
// [
// {
// "date":1459608665,
// "price":0.02722571,
// "type":"sell",
// "amount":1.08112001,
// "tid":"0"
// },
// {
// "date":1459698930,
// "price":0.029,
// "type":"buy",
// "amount":0.444188,
// "tid":"1"
// },
// {
// "date":1459726670,
// "price":0.029,
// "type":"buy",
// "amount":0.25459599,
// "tid":"2"
// }
// ]
//
return this.parseTrades (response, market, since, limit);
if (since !== undefined) {
request['fromTime'] = since - 1; // result does not include exactly `since` time therefore decrease by 1
}
if (limit !== undefined) {
request['limit'] = limit; // default - 10, max - 300
}
const response = await this.v1_01PublicGetTradingTransactionsSymbol (this.extend (request, params));
const items = this.safeValue (response, 'items');
return this.parseTrades (items, symbol, since, limit);
}

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

0 comments on commit 307365d

Please sign in to comment.