From bed8520bc88728fa829c4e6cc6c83be8dc30b9dd Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 18 Nov 2021 11:55:42 -0500 Subject: [PATCH] Write prices on fetch-all --- cli.py | 9 +++++++-- mev_inspect/prices.py | 2 +- mev_inspect/schemas/prices.py | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cli.py b/cli.py index 5e04f6a..fd3a30e 100644 --- a/cli.py +++ b/cli.py @@ -5,6 +5,7 @@ import sys import click from mev_inspect.concurrency import coro +from mev_inspect.crud.prices import write_prices from mev_inspect.db import get_inspect_session, get_trace_session from mev_inspect.inspector import MEVInspector from mev_inspect.prices import fetch_all_supported_prices @@ -83,9 +84,13 @@ async def inspect_many_blocks_command( @cli.command() @coro async def fetch_all_prices(): - print("fetching") + inspect_db_session = get_inspect_session() + + print("Fetching prices") prices = await fetch_all_supported_prices() - print(prices[0]) + + print("Writing prices") + write_prices(inspect_db_session, prices) def get_rpc_url() -> str: diff --git a/mev_inspect/prices.py b/mev_inspect/prices.py index 8f0ac4a..8abe23d 100644 --- a/mev_inspect/prices.py +++ b/mev_inspect/prices.py @@ -21,7 +21,7 @@ async def fetch_all_supported_prices() -> List[Price]: price = Price( token_address=token_address, usd_price=usd_price, - timestamp_seconds=timestamp_seconds, + timestamp=timestamp_seconds, ) prices.append(price) diff --git a/mev_inspect/schemas/prices.py b/mev_inspect/schemas/prices.py index 55abe0f..40e5c48 100644 --- a/mev_inspect/schemas/prices.py +++ b/mev_inspect/schemas/prices.py @@ -1,7 +1,9 @@ +from datetime import datetime + from pydantic import BaseModel class Price(BaseModel): token_address: str - timestamp_seconds: int + timestamp: datetime usd_price: float