Giter VIP home page Giter VIP logo

qtpylib's Introduction

QTPyLib, Pythonic Algorithmic Trading

Python version

PyPi version

PyPi status

Travis-CI build status

Documentation Status

Chat on Discord

Star this repo

Follow me on twitter

QTPyLib (Quantitative Trading Python Library) is a simple, event-driven algorithmic trading library written in Python, that supports backtesting, as well as paper and live trading via Interactive Brokers.

I developed QTPyLib because I wanted for a simple, yet powerful, trading library that will let me focus on the trading logic itself and ignore everything else.

Full Documentation »

Changelog »


Read about the future of QTPyLib here: https://aroussi.com/post/the-future-of-qtpylib


Features

  • A continuously-running Blotter that lets you capture market data even when your algos aren't running.
  • Tick, Bar and Trade data is stored in MySQL for later analysis and backtesting.
  • Using pub/sub architecture using ØMQ (ZeroMQ) for communicating between the Algo and the Blotter allows for a single Blotter/multiple Algos running on the same machine.
  • Support for Order Book, Quote, Time, Tick or Volume based strategy resolutions.
  • Includes many common indicators that you can seamlessly use in your algorithm.
  • Market data events use asynchronous, non-blocking architecture.
  • Have orders delivered to your mobile via SMS (requires a Nexmo or Twilio account).
  • Full integration with TA-Lib via dedicated module (see documentation).
  • Ability to import any Python library (such as scikit-learn or TensorFlow) to use them in your algorithms.

Quickstart

There are 5 main components to QTPyLib:

  1. Blotter - handles market data retrieval and processing.
  2. Broker - sends and process orders/positions (abstracted layer).
  3. Algo - (sub-class of Broker) communicates with the Blotter to pass market data to your strategies, and process/positions orders via Broker.
  4. Reports - provides real-time monitoring of trades and open positions via Web App, as well as a simple REST API for trades, open positions, and market data.
  5. Lastly, Your Strategies, which are sub-classes of Algo, handle the trading logic/rules. This is where you'll write most of your code.

1. Get Market Data

To get started, you need to first create a Blotter script:

Then, with IB TWS/GW running, run the Blotter from the command line:

If your strategy needs order book / market depth data, add the --orderbook flag to the command:

2. Write your Algorithm

While the Blotter running in the background, write and execute your algorithm:

# strategy.py
from qtpylib.algo import Algo

class CrossOver(Algo):

    def on_start(self):
        pass

    def on_fill(self, instrument, order):
        pass

    def on_quote(self, instrument):
        pass

    def on_orderbook(self, instrument):
        pass

    def on_tick(self, instrument):
        pass

    def on_bar(self, instrument):
        # get instrument history
        bars = instrument.get_bars(window=100)

        # or get all instruments history
        # bars = self.bars[-20:]

        # skip first 20 days to get full windows
        if len(bars) < 20:
            return

        # compute averages using internal rolling_mean
        bars['short_ma'] = bars['close'].rolling(window=10).mean()
        bars['long_ma']  = bars['close'].rolling(window=20).mean()

        # get current position data
        positions = instrument.get_positions()

        # trading logic - entry signal
        if bars['short_ma'].crossed_above(bars['long_ma'])[-1]:
            if not instrument.pending_orders and positions["position"] == 0:

                # buy one contract
                instrument.buy(1)

                # record values for later analysis
                self.record(ma_cross=1)

        # trading logic - exit signal
        elif bars['short_ma'].crossed_below(bars['long_ma'])[-1]:
            if positions["position"] != 0:

                # exit / flatten position
                instrument.exit()

                # record values for later analysis
                self.record(ma_cross=-1)


if __name__ == "__main__":
    strategy = CrossOver(
        instruments = [ ("ES", "FUT", "GLOBEX", "USD", 201609, 0.0, "") ], # ib tuples
        resolution  = "1T", # Pandas resolution (use "K" for tick bars)
        tick_window = 20, # no. of ticks to keep
        bar_window  = 5, # no. of bars to keep
        preload     = "1D", # preload 1 day history when starting
        timezone    = "US/Central" # convert all ticks/bars to this timezone
    )
    strategy.run()

To run your algo in a live enviroment, from the command line, type:

The resulting trades be saved in ~/qtpy/STRATEGY_YYYYMMDD.csv for later analysis.

3. Viewing Live Trades

While the Blotter running in the background, write the dashboard:

To run your dashboard, run it from the command line:

Now, point your browser to http://localhost:5000 and use the password generated to access your dashboard.


Note

You can find other examples in the qtpylib/examples directory. Please refer to the Full Documentation to learn how to enable SMS notifications, use the bundled Indicators, and more.

Installation

Install using pip:

Requirements

  • Python >=3.4
  • Pandas (tested to work with >=0.18.1)
  • Numpy (tested to work with >=1.11.1)
  • PyZMQ (tested to work with >=15.2.1)
  • PyMySQL (tested to work with >=0.7.6)
  • pytz (tested to work with >=2016.6.1)
  • dateutil (tested to work with >=2.5.1)
  • Nexmo-Python for SMS support (tested to work with >=1.2.0)
  • Twilio-Python for SMS support (tested to work with >=5.4.0)
  • Flask for the Dashboard (tested to work with >=0.11)
  • Requests (tested to work with >=2.10.0)
  • IbPy2 (tested to work with >=0.8.0)
  • ezIBpy (IbPy wrapper, tested to work with >=1.12.66)
  • Latest Interactive Brokers’ TWS or IB Gateway installed and running on the machine
  • MySQL Server installed and running with a database for QTPyLib

Legal Stuff

QTPyLib is licensed under the Apache License, Version 2.0. A copy of which is included in LICENSE.txt.

QTPyLib is not a product of Interactive Brokers, nor is it affiliated with Interactive Brokers.

P.S.

I'm very interested in your experience with QTPyLib. Please drop me a note with any feedback you have.

Ran

qtpylib's People

Contributors

aspenforest avatar hroff-1902 avatar jkleint avatar lionelyoung avatar miguelvm avatar ranaroussi avatar swampyclark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qtpylib's Issues

Day based bars is not supported yet

Lots of things get a bit weird if you try preload day based bars:

e.g.

    strategy = DayStrategy(
        instruments = [
#         ("ES", "FUT", "GLOBEX", "USD", ACTIVE_MONTH, 0.0, ""),
#          ("SPX", "IND", "CBOE", "USD", "", 0.0, ""),
          ("AAPL", "STK", "SMART", "USD", "", 0.0, "")
         ],
        resolution  = "1D",
        bar_window  = 100,
        preload = "4D"
    )

ES hangs with no history error message on Gateway.
INDes seem to just hang and not return anything.
For stock I got things going with two changes to the blotter.py

     # expand the resolutions
       if resolution[-1] in ("K", "V", "S"):
            self.backfill_resolution = "1 sec"
       elif resolution[-1]== "M":
            self.backfill_resolution = "1 min"
       elif resolution[-1]== "H":
            self.backfill_resolution = "1 hour"
       elif resolution[-1]== "D":
            self.backfill_resolution = "1 day"

