Repository: scrtlabs/catalyst

Issue #178: Completed orders on Binance & Poloniex are sometimes being reported as perpetually "not filled" by exchange_blotter
Created: 2018-01-22T05:21:15Z
Dear Catalyst Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment

Operating System: Windows 10
Python Version: Python 2.7.13 :: Anaconda 4.4.0 (64-bit)
Python Bitness: Command fails
How did you install Catalyst: Conda
Python packages:

alembic                   0.9.6                     <pip>
backports.functools-lru-cache 1.4                       <pip>
bcolz                     0.12.1                    <pip>
boto3                     1.5.19                    <pip>
botocore                  1.8.33                    <pip>
Bottleneck                1.2.1                     <pip>
ca-certificates           2017.08.26           h94faf87_0
ccxt                      1.10.774                  <pip>
certifi                   2016.2.28                py27_0
certifi                   2018.1.18                 <pip>
chardet                   3.0.4                     <pip>
click                     6.7                       <pip>
contextlib2               0.5.5                     <pip>
cycler                    0.10.0                    <pip>
cyordereddict             1.0.0                     <pip>
Cython                    0.27.1                    <pip>
decorator                 4.1.2                     <pip>
docutils                  0.14                      <pip>
empyrical                 0.2.1                     <pip>
enigma-catalyst           0.4.7                     <pip>
futures                   3.2.0                     <pip>
idna                      2.6                       <pip>
intervaltree              2.1.0                     <pip>
jmespath                  0.9.3                     <pip>
Logbook                   1.1.0                     <pip>
lru-dict                  1.1.6                     <pip>
Mako                      1.0.7                     <pip>
MarkupSafe                1.0                       <pip>
matplotlib                2.1.0                     <pip>
mkl                       2017.0.3                      0
multipledispatch          0.4.9                     <pip>
networkx                  2.0                       <pip>
numexpr                   2.6.4                     <pip>
numpy                     1.13.1                   py27_0
openssl                   1.0.2l            vc9hb274bc6_5  [vc9]
pandas                    0.19.2                    <pip>
pandas-datareader         0.5.0                     <pip>
patsy                     0.4.1                     <pip>
pip                       9.0.1                    py27_1
pyparsing                 2.2.0                     <pip>
python                    2.7.13              h1b6d89f_16
python-dateutil           2.6.1                     <pip>
python-editor             1.0.3                     <pip>
pytz                      2017.2                    <pip>
redo                      1.6                       <pip>
requests                  2.18.4                    <pip>
requests-file             1.4.2                     <pip>
requests-ftp              0.3.1                     <pip>
s3transfer                0.1.12                    <pip>
scikit-learn              0.19.1                    <pip>
scipy                     0.19.1              np113py27_0
setuptools                36.4.0                   py27_1
six                       1.11.0                    <pip>
sortedcontainers          1.5.7                     <pip>
SQLAlchemy                1.1.14                    <pip>
sqlite                    3.13.0                    vc9_1  [vc9]
statsmodels               0.8.0                     <pip>
subprocess32              3.2.7                     <pip>
TA-Lib                    0.4.16                    <pip>
tables                    3.4.2                     <pip>
tk                        8.5.18                    vc9_0  [vc9]
toolz                     0.8.2                     <pip>
urllib3                   1.22                      <pip>
vc                        9                    h7299396_1
vs2008_runtime            9.00.30729.1         hfaea7d5_1
wheel                     0.29.0                   py27_0
wincertstore              0.2              py27hf04cefb_0
zlib                      1.2.11               hbc2faf4_2

