Skip to content

Commit

Permalink
Price tool: fix for custom symbol names
Browse files Browse the repository at this point in the history
This bug was introduced in commit #beb4cdb0e7dce17cfe4bc16b127dd4b82ec44cf0.

It is now possible to use a custom symbol name to point to a specific data source and asset ID.

For example:

data_source_select: {
    ...
    ‘FARMB’ : [‘CoinGecko:seed2need'],
    ...
}
  • Loading branch information
nanonano committed Sep 29, 2021
1 parent fbfa56e commit dd56b9c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bittytax/price/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def _update_asset(self, symbol, data_source):

def _add_asset(self, symbol, data_source):
asset_id = data_source.split(':')[1]
# You can only add a new symbol for an id not being used
if asset_id in self.ids and self.assets[self.ids[asset_id]['symbol']]['id'] != asset_id:
if asset_id in self.ids:
self.assets[symbol] = {'id': asset_id, 'name': self.ids[asset_id]['name']}
self.ids[asset_id] = {'symbol': symbol, 'name': self.ids[asset_id]['name']}

Expand All @@ -147,6 +146,12 @@ def get_list(self):
asset_list[symbol] = []

asset_list[symbol].append({'id': c, 'name': self.ids[c]['name']})

# Include any custom symbols as well
for symbol in asset_list:
if self.assets[symbol] not in asset_list[symbol]:
asset_list[symbol].append(self.assets[symbol])

return asset_list
return {k: [{'id':None, 'name': v['name']}] for k, v in self.assets.items()}

Expand Down Expand Up @@ -285,9 +290,6 @@ def get_historical(self, asset, quote, timestamp, _asset_id=None):
'url': url} for d in json_resp['Data']},
timestamp)

def get_list(self):
return {k: [{'id':None, 'name': v['name']}] for k, v in self.assets.items()}

class CoinGecko(DataSourceBase):
def __init__(self):
super(CoinGecko, self).__init__()
Expand Down

0 comments on commit dd56b9c

Please sign in to comment.