```and

  # round to days if asking for days
    if resolution[-1]== "D":
        start_date = datetime(start_date.year, start_date.month, start_date.day)
        end_date   = datetime(end_date.year, end_date.month, end_date.day)
        first_date = datetime(first_date.year, first_date.month, first_date.day)
        last_date  = datetime(last_date.year, last_date.month, last_date.day)
I got the query for the stock back but....something is not parsing the dates well... it works for minute data but not for the day based bars...  (no idea where to debug from here)

1 1970-08-22 10:52:01 1 141.59 142.8 139.35 139.35 352675
2 1970-08-22 10:52:02 1 139.25 141.6 138.67 141.5 238385
3 1970-08-22 10:52:03 1 141.28 141.59 140.61 141 186233
4 1970-08-22 10:52:04 1 141.07 141.74 140.05 140.43 203203
5 2017-03-24 08:36:00 1 141.07 141.14 141.07 141.14 4
6 2017-03-24 08:37:00 1 141.14 141.14 141.14 141.14 0

File Not Found Error during qtpylib install

Hi Ran

I'm wondering if you can help me. I'm running Anaconda 3.6 and when I try to install qtpylib with "pip install qtpylib --upgrade --no-cache-dir" I receive the following error:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\
Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg'

However, I noticed that qtpylib uninstalled this version:

  Found existing installation: setuptools 27.2.0
    Uninstalling setuptools-27.2.0:
      Successfully uninstalled setuptools-27.2.0

  And installed version 34.3.1:
	
 Successfully installed Jinja2-2.9.5 PyJWT-1.4.2 appdirs-1.4.2 cryptography-1.7.2
 httplib2-0.10.3 idna-2.4 nexmo-1.4.0 packaging-16.8 pyasn1-0.2.3 pymysql-0.7.10
 pyparsing-2.1.10 pysocks-1.6.6 qtpylib-1.5.59 requests-2.13.0 setuptools-34.3.1
 twilio-5.7.0
 
Here is the Traceback (most recent call last):
  File "C:\Anaconda3\Scripts\pip-script.py", line 5, in <module>
    sys.exit(pip.main())
  File "C:\Anaconda3\lib\site-packages\pip\__init__.py", line 249, in main
    return command.main(cmd_args)
  File "C:\Anaconda3\lib\site-packages\pip\basecommand.py", line 252, in main
    pip_version_check(session)
  File "C:\Anaconda3\lib\site-packages\pip\utils\outdated.py", line 102, in pip_
version_check
    installed_version = get_installed_version("pip")
  File "C:\Anaconda3\lib\site-packages\pip\utils\__init__.py", line 838, in get_
installed_version
    working_set = pkg_resources.WorkingSet()
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 644, in __init__
    self.add_entry(entry)
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 700, in add_entry
    for dist in find_distributions(entry, True):
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 1949, in find_eggs_in_zip
    if metadata.has_metadata('PKG-INFO'):
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 1463, in has_metadata
    return self.egg_info and self._has(self._fn(self.egg_info, name))
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 1823, in _has
    return zip_path in self.zipinfo or zip_path in self._index()
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 1703, in zipinfo
    return self._zip_manifests.load(self.loader.archive)
  File "C:\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", l
ine 1643, in load
    mtime = os.stat(path).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\
Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg'

Exception in message dispatch

I run the example/blotter.py successfully and then I run a simple strategy that only prints ticks received for IBKR stock. However I get the following "exception in message dispatch". Can you please let me know if this is a bug or I have some other issues. TWS is connected and mysql is running. Thanks!

$ python print_data.py 
Server Version: 76
TWS Time at connection:20161127 16:40:06 CST
27-Nov-16 16:40:07 ERROR     Exception in message dispatch.  Handler 'handleServerEvents' for 'contractDetailsEnd'
Traceback (most recent call last):
  File "/Users/reza/anaconda3/envs/qtpylib_trading/lib/python3.5/site-packages/ib/opt/dispatcher.py", line 44, in __call__
    results.append(listener(message))
  File "/Users/reza/anaconda3/envs/qtpylib_trading/lib/python3.5/site-packages/ezibpy/ezibpy.py", line 295, in handleServerEvents
    self.handleContractDetails(msg, end=True)
  File "/Users/reza/anaconda3/envs/qtpylib_trading/lib/python3.5/site-packages/ezibpy/ezibpy.py", line 411, in handleContractDetails
    self.portfolio[newString] = self.portfolio[oldString]
KeyError: 'IBKR'
Tick: {'symbol': 'IBKR', 'last': 38.88, 'lastsize': 1, 'bidsize': 1, 'symbol_group': 'IBKR', 'datetime': Timestamp('2016-11-27 16:39:32'), 'asset_class': 'STK', 'asksize': 1, 'bid': 38.87, 'ask': 38.91, 'opt_price': nan}

Backtesting not converting prices to float?

I'm just trying the backtest feature; I grabbed the last 3 weeks of SPX from Google and tried to run a simple macd strategy:

def on_bar(self, instrument):
bars = instrument.get_bars(lookback=20)

    # make sure we have at least 20 bars to work with                                                                                                        
    if len(bars) < 20:
        return

    macd = bars.macd()

    bars['macd']        = macd['macd']
    bars['macd_signal'] = macd['signal']
    bars['macd_hist']   = macd['histogram']

    print(macd)

But I get an error:

python ./strategy.py --backtest --start 2016-12-20 --end 2017-01-06 --data ~/data/ --output   ~/portfolio/port.pkl
starting ...
Traceback (most recent call last):
  File "/home/ubuntu/money3/lib/python3.5/site-packages/pandas/core/ops.py", line 1170, in na_op
    raise_on_error=True, **eval_kwargs)
  File "/home/ubuntu/money3/lib/python3.5/site-packages/pandas/computation/expressions.py", line 210, in evaluate
    **eval_kwargs)
  File "/home/ubuntu/money3/lib/python3.5/site-packages/pandas/computation/expressions.py", line 63, in _evaluate_standard
    return op(a, b)
TypeError: unsupported operand type(s) for -: 'str' and 'str'

Help please ... something I'm doing wrong or an issue with the code? Thanks for a great tool!

FUT postions always return 0 by instrument.get_postions()

Ran,
i using Version 1.4.9, FUT postions always return 0 by instrument.get_postions().
CASH can normally get postions ,but change FUT (i only test SGX XINA50 constructs) always retrun 0.
i test some times,found not any problem,can you help check this,thanks !

issue with multi-instrument

I'd like to work with multiple instruments however even with the example that is given in the document I run into issues. Can you help me with the issue?

This is the code:

from qtpylib.algo import Algo

class BuyStockSellOil(Algo):

    def on_bar(self, instrument):

        # get instrument object
        ES = self.get_instrument('ESU2016_FUT')
        CL = self.get_instrument('CLU2016_FUT')

        # rotate holding between ES and CL
        # yes - this strategy makes no sense :)

        es_pos = ES.get_positions()
        cl_pos = CL.get_positions()

        if es_pos["position"] == 0 and cl_pos["position"] > 0:
            ES.buy(1)
            CL.exit(1)
        elif es_pos["position"] > 0 and cl_pos["position"] == 0:
            ES.exit(1)
            CL.buy(1)


if __name__ == "__main__":
    strategy = BuyStockSellOil(
        instruments = [
            ("ES", "FUT", "GLOBEX", "USD", 201609),
            ("CL", "FUT", "NYMEX", "USD", 201609)
        ],
        resolution  = "15T"
    )

    strategy.run()

This is the error I get:

python multi_inst.py
Traceback (most recent call last):
File "multi_inst.py", line 42, in
strategy.run()
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/algo.py", line 284, in run
self.blotter.register(self.instruments)
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/blotter.py", line 1016, in register
instruments['expiry'] = instruments['expiry'].astype(str).str.split(".")[0]
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2357, in setitem
self._set_item(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2423, in _set_item
value = self._sanitize_column(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2578, in _sanitize_column
value = _sanitize_index(value, self.index, copy=False)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/series.py", line 2770, in _sanitize_index
raise ValueError('Length of values does not match length of ' 'index')
ValueError: Length of values does not match length of index

algo.py UnboundLocalError: local variable 'history' referenced before assignment

version:
QTPyLib (1.5.45)
ezIBpy (1.12.42)

algo.py line 283, self.bars = history

# get history
if not self.blotter_args["dbskip"] and (self.backtest or self.preload):

    start = self.backtest_start if self.backtest else tools.backdate(self.preload)
    end = self.backtest_end if self.backtest else None

    history = self.blotter.history(
        symbols    = self.symbols,
        start      = start,
        end        = end,
        resolution = self.resolution,
        tz         = self.timezone,
        continuous = self.continuous
    )

    # history needs backfilling?
    if not self.blotter.backfilled:
        # "loan" Blotter our ibConn
        self.blotter.ibConn = self.ibConn

        # call the back fill
        self.blotter.backfill(data=history, resolution=self.resolution, start=start, end=end)

        # re-get history from db
        history = self.blotter.history(
            symbols    = self.symbols,
            start      = start,
            end        = end,
            resolution = self.resolution,
            tz         = self.timezone,
            continuous = self.continuous
        )

        # take our ibConn back :)
        self.blotter.ibConn = None

if self.backtest:
    # initiate strategy
    self.on_start()

    # drip history
    self.blotter.drip(history,
        self._tick_handler if self.resolution[-1] in ("K", "V") else self._bar_handler)

else:
    # place history self.bars
    self.bars = history

    # add instruments to blotter in case they do not exist
    self.blotter.register(self.instruments)

    # initiate strategy
    self.on_start()

    # listen for RT data
    self.blotter.stream(
        symbols       = self.symbols,
        tz            = self.timezone,
        quote_handler = self._quote_handler,
        tick_handler  = self._tick_handler,
        bar_handler   = self._bar_handler,
        book_handler  = self._book_handler
    )

Support for FA IB accounts

Currently qtpylib doesn't support FA accounts. When using an FA account to log into TWS, no market data is retrieving from IB.

issue with get_bars lookback

Hi Ran,

While connecting to IB demo account I came across a problem with bars:

I have four instruments ['IBKR', 'AAPL', 'OXY', 'SLB']. I run the blotter and strategy and I fetch the bars for each of these instruments with loopback 28. I let the scripts run for more than 30mins. My expectation was that I will be able to receive bars for loopback = 28 (so the length of bars = 28) . However, it is not the case.

here is the some of the output after 30 min :

AAPL 5
IBKR 6
SLB 6
OXY 6
AAPL 6
IBKR 7
SLB 7
OXY 6
AAPL 7

Here is the code:

from qtpylib.algo import Algo
from qtpylib.indicators import macd#, air
import pandas as pd
from datetime import date time
import datetime

class TestStrategy(Algo):
    def on_start(self):
         pass

    def on_tick(self, instrument):
        pass

    def on_bar(self, instrument):      
        lookback = 28
        for symbol in self.instruments:
            instr = self.get_instrument(symbol)
            bars = instr.get_bars(lookback = loopback)
            print(symbol, len(bars))
        
if __name__ == "__main__":
    strategy = TestStrategy(
        #instruments = prescreening('2014-04-25', '2014-04-29'),
        instruments = ['IBKR', 'AAPL', 'OXY', 'SLB'], 
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

[strategy example] pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

Thanks for this great lib.

ver. 1.4.95
Description:
I got MySQL operation error as below error message.
And there are trade records inserted in "trades" table but no record show in dashboard.

$ python strategy.py --log strategy_log/ --ibport 7491 --output strategy_log/
Active month for ES is: 201612
Active month for CL is: 201612
Server Version: 76
TWS Time at connection:20161025 09:08:40 CST
BAR: {'symbol': 'CLZ2016_FUT', 'asset_class': 'FUT', 'low': 50.46, 'close': 50.47, 'volume': 37.0, 'signal': nan, 'symbol_group': 'CL_F', 'datetime': Timestamp('2016-10-25 01:08:00'), 'opt_price': nan, 'high': 50.47, 'open': 50.46}
CLZ2016_FUT still in position. Exiting...
CLZ2016_FUT not in position. Sending a bracket  BUY order...
[2016-10-25 09:10:55,399] ERROR in app: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:55,399 [ERROR]: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:10:55,413] ERROR in app: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:55,413 [ERROR]: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:10:55,423] ERROR in app: Exception on /algos [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 151, in algos
    algos = pd.read_sql("SELECT DISTINCT algo FROM trades", self.dbconn).to_dict(orient="records")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT DISTINCT algo FROM trades
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:55,423 [ERROR]: Exception on /algos [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 151, in algos
    algos = pd.read_sql("SELECT DISTINCT algo FROM trades", self.dbconn).to_dict(orient="records")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT DISTINCT algo FROM trades
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:10:58,058] ERROR in app: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:58,058 [ERROR]: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:10:58,073] ERROR in app: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:58,073 [ERROR]: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:10:58,093] ERROR in app: Exception on /algos [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 151, in algos
    algos = pd.read_sql("SELECT DISTINCT algo FROM trades", self.dbconn).to_dict(orient="records")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT DISTINCT algo FROM trades
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:10:58,093 [ERROR]: Exception on /algos [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 151, in algos
    algos = pd.read_sql("SELECT DISTINCT algo FROM trades", self.dbconn).to_dict(orient="records")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT DISTINCT algo FROM trades
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
BAR: {'symbol': 'ESZ2016_FUT', 'asset_class': 'FUT', 'low': 2145.5, 'close': 2145.5, 'volume': 1.0, 'signal': nan, 'symbol_group': 'ES_F', 'datetime': Timestamp('2016-10-25 01:09:00'), 'opt_price': nan, 'high': 2145.5, 'open': 2145.5}
[2016-10-25 09:11:28,058] ERROR in app: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:11:28,058 [ERROR]: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:11:28,069] ERROR in app: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:11:28,069 [ERROR]: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
CLZ2016_FUT not in position. Sending a bracket  SELL order...
[2016-10-25 09:11:58,061] ERROR in app: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:11:58,061 [ERROR]: Exception on /trades [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 194, in trades
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NOT NULL AND entry_time>='2016-10-18'
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
[2016-10-25 09:11:58,075] ERROR in app: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback
2016-10-25 09:11:58,075 [ERROR]: Exception on /positions [GET]
Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1400, in execute
    cur.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 834, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1004, in _write_bytes
    self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/reports.py", line 222, in positions
    trades  = pd.read_sql(trades_query, self.dbconn)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 399, in read_sql
    chunksize=chunksize)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1435, in read_query
    cursor = self.execute(*args)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1408, in execute
    raise_with_traceback(ex)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/compat/__init__.py", line 339, in raise_with_traceback
    raise exc.with_traceback(traceback)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/io/sql.py", line 1404, in execute
    self.con.rollback()
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 771, in rollback
    self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1054, in _execute_command
    self._write_bytes(packet)
  File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pymysql/connections.py", line 1006, in _write_bytes
    raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pandas.io.sql.DatabaseError: Execution failed on sql: SELECT * FROM trades WHERE exit_time IS NULL
(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
unable to rollback

Bracket Order

Does the instrument support bracket order? I cannot find it in the documentation.

backtest issues

algo.py:158 uses self.output instead of self.record_output

algo.py:175. blotter.drip() does not support quote_handler as parameter.

Recieved bar with all values NaN or completely empty

Hi Ran. I run the following code and very often (specially when I have many symbols) I receive bars with all fields NaN. Also, I sometimes receive empty bars as well.

Example output:

---------- This is for instrument: CVS ----------
   high  open  close  volume  low symbol symbol_group asset_class  signal
3   NaN   NaN    NaN     NaN  NaN    NaN          NaN         NaN     NaN
{'T': 3, 'ABBV': 4, 'GOOG': 2, 'MMM': 3, 'CVS': 4, 'MP': 0, 'AXP': 3, 'ABT': 3,
'ALL': 3, 'AMZN': 4, 'BMY': 3, 'AAPL': 4, 'GOOGL': 2, 'AMGN': 4, 'BLK': 1, 'BAC'
: 4, 'COF': 3, 'ACN': 3, 'BIIB': 3, 'BA': 3, 'AIG': 4, 'AGN': 3}
Total number of on_bar called: 68
Total number of non empty bars recieved: 66

Code:

from qtpylib.algo import Algo
import pandas as pd
import threading

class TestStrategy(Algo):
    def on_start(self):
        self.bar_count = dict.fromkeys(self.symbols, 0)
        self.counter = 0
        self.lock = threading.Lock()
        print("Started...")

    def on_bar(self, instrument):
        if not instrument:
            return

        self.lock.acquire()
        bars = instrument.get_bars(28)
        print('-'*10, 'This is for instrument:', instrument.get_symbol(), '-'*10)
        if len(bars.index):
            self.bar_count[instrument] = self.bar_count[instrument] + 1
            print(bars.tail(1))
        self.counter = self.counter + 1
        allbars = 0
        for symbl in self.symbols:
             allbars = self.bar_count[symbl] + allbars
        print(self.bar_count)
        print('Total number of on_bar called:', self.counter)    
        print('Total number of non empty bars recieved:', allbars)
        print('-'*50)
        self.lock.release()
  

if __name__ == "__main__":
    sp500 = pd.DataFrame.from_csv('../datas/sp500.csv', index_col = None)

    strategy = TestStrategy(
        bar_window = 28,
        #instruments = sp500.iloc[:,0].tolist()[0:98],
        instruments = ['MMM', 'T', 'ABBV', 'ABT', 'ACN', 'AGN', 'ALL', 'GOOG', 'GOOGL', 'MP', 'AMZN', 'AXP', 'AIG', 'AMGN', 'AAPL',
                        'BAC', 'BIIB', 'BLK', 'BA', 'BMY', 'CVS', 'COF'],
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

Instrument CASH

Hi Ran,
your qtpylib is great. I would like to treat CASH instruments (EUR,CASH,IDEALPRO,USD,,, in symbols.csv), and it looks like the incomming quote data is not treated, and neither stored in the DB and not otherwise.
The incomming quote looks like
QUOTE is {'bid': 1.1136999999999999, 'lastsize': 0.0, 'asksize': 18000000.0, 'ask': 1.11375, 'last': 0.0, 'bidsize': 3178000.0}

It is broadcasted, but not stored in the DB with log2db, and not stored internally.

Can you give me a hint how to integrate this?

Thanks and kind regards,
Ernst

No data from Blotter to Algo

Hi Ran,
thanks again for creating qtpylib, it is great.

I have a strange behaviour: if I create a fresh Anaconda environment, install qtpylib there (with pip install qtpylib --upgrade --no-cache-dir), create the database and run the blotter, the quote data for AAPL is stored in the database.
However, if I start a simple strategy - only printing when on_bar() is called, I only get the printout once, so on_bar() is called only once. If I print the bars, they are the first bars when the blotter was started, not the current bars. Then, nothing happens.

If I start the same strategy on an older install (a few weeks) of qtpylib on another machine, the strategy runs fine.

If I remove the line

preload     = "1D", # preload 1 day history when starting

from the instrument definition, it works.

strategy = AAPLStrat(
        instruments = [ ("AAPL", "STK", "SMART", "USD", "", 0.0, "") ], # ib tuples
        resolution  = "1min", # Pandas resolution (use "K" for tick bars)
        tick_window = 20, # no. of ticks to keep
        bar_window  = 5, # no. of bars to keep
        preload     = "1D", # preload 1 day history when starting

The only difference is that TWS runs on the second, older machine where it works. Can this be the reason?

Thank,
Ernst

back testing bar data?

Hi, by checking the source code, I cannot figure out how the platform handle orders while back testing. Do I have to handle it by myself?

Blotter.drip(history...) --> bar handler for each bar

Once a buy signal appears in the current bar, i want to create a stop order that 5 cents above the current high. How do I know if the order is filled through the platform? Do I have to implement by myself,i.e fill/cancel/modify order status during next bar? And how can i get the back testing results?

get_portfolio() is empty

I am using your QTPyLib to paper trade some algorithm ideas. I have troubles however when trying to get the portfolio details (equity positions, cash, etc) when up and running with a paper trading account.

In the on_quote() method, I am making calls to self.get_portfolio(), but the return type is empty, despite having open positions and cash visible in TWS itself.

I have referenced your documentation, and it seems my approach is correct, but it is also unclear if get_portfolio only returns positions for a particular stock.

Can you clarify this problem?

Exception in message dispatch

Hi Ran, I started getting the same issue I reported #32 . It was fixed but after new updates it started showing up:

(python3) C:\Users\Reza\trading\glt>python blotter.py 
2016-12-17 00:41:02,204 [INFO] qtpylib.blotter: Connecting to Interactive Broker
s...
2016-12-17 00:41:03,219 [INFO] qtpylib.blotter: Connection established...
2016-12-17 00:41:03,953 [INFO] qtpylib.blotter: Contract Added [IBKR]
2016-12-17 00:41:04,561 [INFO] qtpylib.blotter: Contract Added [AAPL]
17-Dec-16 00:41:07 ERROR     Exception in message dispatch.  Handler 'handleServ
erEvents' for 'tickString'
Traceback (most recent call last):
  File "C:\Users\Reza\AppData\Local\Continuum\Anaconda2\envs\python3\lib\site-pa
ckages\ib\opt\dispatcher.py", line 44, in __call__
    results.append(listener(message))
  File "C:\Users\Reza\AppData\Local\Continuum\Anaconda2\envs\python3\lib\site-pa
ckages\ezibpy\ezibpy.py", line 249, in handleServerEvents
    self.handleTickString(msg)
  File "C:\Users\Reza\AppData\Local\Continuum\Anaconda2\envs\python3\lib\site-pa
ckages\ezibpy\ezibpy.py", line 837, in handleTickString
    self.ibCallback(caller="handleTickString", msg=msg)
  File "C:\Users\Reza\AppData\Local\Continuum\Anaconda2\envs\python3\lib\site-pa
ckages\qtpylib\blotter.py", line 303, in ibCallback
    self.on_tick_string_received(msg.tickerId, kwargs)
  File "C:\Users\Reza\AppData\Local\Continuum\Anaconda2\envs\python3\lib\site-pa
ckages\qtpylib\blotter.py", line 406, in on_tick_string_received
    "bid":          float(Decimal(tick['bid'].values[-1])),
TypeError: conversion from numpy.int64 to Decimal is not supported
2016-12-17 00:41:16,490 [INFO] qtpylib.blotter: Blotter stopped...
2016-12-17 00:41:16,490 [INFO] qtpylib.blotter: Cancel market data...
2016-12-17 00:41:16,492 [INFO] qtpylib.blotter: Disconnecting...
2016-12-17 00:41:16,492 [INFO] qtpylib.blotter: Deleting runtime args...
2016-12-17 00:41:16,493 [INFO] qtpylib.blotter: Disconnecting from MySQL...

backfill

Any plans handle disconnects and/or automatic backfill of history ?

Dashboard cannot find blotter

I have looked at many different libraries and among all the options out there I really like the simplicity and power of QtPyLib. Thanks for sharing it!

I installed the module and prepared all the pre-requisites. I tried to run the example that comes with documentation. I successfully run blotter.py. However, when I run the dashboard.py, I get this message, even though the blotter is running:

python dashboard.py
[ERROR] Cannot connect to running Blotter [MainBlotter]

What could be the reason?

hdf5 storage for blotter

At this time mysql is very tightly integrated into the blotter. Do you have plans supporting other storage options as hdf5?
I just tried to insert 11 months of 1min bars (≈40M) from S&P500 into mysql and it took the whole day VS in hdf5 takes minutes.
Since you only have one blotter and nothing else communicating with the DB using a server seems overkill.

get_data_ib fails with KeyError the second time it is called.

qtpylib version: '1.5.59a'

If you run get wf.get_data_ib twice in the same notebook kernel, the second call fails with a key error.

You reproduce this by either calling for the same instrument twice or a different instrument. The first to the function works and returns a data frame... the second fails with a key error.

e.g.

# get data from ib finance
estuple = ("ES", "FUT", "GLOBEX", "USD", 201703, 0.0, "")

es = wf.get_data_ib(estuple, '2016-01-01', '1 day')
es.describe()

Will work the first time you call it, but the second time it fails with.

KeyError                                  Traceback (most recent call last)
<ipython-input-5-30f55c2913eb> in <module>()
      2 estuple = ("ES", "FUT", "GLOBEX", "USD", 201703, 0.0, "")
      3 
----> 4 es = wf.get_data_ib(estuple, '2010-01-01', '1 day')
      5 es.head()
      6 es.describe()

/home/ric/miniconda3/envs/qtpylib/lib/python3.6/site-packages/qtpylib/workflow.py in get_data_ib(instrument, start, resolution, blotter, output_path)
    261     ibConn.disconnect()
    262 
--> 263     data = ibConn.historicalData[contract_string]
    264     data['datetime'] = data.index
    265     return prepare_data(instrument, data, output_path=output_path)

KeyError: 'ESH2017_FUT'

Algo with 1S resolution does not get a bar every second

If I request a bar every second, I would expect to get, well... a bar every second, even if the quote has not changed.

from qtpylib.algo import Algo
from time import time


class SecBar(Algo):
    def on_bar(self, instrument):
        print('bar {:.0f} {}'.format(time(), instrument.bar['datetime']))


if __name__ == '__main__':
    SecBar(["AAPL"], '1S').run()

But as you can see there are multi-second gaps between bars:

$ python sec_test.py 
bar 1478844262 2016-11-11 06:04:21
bar 1478844264 2016-11-11 06:04:23
bar 1478844267 2016-11-11 06:04:26
bar 1478844269 2016-11-11 06:04:28
bar 1478844272 2016-11-11 06:04:32
bar 1478844274 2016-11-11 06:04:34
bar 1478844277 2016-11-11 06:04:37
bar 1478844280 2016-11-11 06:04:40

Am I misunderstanding how bars are supposed to work?

KeyError looking up contract on forex order

I'm trying to put in an order for ("EUR", "CASH", "IDEALPRO", "USD").

Traceback (most recent call last):
  File "strategy.py", line 84, in set_position
    self.instrument.order('BUY' if qty > 0 else 'SELL', abs(qty))
  File "/progs/qtpy/python/src/qtpylib/qtpylib/instrument.py", line 180, in order
    self.parent.order(direction.upper(), self, quantity, **kwargs)
  File "/progs/qtpy/python/src/qtpylib/qtpylib/algo.py", line 470, in order
    self._create_order(**kwargs)
  File "/progs/qtpy/python/src/qtpylib/qtpylib/broker.py", line 589, in _create_order
    contract = self.get_contract(symbol)
  File "/progs/qtpy/python/src/qtpylib/qtpylib/broker.py", line 794, in get_contract
    return self.ibConn.contracts[self.ibConn.tickerId(symbol)]
KeyError: 2

If I print the relevant variables in Broker.get_contract():

symbol ('EUR', 'CASH', 'IDEALPRO', 'USD')

self.ibConn.contracts
1 {'m_expiry': '', 'm_currency': 'USD', 'm_strike': 0.0, 'm_includeExpired': False, 'm_secType': 'CASH', 'm_exchange': 'IDEALPRO', 'm_conId': 0, 'm_right': '', 'm_symbol': 'EUR'}

self.ibConn.tickerIds
0 SYMBOL
1 EURUSD_CASH

Looks like tickerId() is not matching, then creates a new ID?

1T vs 1S

I ran this strategy. When I set resolution to '1K' I get the bars, however when I set it to '1T' I don't get any bar even if wait many minutes:

class TestStrategy(Algo):
    def on_start(self):
         pass

    def on_bar(self, instrument):
        # nothing exiting here...
        bar = instrument.get_bar()
        print("BAR:", bar)
 
if __name__ == "__main__":
    # get most active ES contract to trade
]        instruments = [ "AAPL" ],
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

index out of range

Hi Ran, Reza again ;)

I have this code which is essentially the piece of code you saw before. The only difference is that I have 100 symbols added instead of 4 symbols. The file sp500.csv is downloaded from [https://blog.quandl.com/useful-lists] , just in case you would like to run the code.

from qtpylib.algo import Algo
from qtpylib.indicators import macd#, atr
import pandas as pd

#import qtpylib.indicators
class TestStrategy(Algo):
    def on_start(self):
        print("Started...")
   
    def on_bar(self, instrument):
        lookback = 28
        bars = instrument.get_bars(lookback = lookback)
        print("{:<5}".format(instrument.get_symbol()), len(bars))
                    
            
if __name__ == "__main__":
    sp500 = pd.DataFrame.from_csv('../datas/sp500.csv', index_col = None)

    strategy = TestStrategy(
        bar_window = 28,
        instruments = sp500.iloc[:,0].tolist()[0:99],
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

After I run the code, the blotter adds all the 100 symbols (no problem), however, the algorithm code start giving "out of range exception" and some of threads exit. Here is an example of the output

File "C:\Users\Reza\AppData\Local\Programs\Python\Python35\lib\threading.py",
line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\Reza\trading\glt\env\lib\site-packages\qtpylib\asynctools.py",
line 116, in run
    self._func()
  File "C:\Users\Reza\trading\glt\env\lib\site-packages\qtpylib\algo.py", line 1
93, in add_stale_tick
    tick = self.ticks[self.ticks['symbol']==sym][-1:].to_dict(orient='records')[
0]
IndexError: list index out of range

CERN  1
AFL   1
ALXN  1
CAT   1
AIZ   1
BK    1
AMT   1

and after longer run:


Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Reza\AppData\Local\Programs\Python\Python35\lib\threading.py",
line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\Reza\trading\glt\env\lib\site-packages\qtpylib\asynctools.py",
line 116, in run
    self._func()
  File "C:\Users\Reza\trading\glt\env\lib\site-packages\qtpylib\algo.py", line 1
93, in add_stale_tick
    tick = self.ticks[self.ticks['symbol']==sym][-1:].to_dict(orient='records')[
0]
IndexError: list index out of range

Orders don't work

I can't seem to get any orders to go through at all; no errors, but no orders. Stocks, forex, and futures. For example:

from time import time
import sys
import logging

from qtpylib.algo import Algo

logging.getLogger('ezibpy').setLevel(logging.DEBUG)


class SecBar(Algo):
    def on_fill(self, instrument, order):
        print('fill', order)

    def on_bar(self, instrument):
        bar = instrument.bar
        print('bar {:.0f} {}'.format(time(), instrument.bar['datetime']), ' '.join('{:.4f}'.format(bar[val]) for val in ('open', 'high', 'low', 'close', 'volume')), file=sys.stderr)
        instrument.order("BUY", 1)


if __name__ == '__main__':
    SecBar(["AAPL"], '1S', force_resolution=True).run()

Just prints bars all day.

If I run the ezibpy example it works fine. No idea what's going on, because there isn't really any coherent logging, so maybe I'll start there.

Storing different bar frequencies

Hi @ranaroussi

Now that we got the blotter to work and store data in mysql, I'm looking at the data in bars table. It seems that by default blotter stores 1 min bar data. Questions:-

  1. what if i want to store 1M and 15M and Daily bars? There seem to be no way to distinguish what the bar frequency is. It's almost like you need another column to specify the bar frequency.
  2. how does the strategy get the historical bar data during backtesting? For instance I have csv files for daily data that I would like to load into the pyqt database in the bars table so that it can be used for backtesting.
  3. if you run a strategy on daily data, does the system use the tick data to create daily bars? or does the Algo read daily data from the bars table to do the backtest?

Regards,
Nick

slow backtest

On my backtest with 1min bars strateg.on_bar receives a bar per 2.5 seconds. Is this a normal behavior?

No bar events followed by crash with 1S resolution

I modified the example strategy to use 1S resolution bars with AAPL, plus print ticks. It prints ticks until the start of a new minute, then crashes trying to handle a bar.

#!/usr/bin/env python

import sys

from qtpylib.algo import Algo


class DumbAlgo(Algo):

    def on_start(self):
        print('start!')

    def on_tick(self, instrument):
        print('tick!', instrument.get_tick())

    def on_bar(self, instrument):
        print('bar!', instrument.get_bar())


if __name__ == "__main__":

    # initialize the algo
    strategy = DumbAlgo(
        instruments = [ "AAPL" ],
        resolution  = "1S"
    )

    # run the algo
    strategy.run()
$ python strategy.py 
start!
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:12.370000'), 'last': 110.63, 'lastsize': 2, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:12.620000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:13.372000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:14.124000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 6, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:15.374000'), 'last': 110.61, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:16.375000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:16.628000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:16.960000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:17.126000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.64, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:18.380000'), 'last': 110.62, 'lastsize': 2, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:19.379000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 11, 'datetime': Timestamp('2016-11-09 20:01:19.629000'), 'last': 110.63, 'lastsize': 5, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 11, 'datetime': Timestamp('2016-11-09 20:01:19.881000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:21.381000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:22.883000'), 'last': 110.65, 'lastsize': 3, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:23.133000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:23.884000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:01:24.387000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:26.138000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:26.638000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:26.889000'), 'last': 110.65, 'lastsize': 5, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.65, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:29.642000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:29.893000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:31.645000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:32.647000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:32.896000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:33.647000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:34.648000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask': 110.66, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:35.650000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 9, 'datetime': Timestamp('2016-11-09 20:01:36.651000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 9, 'datetime': Timestamp('2016-11-09 20:01:38.653000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 5, 'asset_class': 'STK', 'ask': 110.67, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09 20:01:39.404000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09 20:01:39.655000'), 'last': 110.67, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09 20:01:41.157000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09 20:01:41.658000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:42.658000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 8, 'asset_class': 'STK', 'ask': 110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:43.909000'), 'last': 110.69, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 8, 'asset_class': 'STK', 'ask': 110.67, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:45.411000'), 'last': 110.68, 'lastsize': 3, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:47.414000'), 'last': 110.68, 'lastsize': 2, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:48.416000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 12, 'datetime': Timestamp('2016-11-09 20:01:49.167000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.68, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:51.420000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.69, 'opt_price': nan}
tick! {'bid': 110.68, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:52.171000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask': 110.69, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 4, 'datetime': Timestamp('2016-11-09 20:01:54.422000'), 'last': 110.66, 'lastsize': 2, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.69, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09 20:01:57.927000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:58.427000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 10, 'datetime': Timestamp('2016-11-09 20:01:59.428000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 5, 'datetime': Timestamp('2016-11-09 20:02:02.183000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL', 'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask': 110.68, 'opt_price': nan}
data                           asset_class   close    high     low    open symbol  \
datetime                                                                       
2016-11-09 20:01:00+00:00         STK  110.68  110.69  110.55  110.62   AAPL   

                          symbol_group  volume  opt_price  opt_underlying  \
datetime                                                                    
2016-11-09 20:01:00+00:00         AAPL    79.0        NaN             NaN   

                           opt_dividend  opt_volume  opt_iv  opt_oi  \
datetime                                                              
2016-11-09 20:01:00+00:00           NaN         NaN     NaN     NaN   

                           opt_delta  opt_gamma  opt_vega  opt_theta  
datetime                                                              
2016-11-09 20:01:00+00:00        NaN        NaN       NaN        NaN  
Traceback (most recent call last):
  File "/python/lib/python3.4/site-packages/pandas/indexes/base.py", line 2134, in get_loc
    return self._engine.get_loc(key)
  File "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas/index.c:4443)
  File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas/index.c:4289)
  File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13733)
  File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13687)
KeyError: 'last'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "strategy.py", line 35, in <module>
    strategy.run()
  File "/python/src/qtpylib/qtpylib/algo.py", line 222, in run
    book_handler  = self._book_handler
  File "/python/src/qtpylib/qtpylib/blotter.py", line 943, in listen
    bar_handler(df)
  File "/python/src/qtpylib/qtpylib/algo.py", line 556, in _bar_handler
    self.bars = self._update_window(self.bars, bar, window=self.bar_window, resolution=self.resolution)
  File "/python/src/qtpylib/qtpylib/algo.py", line 583, in _update_window
    df = tools.resample(df, resolution=resolution, tz=tz)
  File "/python/src/qtpylib/qtpylib/tools.py", line 305, in resample
    ohlc = data[data['symbol']==sym]['last'].resample(resolution).ohlc()
  File "/python/lib/python3.4/site-packages/pandas/core/frame.py", line 2059, in __getitem__
    return self._getitem_column(key)
  File "/python/lib/python3.4/site-packages/pandas/core/frame.py", line 2066, in _getitem_column
    return self._get_item_cache(key)
  File "/python/lib/python3.4/site-packages/pandas/core/generic.py", line 1386, in _get_item_cache
    values = self._data.get(item)
  File "/python/lib/python3.4/site-packages/pandas/core/internals.py", line 3541, in get
    loc = self.items.get_loc(item)
  File "/python/lib/python3.4/site-packages/pandas/indexes/base.py", line 2136, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas/index.c:4443)
  File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas/index.c:4289)
  File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13733)
  File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13687)
KeyError: 'last'
2016-11-09 12:02:02,546 [INFO]: Algo stopped...
2016-11-09 12:02:02,546 [INFO]: Disconnecting...
2016-11-09 12:02:02,546 [INFO]: Disconnecting from MySQL...

The crash seems to be in qtpylib/tools.py, trying to use a non-existent 'last' column of a dataframe.

ohlc = data[data['symbol']==sym]['last'].resample(resolution).ohlc()

(I modified tools.py to print data[data['symbol']==sym] before the crash)

Not sure about the missing minute of data.

Code works with IB demo account but not with paper trading account.

I run this program with IB demo account and I am able to get data, however it doesn't work with a paper trading account that I have received from IB. I receive no data! I have contacted IB and they have given me the right to receive the stock data.

from qtpylib.algo import Also
from qtpylib.indicators import macd#, air
import pandas as pd
from datetime import date time
import datetime

class TestStrategy(Algo):
    def on_start(self):
         pass
    def on_tick(self, instrument):
        pass
    def on_bar(self, instrument):      
        lookback = 28
        for symbol in self.instruments:
            instr = self.get_instrument(symbol)
            bars = instr.get_bars(lookback = loopback)
            print(symbol, len(bars))
        
if __name__ == "__main__":
    strategy = TestStrategy(
        #instruments = prescreening('2014-04-25', '2014-04-29'),
        instruments = ['IBKR', 'AAPL', 'OXY', 'SLB'], 
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

Many symbols

I'd like to implement a day trading strategy in following manner: each day, before the market starts, I need to calculate a list of signals for all S&P500 and perform an screening process and choose about 100 companies. Then I need to trade them on a minute based data. Given the high number of companies that I would like to track in the market on minute basis, are you aware of any limitation in the framework to handle that volume of symbols?

This is related issue to [issue with multi-instrument #37]
Thanks again Ran!

Could not get FUT data.

Ran,
Thank for you QTPyLib,I have tested severa weeks,It is very execllent!!!

I have a problem about FUT can not get quote and tick,

Because i use my live account to try get XINA50 FUT(i have subscribed data) quote and tick ,

Like this:(instruments = [("XINA50", "FUT", "SGX", "USD", 201610, 0.0, "")],) But can not get it.

I do not know how to right do it,Can you give me some advice,

Thanks and kind regards,

Error validating request:-'td' : cause - Missing order exchange

Intermittently have the following error when running dumb_algo test. Stops it trading on each bar.

2016-12-30 06:55:01,053 [DEBUG] qtpylib.algo: ORDER: EXIT    0 AAPL {}
2016-12-30 06:55:01,055 [DEBUG] ezibpy: MSG <nextValidId orderId=6>
2016-12-30 06:55:01,093 [DEBUG] ezibpy: MSG <error id=6, errorCode=321, errorMsg=Error validating request:-'td' : cause - Missing order exchange>
2016-12-30 06:55:01,093 [ERROR] ezibpy: [#321] Error validating request:-'td' : cause - Missing order exchange
2016-12-30 06:55:01,093 [DEBUG] ezibpy: MSG <nextValidId orderId=6>

secType OPT, FOP order

Hi Ran

I am trying to test placing order for secType OPT and FOP (using version 4.91). Looks like tick data is coming through but nothing into db tables.

Is this working at your side.

Test Tuple:
("ES", "FOP", "GLOBEX", "USD", 20161216, 2120, "PUT")
("AAPL", "OPT", "SMART", "USD", 20161028, 115.0, "PUT")

Not sure anything obvious that I am missing. Could you please check this out.

Thanks!

Error getting data from IB in workflow

external_data = wf.get_data_ib("AAPL",start="2012-01-01", resolution="1 day")

returns this.

-------------------------

Traceback (most recent call last):
  File "/Users/damani/PycharmProjects/blackbox/strategy.py", line 72, in <module>
    external_data = wf.get_data_ib("AAPL",start="2012-01-01", resolution="1 day")
  File "/Users/damani/anaconda/lib/python3.6/site-packages/qtpylib/workflow.py", line 265, in get_data_ib
    return prepare_data(instrument, data, output_path=output_path)
  File "/Users/damani/anaconda/lib/python3.6/site-packages/qtpylib/workflow.py", line 372, in prepare_data
    df.index = df.index.tz_localize(tools.get_timezone()).tz_convert("UTC")
  File "/Users/damani/anaconda/lib/python3.6/site-packages/pandas/util/decorators.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/Users/damani/anaconda/lib/python3.6/site-packages/pandas/tseries/index.py", line 1821, in tz_localize
    tz = tslib.maybe_get_tz(tz)
  File "pandas/tslib.pyx", line 1753, in pandas.tslib.maybe_get_tz (pandas/tslib.c:32549)
  File "pandas/tslib.pyx", line 1768, in pandas.tslib.maybe_get_tz (pandas/tslib.c:32362)
  File "/Users/damani/anaconda/lib/python3.6/site-packages/pytz/__init__.py", line 181, in timezone
    raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'Etc/GMT-17'

Any chance or plans to integrate FX broker OANDA into qtpylib

Hi Ran,
This library is simple and great . Do you have any plans of adding or integrating FX Broker OANDA into the qtpyLib ? it would be fantastic . i love this qtpyLib Library because it uses ZeroMQ framework in Pub/Sub architecture . OANDA uses REST API v1 or v2 (is the current). i think it might be easier to integrate into qtpylib.

Allow passing all parameters programmatically to Algo and Blotter classes

I prefere testing and developing about everything in a Jupyter notebook instead of in a script and have hard time passing command-line arguments. Would like to initialize a strategy and a blotter with arguments normally passed to command-line as so:

strategy = CrossOver(
    # passing backtest does not change strategy.backtest at this time
    backtest = True,
    start = '2016-01-01',
    end = '2016-02-01'
)

and blotter with symbols in it:

blotter = MainBlotter(
    # passing symbols does not change blotter.symbols at this time
    symbols   = '/Users/evo/projects/test/symbols.csv',
)

Data not being stored to database

Really like the approach you are taking here and look forward to participating in the improvement.

But in the short term, I'm struggling to get data into the local mysql database. Hoping you can give some suggestions as to how to further debug this.

Currently connecting to a remote TWS instance. I've tried running TWS on a couple of different systems in case there is an API problem. As you can see below, Blotter starts up and indicates it is adding the contracts.

2016-12-05 21:49:30,797 [INFO] qtpylib.blotter: Connecting to Interactive Brokers...
Server Version: 76
TWS Time at connection:20161205 14:49:30 MST
2016-12-05 21:49:32,023 [INFO] qtpylib.blotter: Connection established...
2016-12-05 21:49:32,756 [INFO] qtpylib.blotter: Contract Added [AAPL]
2016-12-05 21:49:33,370 [INFO] qtpylib.blotter: Contract Added [ESZ2016]

But looking in the mysql database running on the same server, I have no data stored to the tables:

qtpy@localhost [qtpy]> show tables;
+----------------+
| Tables_in_qtpy |
+----------------+
| _version_      |
| bars           |
| greeks         |
| symbols        |
| ticks          |
| trades         |
+----------------+
6 rows in set (0.00 sec)

qtpy@localhost [qtpy]> select * from bars;
Empty set (0.00 sec)

qtpy@localhost [qtpy]> select * from symbols;
Empty set (0.00 sec)

qtpy@localhost [qtpy]> select * from ticks;
Empty set (0.00 sec)

I ran into some other errors when trying to add some ETFs like SPY, SSO, etc. but will see if first I can get this working with your example instruments. TWS is configured as you show in your screenshots.

Integration with zipline

Hi,
excellent share for the community.
Have you thought of integrating with Zipline - https://github.com/quantopian/zipline
Can you provide some insights as per where you would start, I would gladly try to bridge them in order to get a backup in case Quantopian (commercial zipline for live trading) goes down.

hangs when backtesting

Just installed qtpylib-1.5.27, a botter running. The strategy looks like this:

class Strategy(Algo):
    def on_bar(self, instrument):
        print('.')
strategy = Strategy(
    instruments=["GOOG"],
    resolution="1min",
    backtest=True,
    start='2016-01-05',
    end='2016-01-05',
    output='portfolio.pkl'
)
print(strategy.backtest) # prints True
strategy.run()

It hangs with CPU usage of 100% and nothing is printed.
One minute bars are in the database. Mysql only shows two sleeping connections from the botter.
When I stop the strategy script ( botter still running ) the cpu usage goes back to normal.

symbols

It would be nice to include the contract tuple values in symbols table and provide apis to query symbolid for specified contract tuple and internal single word symbol.

[strategy example]AttributeError: 'NoneType' object has no attribute 'ndim'

$ python strategy.py --log strategy/ --ibport 7491 --output strategy/
Active month for ES is: 201612
Server Version: 76
TWS Time at connection:20161024 23:22:22 CST
ESZ2016_FUT not in position. Sending a bracket SELL order...
Traceback (most recent call last):
File "strategy.py", line 106, in
strategy.run()
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/algo.py", line 206, in run
bar_handler = self._bar_handler
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/blotter.py", line 909, in listen
tick_handler(df)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/algo.py", line 491, in _tick_handler
self.on_tick(self.get_instrument(tick))
File "strategy.py", line 83, in on_tick
self.record(take_action=1)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/algo.py", line 439, in record
self.datastore.record(self.record_ts, _args, *_kwargs)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/qtpylib/tools.py", line 478, in record
row = pd.DataFrame(data=data, index=[timestamp])
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/core/frame.py", line 266, in init
mgr = self._init_dict(data, index, columns, dtype=dtype)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/core/frame.py", line 402, in _init_dict
return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/core/frame.py", line 5384, in _arrays_to_mgr
arrays = _homogenize(arrays, index, dtype)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/core/frame.py", line 5695, in _homogenize
raise_cast_failure=False)
File "/Users/qtpylib_user/anaconda3/envs/qtpylib/lib/python3.5/site-packages/pandas/core/series.py", line 2919, in _sanitize_array
if subarr.ndim == 0:
AttributeError: 'NoneType' object has no attribute 'ndim'
2016-10-24 23:22:31,191 [INFO]: Algo stopped...
2016-10-24 23:22:31,195 [INFO]: Disconnecting...
2016-10-24 23:22:31,198 [INFO]: Disconnecting from MySQL...

disable continuous contract

Is there anyway to turn off the automatic continuous contract selection in the preload ? I am trying to preload CLZ2016, but it is loading CLX2016.

Futures contract data not being downloaded by blotter.

I start by adding the following line to symbols.csv

ES,FUT,GLOBEX,USD,201612,0.0,

After starting blotter, the line is changed to add a .0 to the end of the expiry value.

ES,FUT,GLOBEX,USD,201612.0,0.0,

No ES data is saved to the database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.