Skip to content

Commit

Permalink
Fix for non-RUB bonds quotes downloading from MOEX.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Feb 21, 2024
1 parent 321a666 commit 7f03264
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions jal/net/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ def MOEX_download_info(asset_code, currency='') -> dict:
boards_list = [board.attrib for board in boards]
primary_board = [x for x in boards_list if "is_primary" in x and x["is_primary"] == '1']
if primary_board:
if currency == 'USD':
board_id = primary_board[0]['boardid'][:-1] + 'D'
elif currency == 'EUR':
board_id = primary_board[0]['boardid'][:-1] + 'E'
else:
board_id = primary_board[0]['boardid']
board_id = primary_board[0]['boardid']
if primary_board[0]['currencyid'] != currency and primary_board[0]['market'] != 'bonds':
if currency == 'USD':
board_id = board_id[:-1] + 'D'
if currency == 'EUR':
board_id = board_id[:-1] + 'E'
board = [x for x in boards_list if "boardid" in x and x["boardid"] == board_id]
if board:
asset.update({'engine': board[0]['engine'],
Expand Down
11 changes: 9 additions & 2 deletions tests/test_downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,22 @@ def test_MOEX_downloader(prepare_db_moex):


def test_MOEX_downloader_USD(prepare_db_moex):
create_assets([('FXGD', 'FinEx Gold ETF', 'IE00B8XB7377', 2, PredefinedAsset.ETF, 0)]) # ID = 8
create_assets([('FXGD', 'FinEx Gold ETF', 'IE00B8XB7377', 2, PredefinedAsset.ETF, 0)]) # ID = 9
create_assets([('ГазКЗ-30Д', 'Газпром капитал ООО ЗО30-1-Д', 'RU000A105SG2', 2, PredefinedAsset.Bond, 0)])

JalAsset(9).add_symbol('FXGD', 1, 'FinEx Gold ETF - RUB')
usd_quotes = pd.DataFrame({'Close': [Decimal('12.02'), Decimal('11.90')],
'Date': [datetime(2021, 12, 13), datetime(2021, 12, 14)]})
usd_quotes = usd_quotes.set_index('Date')
downloader = QuoteDownloader()
quotes_downloaded = downloader.MOEX_DataReader(JalAsset(9), 2, 1639353600, 1639440000, update_symbol=False)
quotes_downloaded = downloader.MOEX_DataReader(JalAsset(9), 2, d2t(211213), d2t(211214), update_symbol=False)
assert_frame_equal(usd_quotes, quotes_downloaded)

bond_usd_quotes = pd.DataFrame({'Close': [Decimal('846.509'), Decimal('844.998')],
'Date': [datetime(2024, 2, 13), datetime(2024, 2, 14)]})
bond_usd_quotes = bond_usd_quotes.set_index('Date')
bond_quotes = downloader.MOEX_DataReader(JalAsset(10), 2, d2t(240213), d2t(240214))
assert_frame_equal(bond_quotes, bond_usd_quotes)

def test_NYSE_downloader(prepare_db):
create_stocks([('AAPL', '')], currency_id=2) # id = 4
Expand Down

0 comments on commit 7f03264

Please sign in to comment.