catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Wrong OHLCV data in paper/live mode at Bittrex

Open camanio opened this issue 8 years ago • 8 comments

Dear Catalyst Maintainers,

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

Environment

  • Operating System: Ubuntu 16.04
  • Python Version: Python 2.7.12
  • Python Bitness: 64
  • How did you install Catalyst:pip
  • Python packages: alembic==0.9.7 asn1crypto==0.24.0 attrs==17.4.0 Automat==0.6.0 backports-abc==0.5 backports.functools-lru-cache==1.4 backports.shutil-get-terminal-size==1.0.0 backports.weakref==1.0.post1 backtrader==1.9.59.122 bcolz==0.12.1 bdateutil==0.1 beautifulsoup4==4.6.0 bleach==1.5.0 boto3==1.5.19 botocore==1.8.33 Bottleneck==1.2.1 bt==0.2.5 ccxt==1.10.834 certifi==2018.1.18 cffi==1.11.2 chardet==3.0.4 click==6.7 cloudpickle==0.5.2 configparser==3.5.0 constantly==15.1.0 contextlib2==0.5.5 cryptography==2.1.4 cssselect==1.0.3 cvxopt==1.1.9 cycler==0.10.0 cyordereddict==1.0.0 Cython==0.27.3 decorator==4.2.1 docutils==0.14 empyrical==0.2.1 enigma-catalyst==0.4.7 enum34==1.1.6 ffn==0.3.3 funcsigs==1.0.2 future==0.16.0 futures==3.2.0 graphviz==0.8.2 h5py==2.7.1 holidays==0.8.1 html5lib==0.9999999 Humongolus==1.0.7 hyperlink==17.3.1 idna==2.6 incremental==17.5.0 intervaltree==2.1.0 ipaddress==1.0.19 ipykernel==4.7.0 ipython==5.5.0 ipython-genutils==0.2.0 jmespath==0.9.3 jupyter-client==5.2.1 jupyter-core==4.4.0 llvmlite==0.21.0 Logbook==1.1.0 lru-dict==1.1.6 lxml==4.1.1 Mako==1.0.7 Markdown==2.6.11 MarkupSafe==1.0 matplotlib==2.1.1 mock==2.0.0 mongoengine==0.15.0 multipledispatch==0.4.9 mxnet==0.9.4 networkx==2.0 nltk==3.2.5 numba==0.36.2 numexpr==2.6.4 numpy==1.14.0 oauthlib==2.0.6 observations==0.1.4 pandas==0.19.2 pandas-datareader==0.5.0 parsel==1.3.1 pathlib2==2.3.0 patsy==0.5.0 pbr==3.1.1 pexpect==4.3.1 pgportfolio==1.0.0 pickleshare==0.7.4 Pillow==5.0.0 praw==5.3.0 prawcore==0.13.0 prettytable==0.7.2 prompt-toolkit==1.0.15 protobuf==3.5.1 ptyprocess==0.5.2 pyasn1==0.4.2 pyasn1-modules==0.2.1 pycparser==2.18 PyDispatcher==2.0.5 Pygments==2.2.0 pymodm==0.4.0 pymongo==3.6.0 Pympler==0.5 pyOpenSSL==17.5.0 pyparsing==2.2.0 PyPrind==2.11.1 pyro-ppl==0.1.2 python-dateutil==2.6.1 python-editor==1.0.3 pytz==2017.3 PyYAML==3.12 pyzmq==16.0.3 queuelib==1.4.2 redo==1.6 requests==2.18.4 requests-file==1.4.3 requests-ftp==0.3.1 requests-oauthlib==0.8.0 rpy2==2.8.4 s3transfer==0.1.12 scandir==1.6 scikit-garden==0.1.3 scikit-learn==0.19.1 scipy==1.0.0 Scrapy==1.5.0 seaborn==0.8.1 service-identity==17.0.0 simplegeneric==0.8.1 singledispatch==3.4.0.3 six==1.11.0 sklearn==0.0 sortedcontainers==1.5.9 SQLAlchemy==1.2.1 statsmodels==0.8.0 subprocess32==3.2.7 TA-Lib==0.4.16 tables==3.4.2 tabulate==0.8.2 tensorflow-gpu==1.4.1 tensorflow-tensorboard==0.4.0rc3 textblob==0.15.0 tflearn==0.3.2 toolz==0.9.0 torch==0.3.0.post4 torchvision==0.2.0 tornado==4.5.3 traitlets==4.3.2 Twisted==17.9.0 twython==3.6.0 update-checker==0.16 urllib3==1.22 vaderSentiment==2.5 w3lib==1.18.0 wcwidth==0.1.7 Werkzeug==0.14.1 xgboost==0.7.post3 zope.interface==4.4.3

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

