forked from sreenivasdoosa/sdoosa-algo-trade-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (37 loc) · 1.68 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import logging
from flask import Flask
from config.Config import getBrokerAppConfig, getServerConfig, getSystemConfig
from restapis.HomeAPI import HomeAPI
from restapis.BrokerLoginAPI import BrokerLoginAPI
from restapis.StartAlgoAPI import StartAlgoAPI
from restapis.PositionsAPI import PositionsAPI
from restapis.HoldingsAPI import HoldingsAPI
app = Flask(__name__)
app.config['DEBUG'] = True
app.add_url_rule("/", view_func=HomeAPI.as_view("home_api"))
app.add_url_rule("/apis/broker/login/zerodha", view_func=BrokerLoginAPI.as_view("broker_login_api"))
app.add_url_rule("/apis/algo/start", view_func=StartAlgoAPI.as_view("start_algo_api"))
app.add_url_rule("/positions", view_func=PositionsAPI.as_view("positions_api"))
app.add_url_rule("/holdings", view_func=HoldingsAPI.as_view("holdings_api"))
def initLoggingConfg(filepath):
format = "%(asctime)s: %(message)s"
logging.basicConfig(filename=filepath, format=format, level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S")
# Execution starts here
serverConfig = getServerConfig()
deployDir = serverConfig['deployDir']
if os.path.exists(deployDir) == False:
print("Deploy Directory " + deployDir + " does not exist. Exiting the app.")
exit(-1)
logFileDir = serverConfig['logFileDir']
if os.path.exists(logFileDir) == False:
print("LogFile Directory " + logFileDir + " does not exist. Exiting the app.")
exit(-1)
print("Deploy Directory = " + deployDir)
print("LogFile Directory = " + logFileDir)
initLoggingConfg(logFileDir + "/app.log")
logging.info('serverConfig => %s', serverConfig)
brokerAppConfig = getBrokerAppConfig()
logging.info('brokerAppConfig => %s', brokerAppConfig)
port = serverConfig['port']
app.run('localhost', port)