pyoanda icon indicating copy to clipboard operation
pyoanda copied to clipboard

Documentation for 'get_prices()'

Open bolshoibooze opened this issue 9 years ago • 3 comments

I spent a couple of hours trying to figure out stuff, so here's my simple usage example that you can add to the 'README' and 'readthedocs' :+1:

     # get prices for a list of instruments
     pair_list = ['AUD_JPY','EUR_JPY','GBP_JPY','AUD_USD']
     c.get_prices(instruments=','.join(pair_list),stream=False)

     #json response::
     {u'prices': [{u'ask': 81.551,
         u'bid': 81.53,
         u'instrument': u'AUD_JPY',
         u'time': u'2016-01-26T07:39:56.525788Z'},
        {u'ask': 127.975,
         u'bid': 127.957,
         u'instrument': u'EUR_JPY',
         u'time': u'2016-01-26T07:39:55.712253Z'},
        {u'ask': 167.269,
         u'bid': 167.239,
         u'instrument': u'GBP_JPY',
         u'time': u'2016-01-26T07:39:58.333404Z'},
        {u'ask': 0.69277,
        u'bid': 0.6926,
        u'instrument': u'AUD_USD',
        u'time': u'2016-01-26T07:39:50.358020Z'}]}


     # simplistic way of extracting data from the json response::
     dataset = c.get_prices(instruments=','.join(pair_list),stream=False)

     aud_jpy = [d for d in dataset['prices'] if d['instrument']=='AUD_JPY']
     bid = [d['bid'] for d in aud_jpy][-1]
     ask = [d['ask'] for d in aud_jpy][-1]
     time = [d['time'] for d in aud_jpy][-1]

cheers!

bolshoibooze avatar Jan 26 '16 08:01 bolshoibooze

Thanks mate, Do you mind to create a pull request? So your name will be there :)

Please add this as an example in the examples folder.

toloco avatar Jan 26 '16 09:01 toloco

Alright, will do so

bolshoibooze avatar Jan 26 '16 10:01 bolshoibooze

And any other sample is welcome too!!

Thanks a lot

toloco avatar Jan 26 '16 10:01 toloco