Description of Issue

  • What did you expect to happen? When I request any recent data by calling something like data.history(asset, fields=['high', 'low', 'close'], bar_count=N, frequency=freq) I expect to recieve N last candles (latest candle must be incomplete, as far as I understood).

  • What happened instead? If I look at result of the request in debugger, I see, what last M rows in dataframe filled by the same numbers.

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

Reproduction Steps

Run any algo in paper mode at Bittrex and print history data.

What steps have you taken to resolve this already?

I think, the problem may be in CCXT - base/exchange.py, class Exchange, method parse_ohlcvs. The main parameter of this method recieves candles from excahnge in wrong order. If you reverse input and output of the method, all is fine. Here is the patch:

    def parse_ohlcvs(self, ohlcvs, market=None, timeframe='1m', since=None, limit=None):
        ohlcvs = self.to_array(ohlcvs[::-1])
        num_ohlcvs = len(ohlcvs)
        result = []
        i = 0
        while i < num_ohlcvs:
            if limit and (len(result) >= limit):
                break
            ohlcv = self.parse_ohlcv(ohlcvs[i], market, timeframe, since, limit)
            i = i + 1
            if since and (ohlcv[0] < since):
                continue
            result.append(ohlcv)
        return result[::-1]

Sincerely, camanio

camanio avatar Feb 01 '18 06:02 camanio

Thanks for this! Did you also open an issue with CCXT? If so, what's the number. If not, we'll take a closer look and report as appropriate. @AvishaiW feel free to investigate if feel like you have a sense of the issue.

fredfortier avatar Feb 01 '18 07:02 fredfortier

@fredfortier , thanks for reply. No, I did not open the same issue at CCXT repo.

camanio avatar Feb 01 '18 07:02 camanio

@AvishaiW this bug still exists in latest version of catalyst and CCXT. Moreover, if you try to get historical data for multiple coins, sometimes random columns filled by the same numbers, while the others is OK. Now I request data in live/paper mode in try-except block (because bad responses & timeouts are typical situations) and check each column in resulting dataframe for duplicates. Can you incorparate the similar logic in catalyst?

camanio avatar Feb 08 '18 09:02 camanio

Hi @camanio, we just fixed several issues and released a new version of catalyst. please check if it fixed these issues. Thanks

AvishaiW avatar Feb 08 '18 22:02 AvishaiW

Hi @AvishaiW , I tested a new version in paper mode at Bittrex. These issues fixed, as far as I can see. Thanks!

camanio avatar Feb 10 '18 10:02 camanio

Hello,

It seems that I am having this same issue, it is solved for you @camanio? I am using catalyst installed via pip enigma-catalyst==0.5.1+71.g46e1a87.dirty. I am also using bittrex with the btc_usdt pair.

[2018-03-05 21:21:59.557361] INFO: d_papert_abba_brittany: 
Datetime:
2018-03-05 20:12:00+00:00 UTC
Counter: 420
Resampled Index: 7
Last RC: 2018-03-05 20:00:00+00:00
Previous RC: 2018-03-05 19:00:00+00:00

Candle:
O: 13620.0
H: 13620.0
L: 13327.7636528
C: 13470.4930546
V: 118.01857335
Base price: 13470.4930546
...

As you can see the OHLC values are around 13300 which is not the correct value. Any idea?

I just upgraded to a fresh python3 venv with version 0.5.3. I am going to test the results overnight and compare the results.

Thank you very much.

vonpupp avatar Mar 05 '18 21:03 vonpupp

You appear to be using an old version. We are currently at 0.5.3. Try reinstalling to ensure that you are at the current version. On Mon, Mar 5, 2018 at 1:31 PM Vonpupp [email protected] wrote:

Hello,

It seems that I am having this same issue, it is solved for you @camanio https://github.com/camanio? I am using catalyst installed via pip enigma-catalyst==0.5.1+71.g46e1a87.dirty. I am also using bittrex with the btc_usdt pair.

[2018-03-05 21:21:59.557361] INFO: d_papert_abba_brittany: Datetime: 2018-03-05 20:12:00+00:00 UTC Counter: 420 Resampled Index: 7 Last RC: 2018-03-05 20:00:00+00:00 Previous RC: 2018-03-05 19:00:00+00:00

Candle: O: 13620.0 H: 13620.0 L: 13327.7636528 C: 13470.4930546 V: 118.01857335 Base price: 13470.4930546 ...

As you can see the OHLC values are around 13300 which is not the correct value. Any idea?

Thank you very much.

— You are receiving this because you were mentioned.

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

fredfortier avatar Mar 06 '18 04:03 fredfortier

Hi, @vonpupp! I checked @AvishaiW 's solution in PyCharm and all is fine (yes, for v0.5.3).

camanio avatar Mar 06 '18 04:03 camanio