Now that you know a little about me, let me tell you about the issue I am
having:
Description of Issue
This does not occur every time, but when I place on order on Binance live, sometimes, it does not register the order as filled. The exchange blotter continues to report the order as open, even though it clearly shows it filled on Binance. The position amount also does not update. Here is what it looks like when a buy order works:
[2018-01-22 04:18:05.033000] INFO: mean_reversion_binance: Pricerise: True, Pricerisecount: 3, pos_amount: 0, Minute Count: 1, Price: 1069.41, Trade Happened: False
[2018-01-22 04:18:05.546000] INFO: mean_reversion_binance: 2018-01-22 04:18:00+00:00: buying - price: 1069.41, rsi: 61.8281815443, reason: None
[2018-01-22 04:18:06.072000] INFO: CCXT: adjusted order amount 0.0922413095149 to 0.09224 based on lot size
[2018-01-22 04:18:06.619000] INFO: exchange_algorithm: statistics for the last 1 minutes:
......
[2018-01-22 04:19:00.817000] INFO: exchange_blotter: filled order 18336995 / eth_usdt: 0.09224, avg price: 1072.0
[2018-01-22 04:19:01.807000] INFO: exchange_algorithm: portfolio balances, cash: 2.3896038, positions: 98.88128

And here is what it looks like when the exchange_blotter doesn't recognize the order as filled:
[2018-01-22 04:58:04.836000] INFO: mean_reversion_binance: Pricerise: True, Pricerisecount: 3, pos_amount: 0, Minute Count: 1, Price: 1058.99, Trade Happened: False
[2018-01-22 04:58:05.352000] INFO: mean_reversion_binance: 2018-01-22 04:58:00+00:00: buying - price: 1058.99, rsi: 56.6059504113, reason: None
[2018-01-22 04:58:05.835000] INFO: CCXT: adjusted order amount 0.0923728494131 to 0.09237 based on lot size
[2018-01-22 04:58:06.426000] INFO: exchange_algorithm: statistics for the last 1 minutes:
[2018-01-22 04:59:00.707000] INFO: exchange_blotter: order 18345240 still open after 0 days 00:00:54.450000
[2018-01-22 04:59:01.196000] INFO: exchange_algorithm: portfolio balances, cash: 0.0, positions: 0.0
[2018-01-22 04:59:05.682000] INFO: mean_reversion_binance: Pricerise: False, Pricerisecount: 1, pos_amount: 0, Minute Count: 1, Price: 1060.79, Trade Happened: True
[2018-01-22 04:59:05.762000] INFO: exchange_algorithm: statistics for the last 1 minutes:
....
[2018-01-22 05:00:01.010000] INFO: exchange_blotter: order 18345240 still open after 0 days 00:01:54.754000
[2018-01-22 05:00:01.514000] INFO: exchange_algorithm: portfolio balances, cash: 0.0, positions: 0.0
[2018-01-22 05:00:06.189000] INFO: mean_reversion_binance: Pricerise: False, Pricerisecount: 2, pos_amount: 0, Minute Count: 2, Price: 1061.75, Trade Happened: True
[2018-01-22 05:00:06.271000] INFO: exchange_algorithm: statistics for the last 1 minutes:
...
[2018-01-22 05:01:00.524000] INFO: exchange_blotter: order 18345240 still open after 0 days 00:02:54.268000
[2018-01-22 05:01:01.025000] INFO: exchange_algorithm: portfolio balances, cash: 0.0, positions: 0.0
[2018-01-22 05:01:05.522000] INFO: mean_reversion_binance: Pricerise: True, Pricerisecount: 1, pos_amount: 0, Minute Count: 3, Price: 1061.56, Trade Happened: True
[2018-01-22 05:01:05.596000] INFO: exchange_algorithm: statistics for the last 1 minutes:
...
[2018-01-22 05:02:00.858000] INFO: exchange_blotter: order 18345240 still open after 0 days 00:03:54.602000
[2018-01-22 05:02:01.342000] INFO: exchange_algorithm: portfolio balances, cash: 0.0, positions: 0.0

Here is what I see on Binance:

