moexapi 1.7.16__tar.gz → 1.7.18__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.16
3
+ Version: 1.7.18
4
4
  Summary: Python API for MOEX ISS
5
5
  Author-email: Aliaksei Rak <kventinel@gmail.com>
6
6
  License: MIT License
@@ -71,7 +71,10 @@ class Candle:
71
71
  self.volume /= mult
72
72
 
73
73
 
74
- def _merge_candles(first: list[Candle], second: list[Candle]) -> list[Candle]:
74
+ def _merge_candles(
75
+ first: list[Candle], second: list[Candle], preferred_currency: T.Optional[str] = None,
76
+ ) -> list[Candle]:
77
+ preferred_currency = tickers._sur_to_rub(preferred_currency)
75
78
  i = 0
76
79
  j = 0
77
80
  result: list[Candle] = []
@@ -83,7 +86,18 @@ def _merge_candles(first: list[Candle], second: list[Candle]) -> list[Candle]:
83
86
  result.append(second[j])
84
87
  j += 1
85
88
  else:
86
- result.append(Candle.merge(first[i], second[j]))
89
+ if first[i].currency == second[j].currency:
90
+ result.append(Candle.merge(first[i], second[j]))
91
+ elif second[j].currency == preferred_currency:
92
+ result.append(second[j])
93
+ elif first[i].currency == preferred_currency:
94
+ result.append(first[i])
95
+ else:
96
+ raise ValueError(
97
+ f"Can't select candle currency at {first[i].start}: "
98
+ f"{first[i].currency} and {second[j].currency}; "
99
+ f"preferred currency is {preferred_currency}"
100
+ )
87
101
  i += 1
88
102
  j += 1
89
103
  if i < len(first):
@@ -93,12 +107,14 @@ def _merge_candles(first: list[Candle], second: list[Candle]) -> list[Candle]:
93
107
  return result
94
108
 
95
109
 
96
- def _merge_candles_list(candles: list[list[Candle]]) -> list[Candle]:
110
+ def _merge_candles_list(
111
+ candles: list[list[Candle]], preferred_currency: T.Optional[str] = None,
112
+ ) -> list[Candle]:
97
113
  if len(candles) == 0:
98
114
  return []
99
115
  result = candles[0]
100
116
  for idx in range(1, len(candles)):
101
- result = _merge_candles(result, candles[idx])
117
+ result = _merge_candles(result, candles[idx], preferred_currency)
102
118
  return result
103
119
 
104
120
 
@@ -164,7 +180,7 @@ def _parse_candles(
164
180
  candles.append(
165
181
  _parse_candles_one_board(ticker, board, start_date=start_date, end_date=end_date, interval=interval)
166
182
  )
167
- return _merge_candles_list(candles)
183
+ return _merge_candles_list(candles, ticker.currency)
168
184
 
169
185
 
170
186
  def get_candles(
@@ -179,7 +195,7 @@ def get_candles(
179
195
  candles = []
180
196
  for t in prev_tickers:
181
197
  candles.append(_parse_candles(t, start_date=start_date, end_date=end_date, interval=interval))
182
- result = _merge_candles_list(candles)
198
+ result = _merge_candles_list(candles, ticker.currency)
183
199
  for split in ticker_splits:
184
200
  for candle in result:
185
201
  if candle.end.date() < split.date:
@@ -113,8 +113,12 @@ def _parse_history(
113
113
  start_date: T.Optional[datetime.date] = None,
114
114
  end_date: T.Optional[datetime.date] = None,
115
115
  ) -> list[History]:
116
+ # Bond denomination and board settlement currency can differ. Keep one
117
+ # turnover currency per day, preferring the ticker currency when available.
118
+ preferred_currency = tickers._sur_to_rub(ticker.currency)
116
119
  result: list[History] = []
117
120
  prev_date = start_date
121
+ boards = []
118
122
  while True:
119
123
  start_str = f"from={start_date.isoformat()}" if start_date else ""
120
124
  end_str = f"till={end_date.isoformat()}" if end_date else ""
@@ -122,7 +126,6 @@ def _parse_history(
122
126
  url = f"https://iss.moex.com/iss/history{ticker.market.path}/securities/{ticker.secid}.json{query}"
123
127
  response = utils.json_api_call(url)
124
128
  history = utils.prepare_dict(response, "history")
125
- boards = []
126
129
  for line in history:
127
130
  board = line["BOARDID"]
128
131
  if ticker.boards and board not in ticker.boards:
@@ -158,7 +161,16 @@ def _parse_history(
158
161
  if board in boards:
159
162
  continue
160
163
  boards.append(board)
161
- result[-1] = History.merge(result[-1], item)
164
+ if result[-1].currency == item.currency:
165
+ result[-1] = History.merge(result[-1], item)
166
+ elif item.currency == preferred_currency:
167
+ result[-1] = item
168
+ elif result[-1].currency != preferred_currency:
169
+ raise ValueError(
170
+ f"Can't select history currency for {ticker.secid} on {date}: "
171
+ f"{result[-1].currency} and {item.currency}; "
172
+ f"preferred currency is {preferred_currency}"
173
+ )
162
174
  else:
163
175
  boards = [board]
164
176
  result.append(item)
@@ -100,7 +100,7 @@ _ALL = Market("all")
100
100
  _STOCK = Market("stock", parent=_ALL, engines={"stock"})
101
101
  _EQUITY = Market("equity", parent=_STOCK, markets={"shares"})
102
102
  _SHARES = Market("shares", parent=_EQUITY, security_types={"common_share", "preferred_share", "depositary_receipt"})
103
- _ETFS = Market("etfs", parent=_EQUITY, security_types={"exchange_ppif"})
103
+ _ETFS = Market("etfs", parent=_EQUITY, security_types={"exchange_ppif", "etf_ppif"})
104
104
  _BONDS = Market("bonds", parent=_STOCK, markets={"bonds"})
105
105
  _FEDERAL_BONDS = Market(
106
106
  "federal bonds",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moexapi
3
- Version: 1.7.16
3
+ Version: 1.7.18
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.16"
7
+ version = "1.7.18"
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