Integrate FOREX
jonathan-gatard opened this issue · 5 comments
Hi,
I think it can be nice if we could integrate the forex, i have JPY, CAD, USD, GBP, and it doesn't works on a grafana. We see only JPY because graphs are bigger than others.
Objective is to get EUR/USD, EUR/JPY, etc... and multiply the value
https://fr.finance.yahoo.com/quote/EURJPY=X?ltr=1
I already did it with excel (powerquerry) but i prefer with python and influxdb ! But i'm really noob in python...
And why not add a category FOREX to the portfolio to follow the evolution ;)
I'll try tomorrow ;)
Hi Kalypox, I already did it by putting in the quote tag. In your case it is EURJPY=X in the "sigle" and whatever name you want in "nom". Just use the part in the brackets from yahoo finance including the =X section. Like EUR/USD (EURUSD=X), you use EURUSD=X.
Only problem I'm dealing with is the quantitie has to be an integer. But this is not realistic when doing FX. Any ideas ?
Hi,
I'm working on it to transform all values in euro (or other) in your program. I'm learning python/influxdb/yfinance
I added 2 functions :
def getLastValue(ticker):
ticker = yf.Ticker(ticker)
history = ticker.history(interval="30m")
return history.tail(1)['Close'].iloc[0]
def toEur(cours,symbole):
if symbole != "EUR":
return cours / getLastValue("EUR" + symbole + "=X")
else:
return cours
def run():
try:
with open('data.json') as json_file:
json_loaded = json.load(json_file)
for info in json_loaded:
value = getLastValue(info['ticker'])
json_body = [{
"measurement": "bourse",
"tags": {
"nom": info['nom']
},
"fields": {
"value_origine": value,
"value": toEur(value,info['symbole']),
"qte": info['qte'],
"pru": info['pru']
}
}]
influxdbClient = InfluxDBClient(
host="192.168.1.2",
port="8086",
database="portfolio",
username="uuuu",
password="XXXXXXXXXX")
influxdbClient.write_points(json_body)
influxdbClient.close()
except Exception as e:
print(e)
And symbol in data.json
I made a lot of modifications on
Nice. Will try it out later.
To answer my previous question on the integer and real values, I find out that this it automatically assigned by InfluxDB when you first create the measurement. So if you put 0 or 1, it will assume it is an integer value and assign all values must be integers. To make it automatically assume a real number, then just put 0.0 or 1.0 and then you will have a real value assignment and you won't get errors when you put in 2.3 or other non whole number.