|
5 | 5 |
|
6 | 6 | import cryptomarket.args as args |
7 | 7 | from cryptomarket.dataclasses.wsCandle import WSCandle |
8 | | -from cryptomarket.dataclasses.wsminiTicker import WSMiniTicker |
| 8 | +from cryptomarket.dataclasses.wsMiniTicker import WSMiniTicker |
9 | 9 | from cryptomarket.dataclasses.wsOrderBook import WSOrderBook |
10 | 10 | from cryptomarket.dataclasses.wsOrderBookTop import WSOrderBookTop |
| 11 | +from cryptomarket.dataclasses.wsPriceRate import WSPriceRate |
11 | 12 | from cryptomarket.dataclasses.wsTicker import WSTicker |
12 | 13 | from cryptomarket.dataclasses.wsTrade import WSTrade |
13 | 14 | from cryptomarket.exceptions import CryptomarketAPIException |
@@ -485,3 +486,38 @@ def intercept_feed(feed, feed_type): |
485 | 486 | params=params, |
486 | 487 | result_callback=result_callback |
487 | 488 | ) |
| 489 | + |
| 490 | + def subscribe_to_price_rates( |
| 491 | + self, |
| 492 | + callback: Callable[[Dict[str, WSPriceRate]], None], |
| 493 | + speed: Union[args.PriceRateSpeed, Literal['1s', '3s']], |
| 494 | + target_currency: Optional[str], |
| 495 | + currencies: Optional[List[str]] = None, |
| 496 | + result_callback: Optional[Callable[[ |
| 497 | + Union[CryptomarketAPIException, None], Union[List[str], None]], None]] = None, |
| 498 | + ): |
| 499 | + """subscribe to a feed of price rates |
| 500 | +
|
| 501 | + subscription is for all currencies or specified currencies (bases), against a target currency (quote). indexed by currency id (bases) |
| 502 | +
|
| 503 | + https://api.exchange.cryptomkt.com/#subscribe-to-price-rates |
| 504 | +
|
| 505 | + :param callback: callable that recieves a dict of mini tickers, indexed by symbol. |
| 506 | + :param speed: The speed of the feed. '1s' or '3s' |
| 507 | + :param target_currency: quote currency for the price rates |
| 508 | + :param currencies: Optional. A list of currencies ids (as bases) to subscribe to. If not provided it subscribes to all currencies |
| 509 | + :param result_callback: A callable of two arguments, takes either a CryptomarketAPIException, or the list of correctly subscribed currencies |
| 510 | + """ |
| 511 | + if currencies is None: |
| 512 | + currencies = ['*'] |
| 513 | + params = args.DictBuilder().currencies_as_list(currencies).speed(speed).target_currency(target_currency).build() |
| 514 | + |
| 515 | + def intercept_feed(feed, feed_type): |
| 516 | + callback({key: from_dict(data_class=WSPriceRate, data=feed[key]) |
| 517 | + for key in feed}) |
| 518 | + self._send_channeled_subscription( |
| 519 | + channel=f'price/rate/{speed}', |
| 520 | + callback=intercept_feed, |
| 521 | + params=params, |
| 522 | + result_callback=result_callback |
| 523 | + ) |
0 commit comments