What is API?
Straight from Wikipedia (Sue me for content infringement)
An application programming interface (API) is a computing interface that defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc. It can also provide extension mechanisms so that users can extend existing functionality in various ways and to varying degrees. An API can be entirely custom, specific to a component, or designed based on an industry-standard to ensure interoperability. Through information hiding, APIs enable modular programming, allowing users to use the interface independently of the implementation.
Uhh What?
Application Programming Interface is a form of implementation of a software that allows other software developers to use the software module without worrying about to develop from base.
World Class Forex API's
Forex API’s allows software developers to get foreign exchange rates from best data compilers or forex aggregators in the world. Usually central banks of the countries have dedicated department (Foreign Exchange Management Unit in case of Nepal Rastra Bank) who prepare foreign exchange rates. Now there is another question on how forex rates are determined. That’s a issue for whole another blog here Forex Rates and Currency Manipulation: Explained.
For now let’s focus on the implementation of forex API’s. Some of the world class Forex API’s are
- Yahoo Finance API
- Tradingview API
- Oanda API
- Stocktwits API
- Currency Exchange API
- IP2Currency API
- ForexAlert API
- Sentlytics API
- Fixer API
- Currencystack API
Foreign Exchange, is a fully decentralized global market where currencies are bought and sold. To facilitate trading, many brokerage companies provide an online infrastructure that makes it easy for traders to access the global FX market. In recent years companies have also provided APIs (Application Programmable interface) to help third-party application integrate with there platform.
API from Nepal Rastra Bank
Nepal Rastra Bank is probably the most accurate forex aggregator in Nepal. This is because Nepal Rastra Bank as a regulatory has very strict guidelines for reporting and compiling of foreign exchange transactions. However, forex rates are not just determined by the national transactions. These are more affected by global transactions and the dealers / brokers and business participants all around the world.
Nepal Rastra Bank only recently introduced Forex API Documentation. There are few options to exctract exchange rates from NRB
Using Internet Browser
Well this is a no brainer. You can go to Foreign Exchange Rate – नेपाल राष्ट्र बैंक (nrb.org.np) and choose your date for exchange transaction and get the exchange rates for the foreign convetible currencies in Nepal.
Dumping data in JSON or CSV
Currently NRB allows data to be exported in JSON or CSV for a date range to be downloaded by the users. Here an user will select a date range and get the data exported in JSON or CSV and manipulate the data though the help of spreadsheet softwares or converters or simply some plain old javascripts.
Using NRB FOREX API Documentation
API Base Url
https://www.nrb.org.np/api/forex/v1/
Endpoints
GET /rates:
Returns Foreign Exchange Rates for a given range
Parameters
page:
Current Pageper_page:
Number of items to show per pagefrom:
Starting date (In Y-m-d format)to:
Endingdate (In Y-m-d format)
Example Response
{"status":{"code":400},"errors":{"validation":{"per_page":["Per Page is required","Per Page must be an integer","Per Page must be at least 1","Per Page must be no more than 100"],"page":["Page is required","Page must be an integer"],"from":["From is required","From must be date with format 'Y-m-d'","From must be date with format 'Y-m-d'"],"to":["To is required"]}},"params":{"from":"","to":"","per_page":"","page":""},"data":{"payload":null},"pagination":{"page":null,"pages":null,"per_page":null,"total":null,"links":{"prev":null,"next":null}}}
Implementing NRB's API in Visual Basic For Applications
Why in VBA?
Maybe we want to use this API in Visual Basic for Applications (VBA) because of the application of VBA in microsoft products as well as an independent programming language. This will surely be the most relevant in the case of application in Excel to accountants and those who prepare analyticals or translations of the foreign exchange rates for accounting, reporting or analysis.
How to do it?
The “how to do it” is preety simple. You can simply copy and save the public function below, to your addin file and start using the formula across your worksheets.
Sample Code for Excel Function
Public Function FOREX(Optional Transaction_Date As Date, Optional Foreign_Currency, Optional BR_or_SR) As Variant
‘Courtesy of Sushil Parajuli | contact@sushilparajuli.com
If Transaction_Date = 0 Then
Transaction_Date = Date
Else: End If
If IsMissing(Foreign_Currency) = True Then
Foreign_Currency = “USD”
Else: End If
If IsMissing(BR_or_SR) = True Then
BR_or_SR = “BR”
Else: End If
searchdate = Application.WorksheetFunction.Text(Transaction_Date, “yyyy-mm-dd”)
link = “https://www.nrb.org.np/api/forex/v1/rates?from=” & searchdate & “&to=” & searchdate & “&per_page=100&page=1”
Dim XMLPage As New MSXML2.XMLHTTP60
XMLPage.Open “GET”, link, False
XMLPage.send
‘getting relevant currency
maintext = XMLPage.responseText
maintext = Mid(maintext, InStr(1, maintext, Foreign_Currency, vbTextCompare), 70)
‘finding unit
unit = getnum(Mid(maintext, InStr(1, maintext, “unit”, vbTextCompare), 15))
‘finding buy
buy = getnum(Mid(maintext, InStr(1, maintext, “buy”, vbTextCompare), 15))
‘finding sell
sell = getnum(Mid(maintext, InStr(1, maintext, “sell”, vbTextCompare), 15))
‘geting exchange rate
If BR_or_SR = “BR” Then
FOREX = buy / unit
Else
FOREX = sell / unit
End If
End Function
Examples of Execution


Excel Addin
Visit this page if you want to download the related excel addin: Excel Forex Tool for Nepal (NRB)
Compile error syntax error vanxa ta dai🤔
let me help you vai,
1. did you enable all the references in the screen shot?
2. also paste this additional formula at the bottom for getnum function (i missed to include this above)
Function getnum(Phrase As String) As Double
Dim Length_of_String As Integer
Dim Current_Pos As Integer
Dim Temp As String
Length_of_String = Len(Phrase)
Temp = “”
For Current_Pos = 1 To Length_of_String
If (Mid(Phrase, Current_Pos, 1) = “-“) Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
If (Mid(Phrase, Current_Pos, 1) = “.”) Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
If (IsNumeric(Mid(Phrase, Current_Pos, 1))) = True Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
Next Current_Pos
If Len(Temp) = 0 Then
getnum = 0
Else
getnum = CDbl(Temp)
End If
End Function
Ref Edit Control wala reference chai xaina raixa
thik 6, teso vaye ma addin banayera haldinxu, install file ko form ma
huss, mail gardinu hai dai.. thank you☺
Hi ! Very useful tool. I work with exchange rates for reporting in excel. Helped a lot. Appreciate it!
I don’t know how I ended up here, but I thought this post was good.
Genuinely delighted to glance at this helpful content.
Admiring the hard work you put into your website. Great Stuff.
Just what I needed, thank you very much.
Keep on writing, great job!