Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "fetch" method returns data till the first "None" value in OHLS cande #2

Closed
DmitrySSidorov opened this issue May 17, 2022 · 6 comments

Comments

@DmitrySSidorov
Copy link

How to check it: try to fetch data by GTX stock with 15m interval and 1 month history. It returns about 30 ohls values.

I propose to skip None values in returning data like this (api.py):

if close != None:

                candles.append(
                    {
                        "datetime": time,
                        "open": float(open),
                        "high": float(high),
                        "low": float(low),
                        "close": float(close),
                        "volume": float(volume),
                    }
                )

else:

continue

@ttamg
Copy link
Owner

ttamg commented May 19, 2022

OK interesting thanks.

Seems we could do with a fix to the parse module to pass things through and either return the parsed value or the raw value if the parse fails.

Your suggestion is good but i think we can be even a bit smarter and pick up any exceptions.

@DmitrySSidorov
Copy link
Author

Looks good and it depends by your decision.

I just want to add some info: I use your module to calculate technical indicators (ema, macd, rsi etc). And for them don't need any None (on Null) values. They need only known values.

@DmitrySSidorov
Copy link
Author

And I'd like to show, how looks GTX stock in tradingview (picture below): look at the vertical white lines. It's the trading day borders. Some days are "narrow". It means that tradingview skips empty values in the graph.

image

@ttamg
Copy link
Owner

ttamg commented May 19, 2022

OK here's the solution I am suggesting. Like you say, we can skip candles that have values that cannot be parsed (None values). But doing that silently is probably unhelpful for some people as it can just drop candles without people realising it. So I've added in a warning that is raised when that happens. It doesn't stop the flow but does raise the issue.

And of course if someone wants that original info they can still go back and use the OHCL.raw_fetch() method instead which does not put it through the parser.

Here's the code. I am making the changes now and adding some tests.

           for time, open, high, low, close, volume in zip(
                timestamps,
                indicators["open"],
                indicators["high"],
                indicators["low"],
                indicators["close"],
                indicators["volume"],
            ):
                try:
                    candles.append(
                        {
                            "datetime": time,
                            "open": float(open),
                            "high": float(high),
                            "low": float(low),
                            "close": float(close),
                            "volume": float(volume),
                        }
                    )
                except TypeError as e:
                    warnings.warn(
                        f"Unable to parse some of the candle values at time period {time} - Skipping this candle and continuing."
                    )

            return candles, meta

@ttamg
Copy link
Owner

ttamg commented May 19, 2022

OK I have released version 0.1.3 now on PyPI with the fix. Also updates now pushed up.

Thanks for your help. Closing this issue now

@ttamg ttamg closed this as completed May 19, 2022
@ttamg
Copy link
Owner

ttamg commented May 19, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants