-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdateConfig.py
39 lines (30 loc) · 1.22 KB
/
updateConfig.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
import os
import fileinput
def updateIbcConfig(configFile):
if os.environ.get('TWS_USER', False):
userName = os.environ['TWS_USER']
else:
raise Exception("ERROR: No IB Username Set")
if os.environ.get('TWS_PASSWORD', False):
userPassword = os.environ['TWS_PASSWORD']
else:
raise Exception("ERROR: No IB Password Set")
if os.environ.get('TWS_PORT', False):
twsPort = os.environ['TWS_PORT']
else:
raise Exception("ERROR: No TWS PORT Set")
with fileinput.FileInput(configFile, inplace=True) as file:
for line in file:
line = line.replace('{ib_user}', userName)
line = line.replace('{ib_password}', userPassword)
line = line.replace('OverrideTwsApiPort=4001', 'OverrideTwsApiPort=%d' % int(twsPort))
print(line, end='')
return
def updateTwsConfig(configFile):
with fileinput.FileInput(configFile, inplace=True) as file:
for line in file:
if os.environ.get('TWS_PORT', False):
twsPort = os.environ['TWS_PORT']
line = line.replace('LocalServerPort=4001', 'LocalServerPort=%d' % int(twsPort))
print(line, end='')
return