/
itrade.py
230 lines (192 loc) · 7.56 KB
/
itrade.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env python
# ============================================================================
# Project Name : iTrade
# Module Name : itrade.py
#
# Description: Main
#
# The Original Code is iTrade code (http://itrade.sourceforge.net).
#
# The Initial Developer of the Original Code is Gilles Dumortier.
#
# Portions created by the Initial Developer are Copyright (C) 2004-2008 the
# Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see http://www.gnu.org/licenses/gpl.html
#
# History Rev Description
# 2005-03-17 dgil Wrote it from scratch
# ============================================================================
# ============================================================================
# Imports
# ============================================================================
# python system
import logging
import getopt
import sys
# iTrade system
import itrade_config
from itrade_local import *
from itrade_logging import *
setLevel(logging.INFO)
import itrade_quotes
import itrade_ext
import itrade_import
import itrade_portfolio
import itrade_matrix
# ============================================================================
# Usage
# ============================================================================
def usage():
print "%s %s - %s version - %s" % (itrade_config.softwareName,itrade_config.softwareVersion,itrade_config.softwareLicense,itrade_config.softwareCopyright)
print
print "-h / --help this help "
print "-e connect live and display portfolio evaluation "
print "-i connect and import a ticker (or isin) "
print "-d disconnected (no live update / no network) "
print
print "--file=<f> import or export using a file (EBP file format) "
print "--quote=<n> select a quote by its isin "
print "--ticker=<n> select a quote by its ticker "
print
print "--lang=<l> select the language to be used (fr,us,...) "
print
print "--user=<p> select userdata/ specific folder "
print
print "--nopsyco do not use psyco "
print "-x activate experimental features "
print "--verbose verbose mode (usefull for debugging) "
print "--nowxversion do not use wxversion "
# ============================================================================
# Main / Command line analysing
# ============================================================================
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "xeho:vt:iq:f:l:du:", ["verbose","help", "output=", "ticker=", "quote=","file=","lang=","user=","nopsyco","nowxversion"])
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
# default values
output = None
quote = None
file = None
wx = True
nopsyco = False
nowxversion = False;
vticker = None
vquote = None
lang = gMessage.getAutoDetectedLang('us')
for o, a in opts:
if o == "-d":
itrade_config.setDisconnected(True)
if o == "-v" or o == "--verbose":
itrade_config.verbose = True
print 'Verbose mode : ON'
if o == "-x":
itrade_config.experimental = True
if o == "-e":
itrade_portfolio.cmdline_evaluatePortfolio()
wx = False
if o == "-i":
if quote:
if file:
itrade_import.cmdline_importQuoteFromFile(quote,file)
else:
itrade_import.cmdline_importQuoteFromInternet(quote)
else:
matrix = itrade_matrix.createMatrix()
if file:
itrade_import.cmdline_importMatrixFromFile(matrix,file)
else:
itrade_import.cmdline_importMatrixFromInternet(matrix)
wx = False
if o == "-h" or o == "--help":
usage()
sys.exit()
if o == "-o" or o == "--output":
output = a
if o == "-u" or o == "--user":
itrade_config.dirUserData = a
if not os.path.exists(itrade_config.dirUserData):
print 'userdata folder %s not found !' % a
sys.exit()
if o == "--nopsyco":
nopsyco = True
if o == "--nowxversion":
itrade_config.nowxversion = True
if o == "-f" or o == "--file":
file = a
if o == "-l" or o == "--lang":
lang = a
itrade_config.lang = 255
if o == "-t" or o == "--ticker":
vticker = a
if o == "-q" or o == "--quote":
vquote = a
# Import Psyco if available
if not nopsyco:
try:
import psyco
psyco.full()
print 'Psyco is running'
except ImportError:
print 'Psyco is not running (library not found)'
else:
print 'Psyco is not running (forced by command line)'
# load configuration
itrade_config.loadConfig("itrade.py")
if itrade_config.verbose:
print "*** Proxy server:",itrade_config.proxyHostname, "- Proxy auth:",itrade_config.proxyAuthentication,"- Connection timeout:",itrade_config.connectionTimeout
# load extensions
itrade_ext.loadExtensions(itrade_config.fileExtData,itrade_config.dirExtData)
# init modules
itrade_quotes.initQuotesModule()
itrade_portfolio.initPortfolioModule()
# use the correct pack language
if itrade_config.lang == 255:
gMessage.setLang(lang)
gMessage.load()
# commands
if vticker:
quote = itrade_quotes.quotes.lookupTicker(vticker)
if not quote:
print 'ticker %s not found !' % vticker
sys.exit()
if vquote:
quote = itrade_quotes.quotes.lookupKey(vquote)
if not quote:
print 'quote %s not found ! format is : <ISINorTICKER>.<EXCHANGE>.<PLACE>' % vquote
sys.exit()
if wx:
import itrade_wxmain
itrade_wxmain.start_iTradeWindow()
if quote:
portfolio = itrade_portfolio.loadPortfolio()
quote.update()
quote.compute()
quote.printInfo()
# save the user configuration
# __x ? itrade_config.saveConfig()
# ============================================================================
# Launch me
# ============================================================================
if __name__ == "__main__":
setLevel(logging.INFO)
main()
# ============================================================================
# That's all folks !
# ============================================================================