As you can see, the trade for $1058.99 went through successfully on the 58 minute mark. You can also see the trade on the 18 minute mark, but actually while I posted a buy at a price of $1069.41, it bought for $1072.
After reviewing that, perhaps it's related to my buy code?
orders = get_open_orders(context.market)

        if len(orders) > 0:
            log.info(
                '{} orders open, trying to cancel.'.format(
                    len(orders))
            )
            for market, position in context.portfolio.positions.iteritems():
                order_target_percent(market, 0)
        # pos_amount == 0 pricerise and
        elif pricerise and context.pricerisecount >= 3 and pos_amount == 0:
            log.info(
                '{}: buying - price: {}, rsi: {}, reason: {}'.format(
                    data.current_dt, price, getLast(indicators, 'rsi'), context.reason
                )
            )
            # Set a style for limit orders,

            order_target_percent(
                context.market, 1, limit_price=price * 1.005
            )
            context.traded_today = True
            context.tradehappened = True
        elif pricerise == False and context.pricerisecount >= 3 and pos_amount > 0:
            log.info(
                '{}: selling - price: {}, rsi: {}, reason: {}'.format(
                    data.current_dt, price, getLast(indicators, 'rsi'), context.reason
                )
            )
            #limit_price = price * 1
            order_target_percent(
                context.market, 0, limit_price=price * .995
            )
            context.traded_today = True
            context.tradehappened = True
        else:
            log.info(
                '{}: no action - price: {}, rsi: {}'.format(
                    data.current_dt, price, getLast(indicators, 'rsi')
                )
            )
            context.tradehappened = False

As you can see, I am doing limit orders for 1.005 * price for buys. The one that failed to be recognized as filled looks like it was filled immediately for the current price of the ETH, whereas the one that worked went up from the price of 1069.41 to be purchased at 1072. Perhaps it is this instant fulfillment of a limit order that's causing Catalyst to not recognize the order as being filled? If so, any recommendations? I am trading on a minute by minute basis, so I don't want to set the limit too high and have it not be filled at all, I'm trying to just purchase for basically current price.
Lastly, you can see in my order logic that I'm trying to check for any open orders and sell them off as an effort to clear out what Catalyst thinks are unfilled ones. However that line of code is never hit, so it seems like these orders which never increase my position and are considered unfilled by the exchange_blotter are in fact being removed from my "open orders" list.
Here is how you can reproduce this issue on your machine:
Reproduction Steps

Hopefully the steps above are sufficient.



...
What steps have you taken to resolve this already?
Hopefully above is enough detail.
...
Anything else?
...
Sincerely,
Jarlek

