catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Weird behavoir when running tests on live mode

Open Knifespirit opened this issue 8 years ago • 9 comments

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: ubuntu 16.04
  • Python Version: 2.7
  • Python Bitness: 64
  • How did you install Catalyst pip
  • Python packages: pip alembic==0.9.6 bcolz==0.12.1 boto3==1.5.1 botocore==1.8.15 Bottleneck==1.2.1 ccxt==1.10.400 certifi==2017.11.5 chardet==3.0.4 click==6.7 contextlib2==0.5.5 cyordereddict==1.0.0 Cython==0.27.3 decorator==4.1.2 docutils==0.14 empyrical==0.2.1 enigma-catalyst==0.4.0 futures==3.2.0 idna==2.6 int-date==0.1.8 intervaltree==2.1.0 jmespath==0.9.3 Logbook==1.1.0 lru-dict==1.1.6 Mako==1.0.7 MarkupSafe==1.0 multipledispatch==0.4.9 networkx==2.0 numexpr==2.6.4 numpy==1.13.3 pandas==0.19.2 pandas-datareader==0.5.0 patsy==0.4.1 pkg-resources==0.0.0 python-dateutil==2.6.1 python-editor==1.0.3 pytz==2017.3 requests==2.18.4 requests-file==1.4.2 requests-ftp==0.3.1 s3transfer==0.1.12 scipy==1.0.0 six==1.11.0 sortedcontainers==1.5.9 SQLAlchemy==1.1.15 statsmodels==0.8.0 stockstats==0.2.0 tables==3.4.2 toolz==0.9.0 urllib3==1.22

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

When testing your code on live mode it will save the settings in some file so you can continue where you left of. When your are testing your code this becauses problematic. I was running code that would use all your cash to buy but when i was running i live mode the cash was diffrent than the cash i really had.

This will not only happen to your cash but anything, like position and currency pair (for example the new code was running on the currency pair etc_btc but it still displayed the currency pair ltc_btc)

  • What did you expect to happen? I expected the bot to use the cash I had instead of getting a cash amount from the saved file

  • What happened instead? The cash amount that my bot had was not simmulair with the cash amount I really had

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. Run some bot
  2. Chance the bot a bit like currency pair or use some cash you have to buy something
  3. Run the bot again. Some values now wont match up .

What steps have you taken to resolve this already?

version = '0.06' NAMESPACE = 'rsi_trade - v{}'.format(version)

I change the version everytime i changed my code

Anything else?

I dont know if this is the expected behavoir but what i can say is that its very anoying when you dont kow what is happening. Maybe its good to have some kind of clean cach function? Or a live testing mode? Or just a varaible that u can adjust where u say "dont save my progress"

