|
22 | 22 | ) |
23 | 23 | from dipdup.datasources.datasource import IndexDatasource |
24 | 24 | from dipdup.datasources.tzkt.enums import TzktMessageType |
25 | | -from dipdup.models import BigMapAction, BigMapData, BlockData, Head, HeadBlockData, OperationData |
| 25 | +from dipdup.models import BigMapAction, BigMapData, BlockData, Head, HeadBlockData, OperationData, QuoteData |
26 | 26 | from dipdup.utils import groupby, split_by_chunks |
27 | 27 |
|
28 | 28 | OperationID = int |
@@ -537,6 +537,17 @@ async def get_big_maps( |
537 | 537 | big_maps.append(self.convert_big_map(bm)) |
538 | 538 | return big_maps |
539 | 539 |
|
| 540 | + async def get_quotes(self, level: int) -> QuoteData: |
| 541 | + """Get quote for block""" |
| 542 | + self._logger.info('Fetching quotes for level %s', level) |
| 543 | + quote_json = await self._http.request( |
| 544 | + 'get', |
| 545 | + url='v1/quotes', |
| 546 | + params={"level": level}, |
| 547 | + cache=True, |
| 548 | + ) |
| 549 | + return self.convert_quote(quote_json[0]) |
| 550 | + |
540 | 551 | async def add_index(self, index_config: ResolvedIndexConfigT) -> None: |
541 | 552 | """Register index config in internal mappings and matchers. Find and register subscriptions.""" |
542 | 553 |
|
@@ -866,6 +877,21 @@ def convert_head_block(cls, head_block_json: Dict[str, Any]) -> HeadBlockData: |
866 | 877 | quote_eth=Decimal(head_block_json['quoteEth']), |
867 | 878 | ) |
868 | 879 |
|
| 880 | + @classmethod |
| 881 | + def convert_quote(cls, quote_json: Dict[str, Any]) -> QuoteData: |
| 882 | + """Convert raw quote message from REST into dataclass""" |
| 883 | + return QuoteData( |
| 884 | + level=quote_json['level'], |
| 885 | + timestamp=cls._parse_timestamp(quote_json['timestamp']), |
| 886 | + btc=Decimal(quote_json['btc']), |
| 887 | + eur=Decimal(quote_json['eur']), |
| 888 | + usd=Decimal(quote_json['usd']), |
| 889 | + cny=Decimal(quote_json['cny']), |
| 890 | + jpy=Decimal(quote_json['jpy']), |
| 891 | + krw=Decimal(quote_json['krw']), |
| 892 | + eth=Decimal(quote_json['eth']), |
| 893 | + ) |
| 894 | + |
869 | 895 | async def _send(self, method: str, arguments: List[Dict[str, Any]], on_invocation=None) -> None: |
870 | 896 | client = self._get_client() |
871 | 897 | while client.transport.state != ConnectionState.connected: |
|
0 commit comments