Duplicate issue #198: How does Catalyst calculate the capital_base? capital_base = 1000, it becomes 511.94378394
Created: 2018-01-31T14:58:04Z
Hello Catalyst Maintainers.
I'm running BuyLowandSellHigh algorithm in live mode
# Capital_base is 1000
[2018-01-31 02:24:52.166202] INFO: Loader: Cache at /home/ubuntu/.catalyst/data/treasury_curves.csv does not have data from 1990-01-02 00:00:00+00:00 to 2018-01-30 00:00:00+00:00.
[2018-01-31 02:24:52.166500] INFO: Loader: Downloading treasury data for 'btc_usd'.
[2018-01-31 02:24:52.914407] WARNING: Loader: Still don't have expected data after redownload!
[2018-01-31 02:24:52.917983] INFO: exchange_algorithm: initialized trading algorithm in live mode
[2018-01-31 02:24:53.959906] INFO: buy low sell high: initializing algo
[2018-01-31 02:24:54.307489] INFO: exchange_algorithm: portfolio balances, cash: 1047.80503462, positions: 0.0
[2018-01-31 02:24:54.307758] INFO: buy low sell high: handling bar 2018-01-31 02:24:00+00:00
[2018-01-31 02:24:54.774680] INFO: buy low sell high: got price 10044.61
[2018-01-31 02:24:55.303092] INFO: buy low sell high: got rsi: 54.2118128242
[2018-01-31 02:24:55.303361] INFO: buy low sell high: base currency available: 1000.0
[2018-01-31 02:24:55.303608] INFO: buy low sell high: current orders1: defaultdict(<type 'list'>, {})
[2018-01-31 02:24:55.303773] INFO: buy low sell high: current orders len: 0
[2018-01-31 02:24:55.303937] INFO: buy low sell high: buying position cheaper than cost basis 10044.61 < None
[2018-01-31 02:24:55.304207] INFO: buy low sell high: buy_increment: 0.2
[2018-01-31 02:24:55.304456] INFO: CCXT: adjusted order amount 0.0199111762428 to 0.01991 based on lot size
[2018-01-31 02:24:55.787551] INFO: buy low sell high: current orders2: defaultdict(<type 'list'>, {Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None: [Order({'status': 0, 'created': Timestamp('2018-01-31 02:24:55.787192+0000', tz='UTC'), 'limit_reached': False, 'stop': None, 'amount': 0.01991, 'stop_reached': False, 'commission': 0, 'reason': None, 'limit': 10064.69922, 'sid': Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None, 'dt': Timestamp('2018-01-31 02:24:55.787192+0000', tz='UTC'), 'id': '32009084', 'filled': 0})]})
[2018-01-31 02:24:55.787786] INFO: buy low sell high: current orders len: 1
[2018-01-31 02:24:55.787970] INFO: buy low sell high: base currency after order: 1000.0
[2018-01-31 02:24:55.788136] INFO: buy low sell high: completed bar 2018-01-31 02:24:00+00:00, total execution errors 0
[2018-01-31 02:24:55.808052] INFO: exchange_algorithm: statistics for the last 1 minutes:
starting_cash  ending_cash  portfolio_value  pnl  long_exposure  short_exposure  orders  transactions     price          rsi
period_close
2018-01-31 02:25:00+00:00           1000       # 1000.0           1000.0  0.0              0               0       0             0  10044.61  54.21181282
[2018-01-31 02:25:01.004724] INFO: exchange_blotter: filled order 32009084 / btc_usdt: 0.01991, avg price: 10044.45
[2018-01-31 02:25:01.995942] INFO: exchange_algorithm: portfolio balances, cash: 847.82003512, positions: 199.5629075
[2018-01-31 02:25:01.996193] INFO: buy low sell high: handling bar 2018-01-31 02:25:00+00:00
[2018-01-31 02:25:02.496764] INFO: buy low sell high: got price 10023.25
[2018-01-31 02:25:03.032974] INFO: buy low sell high: got rsi: 54.2116255514
[2018-01-31 02:25:03.033266] INFO: buy low sell high: base currency available: 800.0150005
[2018-01-31 02:25:03.033452] INFO: buy low sell high: current orders1: defaultdict(<type 'list'>, {})
[2018-01-31 02:25:03.033607] INFO: buy low sell high: current orders len: 0
[2018-01-31 02:25:03.033901] INFO: buy low sell high: got position: Position({'last_sale_date': Timestamp('2018-01-31 02:25:01.878000+0000', tz='UTC'), 'amount': 0.01991, 'last_sale_price': 10023.25, 'asset': Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None, 'cost_basis': 10044.45})
[2018-01-31 02:25:03.034088] INFO: buy low sell high: found 0.01991 positions with cost basis 10044.45
[2018-01-31 02:25:03.034218] INFO: buy low sell high: buying position cheaper than cost basis 10023.25 < 10044.45
[2018-01-31 02:25:03.034461] INFO: buy low sell high: buy_increment: 0.2
[2018-01-31 02:25:03.034705] INFO: CCXT: adjusted order amount 0.0159631856035 to 0.015962 based on lot size
[2018-01-31 02:25:03.501452] INFO: buy low sell high: current orders2: defaultdict(<type 'list'>, {Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None: [Order({'status': 0, 'created': Timestamp('2018-01-31 02:25:03.501117+0000', tz='UTC'), 'limit_reached': False, 'stop': None, 'amount': 0.015962, 'stop_reached': False, 'commission': 0, 'reason': None, 'limit': 10043.2965, 'sid': Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None, 'dt': Timestamp('2018-01-31 02:25:03.501117+0000', tz='UTC'), 'id': '32009180', 'filled': 0})]})
[2018-01-31 02:25:03.501693] INFO: buy low sell high: current orders len: 1
[2018-01-31 02:25:03.501894] INFO: buy low sell high: base currency after order: 800.0150005
[2018-01-31 02:25:03.502097] INFO: buy low sell high: completed bar 2018-01-31 02:25:00+00:00, total execution errors 0
[2018-01-31 02:25:03.530645] INFO: exchange_algorithm: statistics for the last 1 minutes:
symbol   amount  cost_basis  last_sale_price
period_close              starting_cash ending_cash portfolio_value pnl       long_exposure short_exposure orders transactions price    rsi
2018-01-31 02:26:00+00:00 1000          # 800.0150005 999.577908      -0.422092 199.5629075   0              1      1            10023.25 54.21162555  btc_usdt  0.01991    10044.45         10023.25
[2018-01-31 02:26:00.823251] INFO: exchange_blotter: filled order 32009180 / btc_usdt: 0.015962, avg price: 10039.612843
[2018-01-31 02:26:01.807219] INFO: exchange_algorithm: portfolio balances, cash: 687.56773492, positions: 360.190752
[2018-01-31 02:26:01.807467] INFO: buy low sell high: handling bar 2018-01-31 02:26:00+00:00
[2018-01-31 02:26:02.307324] INFO: buy low sell high: got price 10041.0
[2018-01-31 02:26:02.840640] INFO: buy low sell high: got rsi: 54.2087400109
[2018-01-31 02:26:02.840954] INFO: buy low sell high: base currency available: 639.7627003
[2018-01-31 02:26:02.841133] INFO: buy low sell high: current orders1: defaultdict(<type 'list'>, {})
[2018-01-31 02:26:02.841283] INFO: buy low sell high: current orders len: 0
[2018-01-31 02:26:02.841564] INFO: buy low sell high: got position: Position({'last_sale_date': Timestamp('2018-01-31 02:26:00.416000+0000', tz='UTC'), 'amount': 0.035872, 'last_sale_price': 10041.0, 'asset': Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None, 'cost_basis': 10042.297605374664})
[2018-01-31 02:26:02.841726] INFO: buy low sell high: found 0.035872 positions with cost basis 10042.2976054
[2018-01-31 02:26:02.841855] INFO: buy low sell high: buying position cheaper than cost basis 10041.0 < 10042.2976054
[2018-01-31 02:26:02.842102] INFO: buy low sell high: buy_increment: 0.2
[2018-01-31 02:26:02.842348] INFO: CCXT: adjusted order amount 0.0127430076745 to 0.012743 based on lot size
[2018-01-31 02:26:13.148346] WARNING: CCXT: unable to create order binance / BTC/USDT: binance POST https://api.binance.com/api/v3/order request timeout
[2018-01-31 02:26:13.148881] WARNING: exchange_blotter: Ordering again.
[2018-01-31 02:26:18.154329] INFO: CCXT: adjusted order amount 0.0127430076745 to 0.012743 based on lot size
[2018-01-31 02:26:18.865707] INFO: buy low sell high: current orders2: defaultdict(<type 'list'>, {Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None: [Order({'status': 0, 'created': Timestamp('2018-01-31 02:26:18.865374+0000', tz='UTC'), 'limit_reached': False, 'stop': None, 'amount': 0.012743, 'stop_reached': False, 'commission': 0, 'reason': None, 'limit': 10061.082, 'sid': Trading Pair btc_usdt(374465) Exchange: binance, Introduced On: 2009-01-01 00:00:00+00:00, Base Currency: btc, Quote Currency: usdt, Exchange Leverage: 1.0, Minimum Trade Size: 9.99999997475e-07 Last daily ingestion: None Last minutely ingestion: None, 'dt': Timestamp('2018-01-31 02:26:18.865374+0000', tz='UTC'), 'id': '32009663', 'filled': 0})]})
[2018-01-31 02:26:18.865930] INFO: buy low sell high: current orders len: 1
[2018-01-31 02:26:18.866210] INFO: buy low sell high: base currency after order: 639.7627003
[2018-01-31 02:26:18.866391] INFO: buy low sell high: completed bar 2018-01-31 02:26:00+00:00, total execution errors 0
[2018-01-31 02:26:18.894231] INFO: exchange_algorithm: statistics for the last 1 minutes:
symbol    amount      cost_basis  last_sale_price
period_close              starting_cash ending_cash portfolio_value pnl        long_exposure short_exposure orders transactions price   rsi
2018-01-31 02:27:00+00:00 1000          # 639.7627003 999.9534523     -0.0465477 360.190752    0              1      3            10041.0 54.20874001  btc_usdt  0.035872  10042.29760537          10041.0
[2018-01-31 02:27:04.197090] INFO: exchange_blotter: filled order 32009663 / btc_usdt: 0.012743, avg price: 10030.52
Traceback (most recent call last):
File "blash.py", line 185, in 
simulate_orders=False,
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 551, in run_algorithm
stats_output=stats_output
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 330, in _run
overwrite_sim_params=False,
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 297, in run
data, overwrite_sim_params
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/algorithm.py", line 724, in run
for perf in self.get_generator():
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/gens/tradesimulation.py", line 224, in transform
for capital_change_packet in every_bar(dt):
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/gens/tradesimulation.py", line 137, in every_bar
handle_data(algo, current_data, dt_to_use)
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/utils/events.py", line 216, in handle_data
dt,
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/utils/events.py", line 235, in handle_data
self.callback(context, data)
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 741, in handle_data
cleanup=lambda: log.warn('Ordering again.')
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/redo/init.py", line 162, in retry
return action(*args, **kwargs)
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/exchange/exchange_algorithm.py", line 606, in synchronize_portfolio
cash=required_cash,
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/exchange/exchange.py", line 700, in sync_positions
cash=cash,
catalyst.exchange.exchange_errors.NotEnoughCashError: # Total usdt amount on binance is lower than the cash reserved for this algo: 431.79635556 < 511.94378394. While trades can be made on the exchange accounts outside of the algo, exchange must have enough free usdt to cover the algo cash.
(catalyst) ubuntu@ip-172-31-41-166:/binance$ python blash.py
Traceback (most recent call last):
File "blash.py", line 184, in 
simulate_orders=False,
File "/home/ubuntu/anaconda3/envs/catalyst/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 494, in run_algorithm
'Please specify a capital_base parameter which is the maximum '
ValueError: Please specify a capital_base parameter which is the maximum amount of base currency available for trading. For example, if the capital_base is 5ETH, the order_target_percent(asset, 1) command will order 5ETH worth of the specified asset.
(catalyst) ubuntu@ip-172-31-41-166:/binance$ Connection reset by 18.219.18.255 port 22

Closing comment (2018-02-01T01:22:19Z): When you enter a position, your cash decrease as the amount of that position increases. You portfolio value and p/l are calculated by adding your cash to the total value of your positions. So I don't see anything abnormal with your cash being 511 < 1000.
The problem that I see is that your cash was somehow miscalculated. If you only ordered through the algo, you would have executed 616 worth of orders but the algo thinks that is around 489. I suspect that the algo got a trade history from Binance which made it calculate a partial order as complete. I speculate that this may be related to #178 but I'd like to be sure by replicating the issue. I'm currently running several live algos including one against Binance and everything seems to add up so far. I'll switch to trading btc_usdt shortly to match your conditions as closely as possible.
In the meantime, it it's not too inconvenient for you, posting the three orders in question might be helpful. Here is a Binance screenshot to give you an idea of what I'm looking for.

Otherwise, I'll keep running transactions until I can replicate the issue or build enough confidence that fixing #178 resolve it.