aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-24 23:35:40 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-25 01:35:28 +0100
commiteb9c92e155941b51042ba57e23f651454bd8e55a (patch)
tree8de8ed33394777aec4b538275ffa319368086bed /main.py
parent17ff995eb623dcaea579e33e507091d6169c52e5 (diff)
downloadTrader-eb9c92e155941b51042ba57e23f651454bd8e55a.tar.gz
Trader-eb9c92e155941b51042ba57e23f651454bd8e55a.tar.zst
Trader-eb9c92e155941b51042ba57e23f651454bd8e55a.zip
Add main running file and fetch information from database
Diffstat (limited to 'main.py')
-rw-r--r--main.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..41abe9e
--- /dev/null
+++ b/main.py
@@ -0,0 +1,64 @@
1import os
2import sys
3import configparser
4import psycopg2
5import argparse
6from datetime import datetime
7
8import portfolio, market
9
10parser = argparse.ArgumentParser(
11 description="Run the trade bot")
12
13parser.add_argument("-c", "--config",
14 default="config.ini",
15 required=False,
16 help="Config file to load (default: config.ini)")
17parser.add_argument("--before",
18 default=False, action='store_const', const=True,
19 help="Run the steps before the cryptoportfolio update")
20parser.add_argument("--after",
21 default=False, action='store_const', const=True,
22 help="Run the steps after the cryptoportfolio update")
23parser.add_argument("--debug",
24 default=False, action='store_const', const=True,
25 help="Run in debug mode")
26
27args = parser.parse_args()
28
29if not os.path.exists(args.config):
30 print("no config file found, exiting")
31 sys.exit(1)
32
33config = configparser.ConfigParser()
34config.read(args.config)
35
36pg_config = config["postgresql"]
37
38connection = psycopg2.connect(**pg_config)
39cursor = connection.cursor()
40
41cursor.execute("SELECT config,user_id FROM market_configs")
42
43report_path = config["app"]["report_path"]
44if not os.path.exists(report_path):
45 os.makedirs(report_path)
46
47for row in cursor:
48 market_config, user_id = row
49 try:
50 user_market = market.get_market(market_config)
51 if args.before:
52 portfolio.h.process_sell_all__1_all_sell(user_market, debug=args.debug)
53 if args.after:
54 portfolio.Portfolio.wait_for_recent()
55 portfolio.h.process_sell_all__2_all_buy(user_market, debug=args.debug)
56 except Exception as e:
57 print(e)
58 pass
59 finally:
60 report_file = "{}/{}_{}.json".format(report_path, datetime.now().isoformat(), user_id)
61 with open(report_file, "w") as f:
62 f.write(portfolio.ReportStore.to_json())
63 portfolio.h.reset_all()
64