diff --git a/tools/save_shares_data.py b/tools/save_shares_data.py index fcfc5b6..f29453c 100644 --- a/tools/save_shares_data.py +++ b/tools/save_shares_data.py @@ -1,13 +1,39 @@ +import argparse +import pathlib + import market_trade.constants import tinkoff_grpc import json import time import grpc +import argparse + + +argument_parser = argparse.ArgumentParser(prog="shares saver") + + +argument_parser.add_argument("-s", "--shares", dest="shares_data_path", action="store") + +argument_parser.add_argument("-o", "--output-directory", dest="output_directory", action="store") if __name__ == '__main__': + cli_args = argument_parser.parse_args() + + + 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") + + 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(market_trade.constants.SHARES_STATS_PATH, encoding="utf-8", mode="r") as shares_stats_file: + with open(shares_path, encoding="utf-8", mode="r") as shares_stats_file: sorted_shares_liquidity_stats = json.load(shares_stats_file) # getting sorted list by liquidity and extracting first n, where n is subscription limit @@ -34,7 +60,7 @@ if __name__ == '__main__': try: tinkoff_trades_saver = tinkoff_grpc.savers.TradesSaver(channel=tinkoff_channel, instruments=shares_to_gather, - filepath=market_trade.constants.SHARES_TRADES_PATH) + filepath=output_data_path) tinkoff_trades_saver.start() except grpc.RpcError as grpc_error: pass