Skip to content

Commit 128092e

Browse files
authored
Merge pull request ccxt#6519 from hroff-1902/patch-3
python base exchange: expose lists of base and quote currencies
2 parents 1ae5405 + 423a2a1 commit 128092e

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

js/base/Exchange.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,22 +635,26 @@ module.exports = class Exchange {
635635
if (currencies) {
636636
this.currencies = deepExtend (currencies, this.currencies)
637637
} else {
638-
const baseCurrencies =
638+
let baseCurrencies =
639639
values.filter (market => 'base' in market)
640640
.map (market => ({
641641
id: market.baseId || market.base,
642642
numericId: (market.baseNumericId !== undefined) ? market.baseNumericId : undefined,
643643
code: market.base,
644644
precision: market.precision ? (market.precision.base || market.precision.amount) : 8,
645645
}))
646-
const quoteCurrencies =
646+
let quoteCurrencies =
647647
values.filter (market => 'quote' in market)
648648
.map (market => ({
649649
id: market.quoteId || market.quote,
650650
numericId: (market.quoteNumericId !== undefined) ? market.quoteNumericId : undefined,
651651
code: market.quote,
652652
precision: market.precision ? (market.precision.quote || market.precision.price) : 8,
653653
}))
654+
baseCurrencies = sortBy (baseCurrencies, 'code')
655+
quoteCurrencies = sortBy (quoteCurrencies, 'code')
656+
this.baseCurrencies = indexBy (baseCurrencies, 'code')
657+
this.quoteCurrencies = indexBy (quoteCurrencies, 'code')
654658
const allCurrencies = baseCurrencies.concat (quoteCurrencies)
655659
const groupedCurrencies = groupBy (allCurrencies, 'code')
656660
const currencies = Object.keys (groupedCurrencies).map (code =>

php/base/Exchange.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ public function __construct($options = array()) {
817817
$this->symbols = null;
818818
$this->ids = null;
819819
$this->currencies = array();
820+
$this->base_currencies = null;
821+
$this->quote_currencies = null;
820822
$this->balance = array();
821823
$this->orderbooks = array();
822824
$this->tickers = array();
@@ -1483,7 +1485,11 @@ public function set_markets($markets, $currencies = null) {
14831485
}, array_filter($values, function ($market) {
14841486
return array_key_exists('quote', $market);
14851487
}));
1486-
$currencies = static::index_by(array_merge($base_currencies, $quote_currencies), 'code');
1488+
$base_currencies = static::sort_by($base_currencies, 'code');
1489+
$quote_currencies = static::sort_by($quote_currencies, 'code');
1490+
$this->base_currencies = static::index_by($base_currencies, 'code');
1491+
$this->quote_currencies = static::index_by($quote_currencies, 'code');
1492+
$currencies = array_merge($this->base_currencies, $this->quote_currencies);
14871493
$this->currencies = array_replace_recursive($currencies, $this->currencies);
14881494
}
14891495
$this->currencies_by_id = static::index_by(array_values($this->currencies), 'id');

python/ccxt/base/exchange.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ class Exchange(object):
216216
transactions = None
217217
ohlcvs = None
218218
tickers = None
219+
base_currencies = None
220+
quote_currencies = None
219221
currencies = None
220222
options = None # Python does not allow to define properties in run-time with setattr
221223
accounts = None
@@ -1255,6 +1257,10 @@ def set_markets(self, markets, currencies=None):
12551257
)
12561258
) if 'precision' in market else 8,
12571259
} for market in values if 'quote' in market]
1260+
base_currencies = self.sort_by(base_currencies, 'code')
1261+
quote_currencies = self.sort_by(quote_currencies, 'code')
1262+
self.base_currencies = self.index_by(base_currencies, 'code')
1263+
self.quote_currencies = self.index_by(quote_currencies, 'code')
12581264
currencies = self.sort_by(base_currencies + quote_currencies, 'code')
12591265
self.currencies = self.deep_extend(self.index_by(currencies, 'code'), self.currencies)
12601266
self.currencies_by_id = self.index_by(list(self.currencies.values()), 'id')

0 commit comments

Comments
 (0)