Forum Discussion
Api in every row of excel.
Hi
Currently I have an excel file with the following columns.
MFund Code I Bought at I Mutual fund name I latest Price
112092 I 100.00 I Fidelity world fund I 112.00 I 100.00
56432 I 25.00 I Stanley index fund I 20.00 I 25.00
There is a website which provides access to latest price through API.
There arre many Mfundcodes so I use a text file to be read in a python program and extract the data.
Following is the main part of the program.
for x in f:
# Add number variable to the api call
x = x[:6]
api = f"https://api.mfapi.in/mf/{x}/latest"
# Get text data from api call
idata = requests.get(api).text;
# Convert json data into dictionary format
d = json.loads(idata)
# Get the first record of data
if not d['data']:
exit
else:
l = d['data'][0]
k.write(f"{x} {l['nav']} {l['date']} \n")
Later I import this text file into the excel for further calculations.
I was wondering if there is a way to have these values load into the excel columns
regards
Jyothsna
you can use Excel built in tools to pull the data. you can create an external link using Data->get data from webpage and pull a table of data but not sure how well that would work here.
alternatively, you can also use inline formula like this:
=--TEXTBEFORE(TEXTAFTER(WEBSERVICE("https://api.mfapi.in/mf/"&$A2&"/latest"),"nav"":"""),"""}],")where A2 is where the Mfund Code is located
NOTE: I do NOT see that Stanley Index fund anywhere in that api
2 Replies
- JO1902Copper Contributor
Thank you very much for this solution. It works like magic.
- m_tarlerSilver Contributor
you can use Excel built in tools to pull the data. you can create an external link using Data->get data from webpage and pull a table of data but not sure how well that would work here.
alternatively, you can also use inline formula like this:
=--TEXTBEFORE(TEXTAFTER(WEBSERVICE("https://api.mfapi.in/mf/"&$A2&"/latest"),"nav"":"""),"""}],")where A2 is where the Mfund Code is located
NOTE: I do NOT see that Stanley Index fund anywhere in that api