Skip to content

Commit

Permalink
Add support for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoscon committed Feb 18, 2022
1 parent 68a0647 commit 0f408c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM python:3.9-buster

COPY cryptostore.py /cryptostore.py

RUN apt install gcc git

RUN pip install --no-cache-dir cython
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"]
14 changes: 14 additions & 0 deletions cryptostore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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':
Expand All @@ -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,
Expand Down

0 comments on commit 0f408c6

Please sign in to comment.