Git Product home page Git Product logo

Comments (15)

hootnot avatar hootnot commented on June 11, 2024

Hi,

It is likely that you used the wrong format, maybe only forgot the 'Z' in the date spec. It must be RFC3339 (or unix time), so short version:

import json
import oandapyV20
import oandapyV20.endpoints.instruments as instruments
client = oandapyV20.API(access_token=...)

params = {
  "count": 5,
  "granularity": "H4",
  "from": "2017-06-23T12:00:00Z",
}
r = instruments.InstrumentsCandles(instrument="DE30_EUR", params=params)
client.request(r)
print(json.dumps(r.response, indent=2))

{
  "instrument": "DE30_EUR", 
  "candles": [
    {
      "volume": 20214, 
      "mid": {
        "h": "12768.4", 
        "c": "12715.0", 
        "l": "12679.0", 
        "o": "12756.8"
      }, 
      "complete": true, 
      "time": "2017-06-23T09:00:00.000000000Z"
    }, 
    {
      "volume": 20012, 
      "mid": {
        "h": "12753.3", 
        "c": "12726.5", 
        "l": "12674.9", 
        "o": "12714.8"
      }, 
      "complete": true, 
      "time": "2017-06-23T13:00:00.000000000Z"
    }, 
    {
      "volume": 2982, 
      "mid": {
        "h": "12732.0", 
        "c": "12731.8", 
        "l": "12708.8", 
        "o": "12726.3"
      }, 
      "complete": true, 
      "time": "2017-06-23T17:00:00.000000000Z"
    }
  ], 
  "granularity": "H4"
}

Most endpoints are covered with examples in the https://github.com/hootnot/oandapyV20-examples repo. ( I've just added a check on the dates to raise an error in case the date does not qualify)

Check the candle-data.py example. If you run:

python src/candle-data.py --price MBA --start "2016-01-01T00:00:00Z" --gran M5 --instruments EUR_USD --nice >/tmp/EUR_USD.hist.M5

you will get 500 records, with Mid/Bid/Ask. You can control that number by using --count N and set it up to 5000

 "instrument": "EUR_USD", 
 "candles": [
  {
   "complete": true, 
   "bid": {
    "h": "1.08699", 
    "c": "1.08676", 
    "l": "1.08674", 
    "o": "1.08699"
   }, 
   "mid": {
    "h": "1.08746", 
    "c": "1.08726", 
    "l": "1.08724", 
    "o": "1.08743"
   }, 
   "volume": 6, 
   "time": "2016-01-03T22:00:00.000000000Z", 
   "ask": {
    "h": "1.08796", 
    "c": "1.08776", 
    "l": "1.08774", 
    "o": "1.08787"
   }
  }, 
  ...
]

Check the curl examples also that are in the docs at http://developer.oanda.com/rest-live-v20/instrument-ep/

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

@torisoft : did not hear from you anymore, guess your problem is solved using the right date spec

from oanda-api-v20.

dexhunter avatar dexhunter commented on June 11, 2024

Hi! I tried to access data from 2016-01-01 to 2016-02-01 with granularity="M5" but failed. Is there a restriction on the datetime oanda api can date back to? Thanks.

Edit:
I tried different granularities and works. Maybe is the M5 data missing. The error is 500, "Internal Server Error"

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

If you get a 500 error it is always the server side, with the server down or other serious trouble.
Check the health-page at developer.oanda.com for issues on their side (and they have lately).
I've downloaded data myself this week and had not errors,
Do those other granularities work the same time you try M5 ? Which instrument ?

from oanda-api-v20.

dexhunter avatar dexhunter commented on June 11, 2024

Do those other granularities work the same time you try M5 ? Which instrument ?

The instrument is EUR_USD. The minimum granularity I tested working is M30. I have sent an email regarding the issue to [email protected], hope they will fix this soon.

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

curl works fine:

curl
-H "Content-Type: application/json"
-H "Authorization: Bearer ${TOK}"
"https://api-fxpractice.oanda.com/v3/instruments/EUR_USD/candles?from=2016-01-01T00:00:00Z&to=2016-02-01T00:00:00Z&price=M&granularity=M5"

Do you use oandapyV20 ? then please show me the code

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

@dexhunter

The piece of code I mentioned as first answer in this discussion works fine too with date(s) formatted as in the example.

It was this discussion that I rewrote the src/candle-data.py example to accept from/to instead of start/end. I also added a check for the date to that. That datecheck fails a return value in case the date is OK.
So I patched that example from the oandapyV20-examples repo

If you do:

python src/candle-data.py --instruments EUR_USD --gran M5 --price MBA --from 2016-01-01T00:00:00Z --to 2016-02-01T00:00:00Z

you have your history over the requested period.

If you need more than 5000 records: use InstrumentsCandlesFactory from oandapyV20.contrib.factories

(But the 500 error was an OANDA thing)

from oanda-api-v20.

dexhunter avatar dexhunter commented on June 11, 2024

Thank you for reply! I found the problem was on server side. I added a database system to my trading framework and now it should be okay.

from oanda-api-v20.

JTInfinite avatar JTInfinite commented on June 11, 2024

Hi hootnot,

thanks for the brilliant wrapper. I have been enjoying my time playing around with it. I have an issue with the candles factory though and that is it never returns candles up until 'now' - more often than not it gives data up until a week ago or more. For instance, if I pass the followng params:

now = datetime.datetime.utcnow().isoformat('T')+'Z'
now = str(now[:-8] + 'Z')

params = {
            "from": "2017-04-01T00:00:00Z",
            "to": now,
            "price": "M",
            "granularity": "M30"
            }

This is the last chunk of data I receive (put into a dataframe) is:

2017-09-14 23:00:00+00:00 699 1.33982 1.34037 1.33975 1.34012

[5686 rows x 5 columns]

Why has it stopped on the 14th? Why not up until 22/09/2017?

Thanks for any clarity

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

@4eye thanks for the compliment, I will have a look...
Ok, it needs a fix, will open a new issue

from oanda-api-v20.

JTInfinite avatar JTInfinite commented on June 11, 2024

Thanks hootnot!

Let me know if I can do anything. Of course, more than happy to run tests etc.

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

Hi, just triggered the release 0.4.4. I tested it on your request, it fills fully now.
It will take some time before the new version pops up in pypi. So, if you are in a hurry upgrade from github. Otherwise give it some time and then upgrade using pip:

pip install oandapyV20 --upgrade

from oanda-api-v20.

JTInfinite avatar JTInfinite commented on June 11, 2024

perfect, thanks!

from oanda-api-v20.

hootnot avatar hootnot commented on June 11, 2024

You're welcome. Enjoy the use of the library and the InstrumentsCandlesFactory. When retrieving bulk history it is very conveniant

from oanda-api-v20.

JTInfinite avatar JTInfinite commented on June 11, 2024

tested and working perfectly. You're a legend!

from oanda-api-v20.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.