Skip to content

Commit

Permalink
feat: add support for BC Bitcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpater committed May 21, 2020
1 parent eb157a9 commit db140ed
Show file tree
Hide file tree
Showing 3 changed files with 9,761 additions and 0 deletions.
40 changes: 40 additions & 0 deletions drivers/bcbitcoin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const request = require('../lib/request');
const Ticker = require('../models/ticker');
const { parseToFloat } = require('../lib/utils.js');

module.exports = async () => {
const markets = await request('https://www.bcbitcoin.co.uk/api/products/');
const { Trades: trades } = await request('https://www.bcbitcoin.co.uk/api/trades/');

return markets.map((market) => {
const [base, quote] = market.id.split('-');

const twentyFourHoursAgoInSeconds = (Date.now() / 1000) - (24 * 60 * 60);
const tradesInLast24h = trades
.filter((trade) => trade.pair === market.id)
.filter((trade) => trade.timestamp >= twentyFourHoursAgoInSeconds);

let high;
let low;
let close;
let baseVolume;

if (tradesInLast24h.length) {
high = tradesInLast24h
.reduce((acc, value) => Math.max(acc, parseToFloat(value.price)), -Infinity);
low = tradesInLast24h
.reduce((acc, value) => Math.min(acc, parseToFloat(value.price)), Infinity);
close = parseToFloat(tradesInLast24h[tradesInLast24h.length - 1].price);
baseVolume = tradesInLast24h.reduce((acc, value) => acc + parseToFloat(value.amount), 0);
}

return new Ticker({
base,
quote,
high,
low,
close,
baseVolume,
});
});
};
1 change: 1 addition & 0 deletions drivers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.bancor = require('./bancor');
exports.bancor = require('./bancor');
exports.bankera = require('./bankera');
exports.barginex = require('./barginex');
exports.bcbitcoin = require('./bcbitcoin');
exports.bcex = require('./bcex');
exports.bequant = require('./bequant');
exports.bgogo = require('./bgogo');
Expand Down
Loading

0 comments on commit db140ed

Please sign in to comment.