I'm trying to access oanda's fx lab data points by connecting with API. They have bunch of cool information that i'd like to get access to and then use them within my strategies. Because ninjascript is just C, I can't imagine it being complicated.. just don't know where to start
Thanks for asking the dev team. Would be nice to have some example if they can provide on how to pull data from an API from external sources within ninjascript.
fx lab variables:
developer:
http://developer.oanda.com/rest-live...ign=forex-labs
http://developer.oanda.com/rest-live-v20/instrument-ep/
^--- this is their most updated API documentation (v20).
Below is a sample python script that i've used previously to connect with their API.
import subprocess, os, csv
import json, http.client, math, calendar, datetime, requests
from time import *
import pandas as pd
import sys
import openpyxl
from openpyxl.reader.excel import load_workbook
import oandapyV20
import oandapyV20.endpoints.forexlabs as labs
Symbol='EUR_USD'
accountID = "********************"
client = oandapyV20.API(access_token="********************* *")
params ={"instrument": Symbol,"period": 3600}
r = labs.HistoricalPositionRatios(params=params)
output = client.request(r)
position_data = output['data'][Symbol]['data']
for p in range(len(position_data)):
position_data[p][0] = datetime.datetime.fromtimestamp(position_data[p][0])
headers = ["timestamp", "lpr", "rate"]
df = pd.DataFrame(position_data, columns=headers)
df = df.set_index(df['timestamp'])
df = df.drop(['timestamp', 'rate'], axis=1)
df = df[:-1]
latest_value= df.tail(1)
Leave a comment: