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

InstrumentsCandlesFactory not working for monthly granularity #148

Open
mpatkinson7 opened this issue Jul 21, 2019 · 4 comments
Open

InstrumentsCandlesFactory not working for monthly granularity #148

mpatkinson7 opened this issue Jul 21, 2019 · 4 comments
Assignees

Comments

@mpatkinson7
Copy link

mpatkinson7 commented Jul 21, 2019

Hi

The InstrumentsCandlesFactory is not working for "monthly" granularity. Works fine for weekly and daily granularities.

Using parameters below.

params = {
    "price": "M",
    "granularity": "M",
    "from": "2005-01-01T00:00:00Z",
    "to": "2017-07-01T00:00:00Z",
    "dailyAlignment": 17,
    "alignmentTimezone": "America/New_York",
    "weeklyAlignment": "Friday"
}

Say instrument is "AU200_AUD"

Basically, calling line below:
client.request(factories.InstrumentsCandlesFactory(instrument=instrument, params=params))

Running line in Interactive Window in VSCode (using WinPython) yields error below.

AttributeError Traceback (most recent call last)
in

----> 1 client.request(factories.InstrumentsCandlesFactory(instrument=instrument, params=params))

C:\WPy64-3720\python-3.7.2.amd64\lib\site-packages\oandapyV20\oandapyV20.py in request(self, endpoint)
    274             V20Error in case of HTTP response code >= 400
    275         """
--> 276         method = endpoint.method
    277         method = method.lower()
    278         params = None

AttributeError: 'generator' object has no attribute 'method'
---------------------------------------------------------------------------

I've just run the script for daily & weekly data - so pretty sure OANDA is working fine.

@hootnot
Copy link
Owner

hootnot commented Jul 21, 2019

Hi,

First of all: you are using it the wrong way.

InstrumentsCandlesFactory is a generator that yields InstrumentsCandles request objects to cover the full range of data specified by from/to.
The way to use the factory is:

   for r in InstrumentsCandlesFactory(...):
      rv = client.request(r)
      # and process the data ...

there is an example in the README.rst of the repo ! Check the docs also: https://oanda-api-v20.readthedocs.io/en/latest/contrib/factories/instrumentscandlesfactory.html

I get the impression OANDA added W(eekly) later on and then after that M(onthly). It was april 2018 that I added 'W' to support the weekly data. The function parsing granularity parameter doesn' t support 'M'(onthly) yet.

Easy work-around:

Instead of using InstrumentsCandlesFactory simply use the InstrumentsCandles class to fetch the monthly data. The data of OANDA goes back to 2005. The default count is 500, large enough to get you all monthly history since 2005.

@mpatkinson7
Copy link
Author

Thanks for the response Feit.

Sorry, I should have been clearer. I was using the InstrumentsCandlesFactory as you described in my code, and as described in the documentation. I just didn't use it correctly in that 'line below' I was referring to in the bug! I was hacking around with stuff interactively.

Yeah, you must have read my mind. I have already coded the work around you suggested (i.e. if / else checking granularity) before your reply! That was a great suggestion you made!!! 😊

Finally, just for completeness, do you think the "M" / monthly granularity will be made available at some point in the future in InstrumentsCandlesFactory?

Thanks.

@hootnot hootnot self-assigned this Jul 21, 2019
@hootnot
Copy link
Owner

hootnot commented Jul 21, 2019

For completeness it should be there. To be honest: I don't think there is much value in monthly data.

@flowtrader2016
Copy link

Are there any plans to add this enhancement please?

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

No branches or pull requests

3 participants