Skip to content

Commit

Permalink
adding fetchCurrencies() for coinmarketcap, cryptopia, poloniex
Browse files Browse the repository at this point in the history
  • Loading branch information
mirror-neuron committed Dec 3, 2017
1 parent 9f8aee4 commit efbb3e5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 9 deletions.
21 changes: 12 additions & 9 deletions js/bittrex.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,23 @@ module.exports = class bittrex extends Exchange {
async fetchCurrencies () {
let response = await this.publicGetCurrencies ();
let currencies = response['result'];
let result = [];
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let result = {};
for (let i = 0; i < currencies.length; i++) {
let currency = currencies[i];
let id = currency['Currency'];
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
result.push ({
result[this.commonCurrencyCode (id)] = {
'id': id,
'info': currency,
'name': currency['CurrencyLong'],
'code': this.commonCurrencyCode (id),
'active': currency['IsActive'],
'fees': currency['TxFee'], // todo: redesign
'fee': currency['TxFee'], // todo: redesign
'precision': precision,
'limits': {
'amount': {
Expand All @@ -261,8 +260,12 @@ module.exports = class bittrex extends Exchange {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['TxFee'],
'max': Math.pow (10, precision['amount']),
},
},
});
};
}
return result;
}
Expand Down
47 changes: 47 additions & 0 deletions js/coinmarketcap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module.exports = class coinmarketcap extends Exchange {
'hasFetchOrderBook': false,
'hasFetchTrades': false,
'hasFetchTickers': true,
'hasFetchCurrencies': true,
'has': {
'fetchCurrencies': true,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/28244244-9be6312a-69ed-11e7-99c1-7c1797275265.jpg',
'api': 'https://api.coinmarketcap.com',
Expand Down Expand Up @@ -183,6 +187,49 @@ module.exports = class coinmarketcap extends Exchange {
return this.parseTicker (ticker, market);
}

async fetchCurrencies () {
let currencies = await this.publicGetTicker ({'limit': 0});
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let result = {};
for (let i = 0; i < currencies.length; i++) {
let currency = currencies[i];
let id = currency['symbol'];
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
result[this.commonCurrencyCode (id)] = {
'id': id,
'info': currency,
'name': currency['name'],
'active': undefined,
'fee': undefined, // todo: redesign
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': undefined,
'max': undefined,
},
},
};
}
return result;
}

sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'] + '/' + this.version + '/' + this.implodeParams (path, params);
let query = this.omit (params, this.extractParams (path));
Expand Down
48 changes: 48 additions & 0 deletions js/cryptopia.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = class cryptopia extends Exchange {
'hasFetchOpenOrders': true,
'hasFetchClosedOrders': true,
'hasFetchMyTrades': true,
'hasFetchCurrencies': true,
'hasDeposit': true,
'hasWithdraw': true,
// new metainfo interface
Expand All @@ -33,6 +34,7 @@ module.exports = class cryptopia extends Exchange {
'fetchOpenOrders': true,
'fetchClosedOrders': 'emulated',
'fetchMyTrades': true,
'fetchCurrencies': true,
'deposit': true,
'withdraw': true,
},
Expand Down Expand Up @@ -284,6 +286,52 @@ module.exports = class cryptopia extends Exchange {
return this.parseTrades (response['Data'], market);
}

async fetchCurrencies () {
let response = await this.publicGetCurrencies ();
let currencies = response['Data'];
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let result = {};
for (let i = 0; i < currencies.length; i++) {
let currency = currencies[i];
let id = currency['Symbol'];
if (currency['ListingStatus'] == 'Active') {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
result[this.commonCurrencyCode (id)] = {
'id': id,
'info': currency,
'name': currency['Name'],
'active': currency['Status'] == 'OK',
'fee': currency['WithdrawFee'],
'precision': precision,
'limits': {
'amount': {
'min': currency['MinBaseTrade'],
'max': Math.pow (10, precision['amount']),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['MinWithdraw'],
'max': currency['MaxWithdraw'],
},
},
};
}
}
return result;
}

async fetchBalance (params = {}) {
await this.loadMarkets ();
let response = await this.privatePostGetBalance ();
Expand Down
48 changes: 48 additions & 0 deletions js/poloniex.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = class poloniex extends Exchange {
'hasFetchOpenOrders': true,
'hasFetchClosedOrders': true,
'hasFetchTickers': true,
'hasFetchCurrencies': true,
'hasWithdraw': true,
'hasFetchOHLCV': true,
// new metainfo interface
Expand All @@ -34,6 +35,7 @@ module.exports = class poloniex extends Exchange {
'fetchOpenOrders': true,
'fetchClosedOrders': 'emulated',
'fetchTickers': true,
'fetchCurrencies': true,
'withdraw': true,
},
'timeframes': {
Expand Down Expand Up @@ -294,6 +296,52 @@ module.exports = class poloniex extends Exchange {
return result;
}

async fetchCurrencies () {
let currencies = await this.publicGetReturnCurrencies ();
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let ids = Object.keys (currencies);
let result = {};
for (let i = 0; i < ids.length; i++) {
let id = ids[i];
let currency = currencies[id];
if (currency['delisted'] == 0) {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
result[this.commonCurrencyCode (id)] = {
'id': id,
'info': currency,
'name': currency['name'],
'active': !currency['disabled'],
'fee': currency['txFee'], // todo: redesign
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['txFee'],
'max': Math.pow (10, precision['amount']),
},
},
};
}
}
return result;
}

async fetchTicker (symbol, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
Expand Down

0 comments on commit efbb3e5

Please sign in to comment.