diff --git a/Dockerfile b/Dockerfile index 7499742..0e577e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM python:3.9-buster -COPY cryptostore.py /cryptostore.py - RUN apt install gcc git RUN pip install --no-cache-dir cython @@ -9,7 +7,9 @@ RUN pip install --no-cache-dir cryptofeed RUN pip install --no-cache-dir aioredis RUN pip install --no-cache-dir pymongo[srv] RUN pip install --no-cache-dir motor +RUN pip install --no-cache-dir asyncpg +COPY cryptostore.py /cryptostore.py CMD ["/cryptostore.py"] ENTRYPOINT ["python"] diff --git a/cryptostore.py b/cryptostore.py index c0c2712..caf31c9 100644 --- a/cryptostore.py +++ b/cryptostore.py @@ -13,6 +13,7 @@ from cryptofeed.backends.redis import BookRedis, TradeRedis, TickerRedis, FundingRedis, CandlesRedis, OpenInterestRedis, LiquidationsRedis from cryptofeed.backends.redis import BookStream, TradeStream, TickerStream, FundingStream, CandlesStream, OpenInterestStream, LiquidationsStream from cryptofeed.backends.mongo import BookMongo, TradeMongo, TickerMongo, FundingMongo, CandlesMongo, OpenInterestMongo, LiquidationsMongo +from cryptofeed.backends.postgres import BookPostgres, TradePostgres, TickerPostgres, FundingPostgres, CandlesPostgres, OpenInterestPostgres, LiquidationsPostgres async def tty(obj, receipt_ts): @@ -52,6 +53,8 @@ def load_config() -> Feed: port = int(port) candle_interval = os.environ.get('CANDLE_INTERVAL', '1m') database = os.environ.get('DATABASE') + user = os.environ.get('USER') + password = os.environ.get('PASSWORD') cbs = None if backend == 'REDIS' or backend == 'REDISSTREAM': @@ -76,6 +79,17 @@ def load_config() -> Feed: OPEN_INTEREST: OpenInterestMongo(database, **kwargs), LIQUIDATIONS: LiquidationsMongo(database, **kwargs) } + elif backend == 'POSTGRES': + kwargs = {'db': database, 'host': host, 'port': port if port else 5432, 'user': user, 'pw': password} + cbs = { + L2_BOOK: BookPostgres(snapshot_interval=snap_interval, snapshots_only=snap_only, **kwargs), + TRADES: TradePostgres(**kwargs), + TICKER: TickerPostgres(**kwargs), + FUNDING: FundingPostgres(**kwargs), + CANDLES: CandlesPostgres(**kwargs), + OPEN_INTEREST: OpenInterestPostgres(**kwargs), + LIQUIDATIONS: LiquidationsPostgres(**kwargs) + } elif backend == 'TTY': cbs = { L2_BOOK: tty,