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
Bug 3 - Working