Skip to content

Commit

Permalink
Updated except syntax to be compatible with Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
gbeced committed Jul 22, 2018
1 parent c94194c commit e46923e
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pyalgotrade/bitstamp/livebroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run(self):
self.__lastTradeId = trades[-1].getId()
common.logger.info("%d new trade/s found" % (len(trades)))
self.__queue.put((TradeMonitor.ON_USER_TRADE, trades))
except Exception, e:
except Exception as e:
common.logger.critical("Error retrieving user transactions", exc_info=e)

time.sleep(TradeMonitor.POLL_FREQUENCY)
Expand Down
4 changes: 2 additions & 2 deletions pyalgotrade/bitstamp/livefeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __initializeClient(self):
# Start the thread that runs the client.
self.__thread = self.buildWebSocketClientThread()
self.__thread.start()
except Exception, e:
except Exception as e:
common.logger.exception("Error connecting : %s" % str(e))

# Wait for initialization to complete.
Expand Down Expand Up @@ -243,7 +243,7 @@ def stop(self):
if self.__thread is not None and self.__thread.is_alive():
common.logger.info("Shutting down websocket client.")
self.__thread.stop()
except Exception, e:
except Exception as e:
common.logger.error("Error shutting down client: %s" % (str(e)))

# This should not raise.
Expand Down
4 changes: 2 additions & 2 deletions pyalgotrade/bitstamp/wsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def onDisconnectionDetected(self):
common.logger.warning("Disconnection detected.")
try:
self.stopClient()
except Exception, e:
except Exception as e:
common.logger.error("Error stopping websocket client: %s." % (str(e)))
self.__queue.put((WebSocketClient.Event.DISCONNECTED, None))

Expand Down Expand Up @@ -191,5 +191,5 @@ def stop(self):
if self.__wsClient is not None:
common.logger.info("Stopping websocket client.")
self.__wsClient.stopClient()
except Exception, e:
except Exception as e:
common.logger.error("Error stopping websocket client: %s." % (str(e)))
2 changes: 1 addition & 1 deletion pyalgotrade/optimizer/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def runStrategy(self, barFeed, *args, **kwargs):
w = Worker("localhost", port, name)
w.getLogger().setLevel(logLevel)
w.run()
except Exception, e:
except Exception as e:
w.getLogger().exception("Failed to run worker: %s" % (e))


Expand Down
4 changes: 2 additions & 2 deletions pyalgotrade/optimizer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __processJob(self, job, barsFreq, instruments, bars):
result = None
try:
result = self.runStrategy(feed, *parameters)
except Exception, e:
except Exception as e:
self.getLogger().exception("Error running strategy with parameters %s: %s" % (str(parameters), e))
self.getLogger().info("Result %s" % result)
if bestResult is None or result > bestResult:
Expand Down Expand Up @@ -117,7 +117,7 @@ def run(self):
self.__processJob(job, barsFreq, instruments, bars)
job = self.getNextJob()
self.getLogger().info("Finished running")
except Exception, e:
except Exception as e:
self.getLogger().exception("Finished running with errors: %s" % (e))


Expand Down
4 changes: 2 additions & 2 deletions pyalgotrade/tools/quandl.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def build_feed(sourceCode, tableCodes, fromYear, toYear, storage, frequency=bar.
else:
assert frequency == bar.Frequency.WEEK, "Invalid frequency"
download_weekly_bars(sourceCode, tableCode, year, fileName, authToken)
except Exception, e:
except Exception as e:
if skipErrors:
logger.error(str(e))
continue
Expand Down Expand Up @@ -194,7 +194,7 @@ def main():
else:
assert args.frequency == "weekly", "Invalid frequency"
download_weekly_bars(args.source_code, args.table_code, year, fileName, args.auth_token)
except Exception, e:
except Exception as e:
if args.ignore_errors:
logger.error(str(e))
continue
Expand Down
2 changes: 1 addition & 1 deletion pyalgotrade/twitter/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def stop(self):
if self.__thread is not None and self.__thread.is_alive():
logger.info("Shutting down client.")
self.__stream.disconnect()
except Exception, e:
except Exception as e:
logger.error("Error disconnecting stream: %s." % (str(e)))

def join(self):
Expand Down
4 changes: 2 additions & 2 deletions pyalgotrade/websocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def received_message(self, message):
return

self.onMessage(msg)
except Exception, e:
except Exception as e:
self.onUnhandledException(e)

def opened(self):
Expand Down Expand Up @@ -158,7 +158,7 @@ def stopClient(self):
if self.__connected:
self.close()
self.close_connection()
except Exception, e:
except Exception as e:
logger.warning("Failed to close connection: %s" % (e))

######################################################################
Expand Down
2 changes: 1 addition & 1 deletion samples/bccharts_example_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _buySignal(self, price):
self.info("Buy %s at %s" % (size, price))
try:
self.limitOrder(self.__instrument, price, size)
except Exception, e:
except Exception as e:
self.error("Failed to buy: %s" % (e))

def _sellSignal(self, price):
Expand Down
4 changes: 2 additions & 2 deletions testcases/ninjatraderfeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def testWithIntegerTimezone(self):
try:
barFeed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE, -3)
self.assertTrue(False, "Exception expected")
except Exception, e:
except Exception as e:
self.assertTrue(str(e).find("timezone as an int parameter is not supported anymore") == 0)

