May-28-2017, 03:36 PM
Hi,
Could someone kindly advise on how to add a parameter to an API request, this maybe using curl, but I am unsure of how to do this.
I am using Windows 10 and Python 3.6.
The first question is, how to add an option provided by the website to request the time to be in Unix format (i.e. 1495973084.8393297) rather than the current format of (2016-12-31T22:00:00.000000Z) as I need the format to be consistant,
The website provides this parameter X-Accept-Datetime-Format: UNIX but I am unsure how to include it in the url string successfully.
The second question is, if the solution involves converting the time format rather than requesting the unix format, then I would still like to understand how it can be done via an API as I have other requirements to add parameters to the API.
Thank you in advance. A copy of the code is shown below.
Bass
Could someone kindly advise on how to add a parameter to an API request, this maybe using curl, but I am unsure of how to do this.
I am using Windows 10 and Python 3.6.
The first question is, how to add an option provided by the website to request the time to be in Unix format (i.e. 1495973084.8393297) rather than the current format of (2016-12-31T22:00:00.000000Z) as I need the format to be consistant,
The website provides this parameter X-Accept-Datetime-Format: UNIX but I am unsure how to include it in the url string successfully.
The second question is, if the solution involves converting the time format rather than requesting the unix format, then I would still like to understand how it can be done via an API as I have other requirements to add parameters to the API.
Thank you in advance. A copy of the code is shown below.
Bass
###################### # Libraries, Passed Variables etc. # ###################### import requests as requests import json as json url_pair = "GBP_JPY" ################# # Initilise url for API Call # ################# # Standard API Set up url_granularity = "" url = "" url_1 = 'https://api-fxtrade.oanda.com/v1/candles?instrument=' url_2 = '&granularity=' url_3 = '&count=' url_4 = '&candleFormat=bidask' # THIS IS what I have tried # url_4 = url_4 + '? X-Accept-Datetime-Format: UNIX' # Customizing Options for API url_granularity = "M" url_count = "5" url = url_1 + url_pair + url_2 + url_granularity + url_3 + url_count + url_4 url_response = requests.get(url) M_pdata = json.loads(url_response.text) print("url = ", url) print("M_pdata = ", M_pdata)