Write prices. Ignore duplicates
This commit is contained in:
parent
bed8520bc8
commit
5b59427d4f
17
mev_inspect/crud/prices.py
Normal file
17
mev_inspect/crud/prices.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.postgresql import insert
|
||||||
|
|
||||||
|
from mev_inspect.models.prices import PriceModel
|
||||||
|
from mev_inspect.schemas.prices import Price
|
||||||
|
|
||||||
|
|
||||||
|
def write_prices(db_session, prices: List[Price]) -> None:
|
||||||
|
insert_statement = (
|
||||||
|
insert(PriceModel.__table__)
|
||||||
|
.values([price.dict() for price in prices])
|
||||||
|
.on_conflict_do_nothing()
|
||||||
|
)
|
||||||
|
|
||||||
|
db_session.execute(insert_statement)
|
||||||
|
db_session.commit()
|
11
mev_inspect/models/prices.py
Normal file
11
mev_inspect/models/prices.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from sqlalchemy import Column, Numeric, String, TIMESTAMP
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class PriceModel(Base):
|
||||||
|
__tablename__ = "usd_prices"
|
||||||
|
|
||||||
|
timestamp = Column(TIMESTAMP, nullable=False, primary_key=True)
|
||||||
|
usd_price = Column(Numeric, nullable=False)
|
||||||
|
token_address = Column(String, nullable=False, primary_key=True)
|
Loading…
x
Reference in New Issue
Block a user