oanda / oandapy

Python wrapper for the OANDA REST API
MIT License
325 stars 148 forks source link

Cheatsheet for migrating from oandapy to oandapyv2 #41

Open houmie opened 8 years ago

houmie commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 4 years ago

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 commented 4 years ago

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 api@oanda.com