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

Cheatsheet for migrating from oandapy to oandapyv2 #41

Open
houmie opened this issue Nov 30, 2016 · 5 comments
Open

Cheatsheet for migrating from oandapy to oandapyv2 #41

houmie opened this issue Nov 30, 2016 · 5 comments

Comments

@houmie
Copy link

houmie commented Nov 30, 2016

Hi,

I think there is a need for a cheat sheet to migrate the old to the new version.

oanda = oandapy.API(environment="practice", access_token=OANDA_ACCESS_TOKEN)
response = oanda.get_prices(instruments="EUR_USD")
api = oandapyV20.API(environment="practice", access_token=OANDA_ACCESS_TOKEN)

e.g. how do I do get_prices now in V2?

Many Thanks,
Houman

@hootnot
Copy link
Contributor

hootnot commented Nov 30, 2016

@houmie

Hi, please check the examples repo: https://github.com/hootnot/oandapyV20-examples

it has a candle-data application and different streaming examples

Also check the docs: http://oanda-api-v20.readthedocs.io/en/latest/oandapyV20.endpoints.html#module-oandapyV20.endpoints.instruments

@houmie
Copy link
Author

houmie commented Nov 30, 2016

Thanks for the pointers, apologies if I ask strange questions, as I'm new to the wrapper and trading in general.

I have followed your advice and have tried this:

api = oandapyV20.API(environment="practice", access_token=OANDA_ACCESS_TOKEN)
r = instruments.InstrumentsCandles(instrument="EUR_USD")
response = api.request(r)
prices = response.get("candles")

Problem is that I don't see the bid price on that list. Am I completely off with my approach or just don't see the wood for the trees?

@hootnot
Copy link
Contributor

hootnot commented Dec 1, 2016

You only see the mid prices with the granularity of S5 because these are the defaults. If you want something different you will need to specify it.

I've extended the candle-data example with the price parameter .

The params parameter simply accepts all the parameters as they are in the specs of OANDA's REST V20 docs, see developer.oanda.com/rest-live-v20

So if you pass:

params={'count': 2, 'price': 'B', 'granularity': 'M5'}

you will get the 'bid', pass 'BA' you get 'bid/ask', run the example:

python src/candle-data.py --count 1 --price MBA --i EUR_USD --gr M5 --nice
{
 "candles": [
  {
   "complete": false, 
   "bid": {
    "h": "1.06224", 
    "c": "1.06224", 
    "l": "1.06216", 
    "o": "1.06216"
   }, 
   "mid": {
    "h": "1.06230", 
    "c": "1.06230", 
    "l": "1.06223", 
    "o": "1.06223"
   }, 
   "volume": 6, 
   "time": "2016-12-01T06:35:00.000000000Z", 
   "ask": {
    "h": "1.06236", 
    "c": "1.06236", 
    "l": "1.06230", 
    "o": "1.06230"
   }
  }
 ], 
 "instrument": "EUR_USD", 
 "granularity": "M5"
}

@th1nk1ng0utl0ud
Copy link

th1nk1ng0utl0ud commented Jul 9, 2020

Hi, how do you specify in the instruments.InstrumentsCandles() params the dailyalignment or the weeklyalignment? for the daily OHLC data?, or can I modify the UTC timezone for the daily data in some way?, im getting different data from the Oanda page and from the oandapyV20 when I retrieve the daily data.

@hootnot
Copy link
Contributor

hootnot commented Jul 10, 2020

Hi, you are posting in the oanda repo, but reading your post you seem to use oandapyV20.

Regarding oandapV20: every parameter you find in the docs under request parameters can be passed via the params dict. So, that also goes for the alignment parameters. https://developer.oanda.com/rest-live-v20/instrument-ep/

If you have questions regarding data differences, pls drop those at OANDA, maybe [email protected]

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

3 participants