try:
barFeed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE)
barFeed.addBarsFromCSV("spy", common.get_data_file_path("nt-spy-minute-2011.csv"), -5)
self.assertTrue(False, "Exception expected")
except Exception, e:
except Exception as e:
self.assertTrue(str(e).find("timezone as an int parameter is not supported anymore") == 0)

def testLocalizeAndFilter(self):
Expand Down
4 changes: 2 additions & 2 deletions testcases/yahoofeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def testWithIntegerTimezone(self):
try:
barFeed = yahoofeed.Feed(timezone=-5)
self.assertTrue(False, "Exception expected")
except Exception, e:
except Exception as e:
self.assertTrue(str(e).find("timezone as an int parameter is not supported anymore") == 0)

try:
barFeed = yahoofeed.Feed()
barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv"), -3)
self.assertTrue(False, "Exception expected")
except Exception, e:
except Exception as e:
self.assertTrue(str(e).find("timezone as an int parameter is not supported anymore") == 0)

def testMapTypeOperations(self):
Expand Down
4 changes: 2 additions & 2 deletions tools/symbols/get_merval_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def process_symbol(writer, symbol):
logger.warning("Industry not found")

writer.addStock(symbol, company, sector, industry)
except Exception, e:
except Exception as e:
logger.error(str(e))


Expand All @@ -89,7 +89,7 @@ def main():

logger.info("Writing merval.xml")
writer.write("merval.xml")
except Exception, e:
except Exception as e:
logger.error(str(e))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/symbols/get_nasdaq_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():

logger.info("Writing nasdaq.xml")
symbolsXML.write("nasdaq.xml")
except Exception, e:
except Exception as e:
logger.error(str(e))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/symbols/get_nyse_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():

logger.info("Writing nyse.xml")
symbolsXML.write("nyse.xml")
except Exception, e:
except Exception as e:
logger.error(str(e))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/symbols/get_sp500_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main():

logger.info("Writing sp500.xml")
symbolsXML.write("sp500.xml")
except Exception, e:
except Exception as e:
logger.error(str(e))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/yahoodbfeed/analyze_gaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def main():
stockCallback = lambda stock: process_symbol(stock.getTicker(), fromYear, toYear, missingDataVerifierClass)
indexCallback = stockCallback
symbolsxml.parse(symbolsFile, stockCallback, indexCallback)
except Exception, e:
except Exception as e:
logger.error(str(e))

main()
4 changes: 2 additions & 2 deletions tools/yahoodbfeed/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def download_files_for_symbol(symbol, fromYear, toYear):
try:
yahoofinance.download_daily_bars(symbol, year, fileName)
status += "1"
except Exception, e:
except Exception as e:
logger.error(str(e))
status += "0"
else:
Expand All @@ -73,7 +73,7 @@ def main():
symbolsFile = os.path.join("..", "symbols", "merval.xml")
callback = lambda stock: download_files_for_symbol(stock.getTicker(), fromYear, toYear)
symbolsxml.parse(symbolsFile, callback, callback)
except Exception, e:
except Exception as e:
logger.error(str(e))

main()

0 comments on commit e46923e

Please sign in to comment.