moexapi 1.7.3__tar.gz → 1.7.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moexapi
3
- Version: 1.7.3
3
+ Version: 1.7.5
4
4
  Summary: Python API for MOEX ISS
5
5
  Author-email: Aliaksei Rak <kventinel@gmail.com>
6
6
  License: MIT License
@@ -17,7 +17,10 @@ Dividends = list[Dividend]
17
17
 
18
18
 
19
19
  def _get_dividends_for_one_ticker(ticker: tickers.Ticker):
20
- resp = utils.json_api_call(f"https://iss.moex.com/iss/securities/{ticker.secid}/dividends.json")['dividends']
20
+ response = utils.json_api_call(f"https://iss.moex.com/iss/securities/{ticker.secid}/dividends.json")
21
+ resp = response.get('dividends')
22
+ if resp is None:
23
+ return []
21
24
  columns = resp['columns']
22
25
  data = resp['data']
23
26
  dividends: Dividends = []
@@ -102,8 +102,23 @@ _EQUITY = Market("equity", parent=_STOCK, markets={"shares"})
102
102
  _SHARES = Market("shares", parent=_EQUITY, security_types={"common_share", "preferred_share", "depositary_receipt"})
103
103
  _ETFS = Market("etfs", parent=_EQUITY, security_types={"exchange_ppif"})
104
104
  _BONDS = Market("bonds", parent=_STOCK, markets={"bonds"})
105
- _FEDERAL_BONDS = Market("federal bonds", parent=_BONDS, boards={"TQOB"})
106
- _COMPANY_BONDS = Market("company bonds", parent=_BONDS, boards={"TQCB"})
105
+ _FEDERAL_BONDS = Market(
106
+ "federal bonds",
107
+ parent=_BONDS,
108
+ security_types={"cb_bond", "euro_bond", "ofz_bond"},
109
+ )
110
+ _COMPANY_BONDS = Market(
111
+ "company bonds",
112
+ parent=_BONDS,
113
+ security_types={
114
+ "corporate_bond",
115
+ "exchange_bond",
116
+ "ifi_bond",
117
+ "municipal_bond",
118
+ "state_bond",
119
+ "subfederal_bond",
120
+ },
121
+ )
107
122
  _INDEX = Market("index", parent=_STOCK, markets={"index"})
108
123
  _CURRENCY = Market("currency", parent=_ALL, engines={"currency"}, markets={"selt"}, boards={"CETS"})
109
124
 
@@ -37,6 +37,12 @@ def _sur_to_rub(currency: T.Optional[str]) -> T.Optional[str]:
37
37
  return currency
38
38
 
39
39
 
40
+ def _get_security_currency(security: dict) -> T.Optional[str]:
41
+ if FACEVALUEONSETTLEDATE in security or LOTVALUE in security:
42
+ return _sur_to_rub(security.get(FACEUNIT, "RUB"))
43
+ return _sur_to_rub(security.get(CURRENCY, "RUB"))
44
+
45
+
40
46
  class NotFindTicker(RuntimeError):
41
47
  def __init__(self, ticker, candidates):
42
48
  self.ticker = ticker
@@ -76,12 +82,12 @@ class TickerBoardInfo:
76
82
  securities = utils.prepare_dict(response, "securities")
77
83
  marketdata = utils.prepare_dict(response, "marketdata")
78
84
  assert len(securities) == len(marketdata)
79
- boards = []
85
+ boards: list[tuple[str, T.Optional[str]]] = []
80
86
  result = None
81
87
  for sec_line, market_line in zip(securities, marketdata):
82
88
  board = sec_line[BOARDID]
83
89
  if board != primary_board:
84
- boards.append(board)
90
+ boards.append((board, _get_security_currency(sec_line)))
85
91
  continue
86
92
  else:
87
93
  assert result is None, f"Second accurance of ticker {secid}: {result.boards[0]} vs {board}"
@@ -97,10 +103,7 @@ class TickerBoardInfo:
97
103
  lotvalue = sec_line.get(FACEVALUEONSETTLEDATE)
98
104
  if lotvalue is None:
99
105
  lotvalue = sec_line.get(LOTVALUE)
100
- if lotvalue is not None:
101
- currency = _sur_to_rub(sec_line.get(FACEUNIT, "RUB"))
102
- else:
103
- currency = _sur_to_rub(sec_line.get(CURRENCY, "RUB"))
106
+ currency = _get_security_currency(sec_line)
104
107
  rate = 1
105
108
  price = raw_price
106
109
  if currency is not None and currency != "RUB" and market != markets.Markets.CURRENCY and price is not None:
@@ -126,7 +129,7 @@ class TickerBoardInfo:
126
129
  value=market_line[VALTODAY],
127
130
  )
128
131
  if result:
129
- result.boards.extend(boards)
132
+ result.boards.extend(board for board, currency in boards if currency == result.currency)
130
133
  response = utils.json_api_call(f"https://iss.moex.com/iss/securities/{secid}.json")
131
134
  for line in utils.prepare_dict(response, "boards"):
132
135
  board = line[BOARDID.lower()]
@@ -134,6 +137,7 @@ class TickerBoardInfo:
134
137
  board not in result.boards
135
138
  and line["engine"] in market.engines
136
139
  and line["market"] in market.markets
140
+ and _sur_to_rub(line.get(CURRENCY.lower())) == result.currency
137
141
  ):
138
142
  result.boards.append(board)
139
143
  return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moexapi
3
- Version: 1.7.3
3
+ Version: 1.7.5
4
4
  Summary: Python API for MOEX ISS
5
5
  Author-email: Aliaksei Rak <kventinel@gmail.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "moexapi"
7
- version = "1.7.3"
7
+ version = "1.7.5"
8
8
  description = "Python API for MOEX ISS"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Aliaksei Rak", email = "kventinel@gmail.com" }]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes