From df961f50c6c50cfdae20f899600777ad3e7cf4be Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 26 Dec 2023 22:42:52 +0200 Subject: [PATCH] added multiple script modifications and finalized the dockerfile --- .dockerignore | 1 + .gitignore | 2 ++ ...erfile => save_currencies_data.Dockerfile} | 17 +++++--------- market_trade/__init__.py | 0 pyproject.toml | 3 +-- tools/__init__.py | 0 tools/save_currencies_data.py | 23 ++++++++++++++++--- tools/save_shares_data.py | 12 ++++++---- 8 files changed, 37 insertions(+), 21 deletions(-) rename dockerfiles/{Dockerfile => save_currencies_data.Dockerfile} (58%) create mode 100644 market_trade/__init__.py create mode 100644 tools/__init__.py diff --git a/.dockerignore b/.dockerignore index d7d90e6..c345b00 100644 --- a/.dockerignore +++ b/.dockerignore @@ -235,6 +235,7 @@ venv/ ENV/ env.bak/ venv.bak/ +env.list # Spyder project settings .spyderproject diff --git a/.gitignore b/.gitignore index 18c025b..19af17d 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,5 @@ Package Control.user-ca-bundle oscrypto-ca-bundle.crt bh_unicode_properties.cache GitHub.sublime-settings + +env.list \ No newline at end of file diff --git a/dockerfiles/Dockerfile b/dockerfiles/save_currencies_data.Dockerfile similarity index 58% rename from dockerfiles/Dockerfile rename to dockerfiles/save_currencies_data.Dockerfile index c804122..5ecb7fb 100644 --- a/dockerfiles/Dockerfile +++ b/dockerfiles/save_currencies_data.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-buster as builder +FROM python:3.11-buster RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.1 python3 - @@ -10,19 +10,14 @@ ENV POETRY_NO_INTERACTION=1 \ WORKDIR /app -COPY pyproject.toml poetry.lock ./ -RUN touch README.md +COPY pyproject.toml poetry.lock /app/ +COPY market_trade /app/market_trade/ +COPY tools /app/tools RUN mkdir --parents --mode 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts -RUN --mount=type=ssh --mount=type=cache,target=$POETRY_CACHE_DIR $HOME/.local/bin/poetry install --without dev --no-root - -FROM python:3.11-slim-buster as runtime +RUN --mount=type=ssh --mount=type=cache,target=$POETRY_CACHE_DIR $HOME/.local/bin/poetry install --without dev ENV VIRTUAL_ENV=/app/.venv \ PATH="/app/.venv/bin:$PATH" -COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} - -COPY market_trade ./market_trade - -ENTRYPOINT ["python", "-m", "annapurna.main"] +ENTRYPOINT ["python", "tools/save_currencies_data.py"] diff --git a/market_trade/__init__.py b/market_trade/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index f69aa34..b2c2ad3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,9 @@ [tool.poetry] -name = "markettrade" +name = "market_trade" version = "0.2.0" description = "" authors = ["Mark ", "Sasha "] - [tool.poetry.dependencies] python = ">=3.9,<3.13" pandas = "^2.1.3" diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/save_currencies_data.py b/tools/save_currencies_data.py index 3e0ded3..63a3262 100644 --- a/tools/save_currencies_data.py +++ b/tools/save_currencies_data.py @@ -1,9 +1,18 @@ +import argparse +import pathlib import time -import grpc import market_trade.constants import tinkoff_grpc.src.instruments import tinkoff_grpc.src.marketdata import tinkoff_grpc.src.channel +import grpc + + +# initializing argument parser +argument_parser = argparse.ArgumentParser(prog="currencies saver") + +# this argument is used to save the currency trades into distinct dir +argument_parser.add_argument("-o", "--output-directory", type=pathlib.Path, dest="output_directory", action="store") def get_all_currencies(channel: tinkoff_grpc.src.channel.Channel): @@ -15,7 +24,7 @@ def get_all_currencies(channel: tinkoff_grpc.src.channel.Channel): # initializing service instruments_service = tinkoff_grpc.src.instruments.InstrumentsService(channel) - # getting currencies + # getting currencies list currencies = instruments_service.get_currencies( instrument_status_name=market_trade.constants.DEFAULT_INSTRUMENT_STATUS ) @@ -23,6 +32,14 @@ def get_all_currencies(channel: tinkoff_grpc.src.channel.Channel): if __name__ == '__main__': + # getting the paths loaded + cli_args = argument_parser.parse_args() + + if cli_args.output_directory: + output_data_path = cli_args.output_directory + else: + raise NotImplementedError("We would like to have a path where we would save data") + api_address = market_trade.constants.TINKOFF_API_ADDRESS token = market_trade.constants.TINKOFF_BEARER_TOKEN authorization_field = market_trade.constants.TINKOFF_AUTHORIZATION_HEADER @@ -34,7 +51,7 @@ if __name__ == '__main__': time.sleep(1) try: tinkoff_trades_saver = tinkoff_grpc.savers.TradesSaver(channel=tinkoff_channel, instruments=currencies, - filepath=market_trade.constants.CURRENCIES_TRADES_PATH) + filepath=output_data_path) tinkoff_trades_saver.start() except grpc.RpcError as grpc_error: pass diff --git a/tools/save_shares_data.py b/tools/save_shares_data.py index f29453c..af8f5af 100644 --- a/tools/save_shares_data.py +++ b/tools/save_shares_data.py @@ -8,30 +8,32 @@ import time import grpc import argparse - +# initializing argument parser argument_parser = argparse.ArgumentParser(prog="shares saver") -argument_parser.add_argument("-s", "--shares", dest="shares_data_path", action="store") +# this argument is used for shares info location, it contains the liquidity info +argument_parser.add_argument("-s", "--shares", type=pathlib.Path, dest="shares_data_path", action="store") -argument_parser.add_argument("-o", "--output-directory", dest="output_directory", action="store") +# this argument is used to save the output into distinct dir +argument_parser.add_argument("-o", "--output-directory", type=pathlib.Path, dest="output_directory", action="store") if __name__ == '__main__': cli_args = argument_parser.parse_args() - + # filling the shares data path, no other modes are though of if cli_args.shares_data_path: shares_path = pathlib.Path(cli_args.shares_data_path) else: raise NotImplementedError("No path provided for shares liquidity data") + # filling the output directory data path, where the trades would be saved if cli_args.output_directory: output_data_path = pathlib.Path(cli_args.output_directory) else: raise NotImplementedError("No path for the output data of shares") - # loading shares liquidity stats gathered with open(shares_path, encoding="utf-8", mode="r") as shares_stats_file: sorted_shares_liquidity_stats = json.load(shares_stats_file)