Sincerely, `Vincent

Knifespirit avatar Dec 20 '17 10:12 Knifespirit

Sorry, I don't doubt the issue but I don't have a good enough idea of what's going on to replicate it. Which values do not match between frames. In live mode, the algo state is saved to disk. To reset it, run:

catalyst clean-algo -n {namespace of your algo}

fredfortier avatar Dec 20 '17 18:12 fredfortier

The values that didnt match for me were cash, position and currency pair. I dont think this is a real issue since you just told me how to clean it. (Also two of the clean commands didnt work for me, but i looked at it quite quickly a while ago)

I think there should be some information about the cleaning in de docs but maybe its just me but i was really confused why my values were diffrent until i saw in the example code a file is saved every time you run life mode. I got quite some problems with expected values so in develpment i think its nice to always clean it. (I prefer not the develop in live but as a new user it is nice to test it out) (i am not just new to catalyst but trading in general)

In general alot of the confusion i had with catalyst came from not having enough information from the docs. I will be looking in how to contribute to the docs.

Knifespirit avatar Dec 21 '17 06:12 Knifespirit

I tried cleaning up the algo, but the positions are still wrong. The algorithm crashed after making an order and the order got filled, but when I restart it, it says I have 0 positions, even after cleanup.

caioaao avatar Dec 29 '17 23:12 caioaao

@caioaao do you have the stack trace related with this incident? Something specific must have happened. I did resolve an issue with placing orders with Poloniex last week (some inconsistency with how it's presenting the order_id). This is resolved in the "develop" branch, but we did not issue a release yet. The stack trace will allow me to confirm that it's the same issue.

fredfortier avatar Dec 30 '17 00:12 fredfortier

I think it was just an API instability or backpressure (idk how many requests/sec are being made to poloniex api when a buy happens). anyway, here's the stack trace when it blew up:

[2017-12-29 23:19:00.993179] WARNING: exchange_blotter: check open orders attempt 0: Request failed: 'Exchange'
[2017-12-29 23:19:07.512328] WARNING: exchange_blotter: check open orders attempt 1: Request failed: 'Exchange'
[2017-12-29 23:19:12.658269] WARNING: exchange_blotter: check open orders attempt 2: Request failed: 'Exchange'
[2017-12-29 23:19:19.220624] WARNING: exchange_blotter: check open orders attempt 3: Request failed: 'Exchange'
[2017-12-29 23:19:24.323487] WARNING: exchange_blotter: check open orders attempt 4: Request failed: 'Exchange'
[2017-12-29 23:19:30.453291] WARNING: exchange_blotter: check open orders attempt 5: Request failed: 'Exchange'
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/strat.py", line 185, in <module>
live=True)
File "/usr/local/lib/python2.7/dist-packages/catalyst/utils/run_algo.py", line 563, in run_algorithm
stats_output=stats_output
File "/usr/local/lib/python2.7/dist-packages/catalyst/utils/run_algo.py", line 346, in _run
overwrite_sim_params=False,
File "/usr/local/lib/python2.7/dist-packages/catalyst/algorithm.py", line 724, in run
for perf in self.get_generator():
File "/usr/local/lib/python2.7/dist-packages/catalyst/gens/tradesimulation.py", line 224, in transform
for capital_change_packet in every_bar(dt):
File "/usr/local/lib/python2.7/dist-packages/catalyst/gens/tradesimulation.py", line 122, in every_bar
blotter.get_transactions(current_data)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 297, in get_transactions
return self.get_exchange_transactions()
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions
return self.get_exchange_transactions(attempt_index + 1)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions
return self.get_exchange_transactions(attempt_index + 1)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions
return self.get_exchange_transactions(attempt_index + 1)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions
return self.get_exchange_transactions(attempt_index + 1)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions
return self.get_exchange_transactions(attempt_index + 1)
File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 289, in get_exchange_transactions
error=e
catalyst.exchange.exchange_errors.ExchangePortfolioDataError: Unable to retrieve portfolio data: order-status, giving up after 5 attempts: Request failed: 'Exchange'
No newer events found at the moment. Retry.

the weirdness happens afterwards, when I restart:

[2017-12-29 23:30:49.753261] INFO: run_algo: running algo in live-trading mode
[2017-12-29 23:30:52.598118] INFO: run_algo: base currency available in the account: [redacted] usdt
[2017-12-29 23:30:52.600201] INFO: exchange_algorithm: initialized trading algorithm in live mode
[2017-12-29 23:30:52.901352] INFO: exchange_algorithm: got totals from exchanges, cash: [redacted] positions: 0.0
[2017-12-29 23:30:57.104007] INFO: exchange_algorithm: statistics for the last 10 minutes:
starting_cash ending_cash portfolio_value pnl long_exposure short_exposure orders transactions
period_close
2017-12-29 23:30:00+00:00 [redacted] [redacted] [redacted] 0.0 0 0 0 0

the result was the same before and after a cleanup. there was actually a positive balance of XRP that the algorithm couldn't see

caioaao avatar Dec 30 '17 13:12 caioaao

Yes, this actually looks like the issue which is resolved in the develop branch. It placed the order just fine, but the retries happen after when trying to fetch the order_status afterwards to confirm the transaction. There is a specific difference with the poloniex data which I did not catch testing with Binance and Bittrex. You can work around this issue by testing with the develop branch. We’ll make sure to push a release on Tuesday. On Sat, Dec 30, 2017 at 5:04 AM Caio Oliveira [email protected] wrote:

I think it was just an API instability or backpressure (idk how many requests/sec are being made to poloniex api when a buy happens). anyway, here's the stack trace when it blew up:

[2017-12-29 23:19:00.993179] WARNING: exchange_blotter: check open orders attempt 0: Request failed: 'Exchange' [2017-12-29 23:19:07.512328] WARNING: exchange_blotter: check open orders attempt 1: Request failed: 'Exchange' [2017-12-29 23:19:12.658269] WARNING: exchange_blotter: check open orders attempt 2: Request failed: 'Exchange' [2017-12-29 23:19:19.220624] WARNING: exchange_blotter: check open orders attempt 3: Request failed: 'Exchange' [2017-12-29 23:19:24.323487] WARNING: exchange_blotter: check open orders attempt 4: Request failed: 'Exchange' [2017-12-29 23:19:30.453291] WARNING: exchange_blotter: check open orders attempt 5: Request failed: 'Exchange' Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/local/lib/python2.7/dist-packages/moneyprinter/strategies/bbands.py", line 185, in live=True) File "/usr/local/lib/python2.7/dist-packages/catalyst/utils/run_algo.py", line 563, in run_algorithm stats_output=stats_output File "/usr/local/lib/python2.7/dist-packages/catalyst/utils/run_algo.py", line 346, in _run overwrite_sim_params=False, File "/usr/local/lib/python2.7/dist-packages/catalyst/algorithm.py", line 724, in run for perf in self.get_generator(): File "/usr/local/lib/python2.7/dist-packages/catalyst/gens/tradesimulation.py", line 224, in transform for capital_change_packet in every_bar(dt): File "/usr/local/lib/python2.7/dist-packages/catalyst/gens/tradesimulation.py", line 122, in every_bar blotter.get_transactions(current_data) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 297, in get_transactions return self.get_exchange_transactions() File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions return self.get_exchange_transactions(attempt_index + 1) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions return self.get_exchange_transactions(attempt_index + 1) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions return self.get_exchange_transactions(attempt_index + 1) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions return self.get_exchange_transactions(attempt_index + 1) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 283, in get_exchange_transactions return self.get_exchange_transactions(attempt_index + 1) File "/usr/local/lib/python2.7/dist-packages/catalyst/exchange/exchange_blotter.py", line 289, in get_exchange_transactions error=e catalyst.exchange.exchange_errors.ExchangePortfolioDataError: Unable to retrieve portfolio data: order-status, giving up after 5 attempts: Request failed: 'Exchange' No newer events found at the moment. Retry.

the weirdness happens afterwards, when I restart:

[2017-12-29 23:30:49.753261] INFO: run_algo: running algo in live-trading mode [2017-12-29 23:30:52.598118] INFO: run_algo: base currency available in the account: [redacted] usdt [2017-12-29 23:30:52.600201] INFO: exchange_algorithm: initialized trading algorithm in live mode [2017-12-29 23:30:52.901352] INFO: exchange_algorithm: got totals from exchanges, cash: [redacted] positions: 0.0 [2017-12-29 23:30:57.104007] INFO: exchange_algorithm: statistics for the last 10 minutes: starting_cash ending_cash portfolio_value pnl long_exposure short_exposure orders transactions period_close 2017-12-29 23:30:00+00:00 [redacted] [redacted] [redacted] 0.0 0 0 0 0

the result was the same before and after a cleanup. there was actually a positive balance of XRP that the algorithm couldn't see

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/enigmampc/catalyst/issues/112#issuecomment-354545235, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZ-Qg1WIQetn2qQlt8Zh_gJUbQrG3Syks5tFjTOgaJpZM4RIKfV .

fredfortier avatar Dec 30 '17 13:12 fredfortier

@fredfortier great, thanks! btw, how "safe" is the develop branch? I mean, is there someone running live algos with it?

caioaao avatar Dec 30 '17 14:12 caioaao

It’s not a stable branch. We’re trying not to push breaking in changes but that’s our main development branch. On Sat, Dec 30, 2017 at 6:01 AM Caio Oliveira [email protected] wrote:

@fredfortier https://github.com/fredfortier great, thanks! btw, how "safe" is the develop branch? I mean, is there someone running live algos with it?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/enigmampc/catalyst/issues/112#issuecomment-354547728, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZ-QlgSRr0-xQabqH22zm7PGIbqjh9Wks5tFkI_gaJpZM4RIKfV .

fredfortier avatar Dec 30 '17 14:12 fredfortier

This fix is now included in release 0.4.6.

fredfortier avatar Jan 19 '18 22:01 fredfortier