web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

How to change Exchange rate Engine in F&O using X++

Kartik Hans Profile Picture Kartik Hans 181

Here many people ask can we change or create exchange rate engine to download data in D365 using custom code, Then answer is Yes, You can do pretty much in few steps if you have good understanding of API and X++ code.

Here I am taking an example of Oando API. You can register on their website to get Free API key for your testing and new enhancement.

Microsoft give you complete engine to download exchange rate from oanda but it won’t allow to define somewhere from which bank you can download exchange rate and other parameters which Oanda gives.

Here its Oanda API documentation will help you to understand which parameters you can use it.

OANDA Exchange Rates API Documentation

Possible parameters allowed for APi call.

Now we will understand what Microsoft gives you as part of standard integration.

This is standard class which actually run behind to download exchange rate rate.

It only allows following parameters.

Start Date, End Date, Fields, Decimal place and Quote.

Now lets start making some change to add more parameters like interbank and data_set.

First register on https://developer.oanda.com/ to get free API key.

I have used postman tool before even starting my custom code in D365 using X++ to test API.

If your API work with key and other parameters, You can start working on D365 changes.

Now its time to make some change in D365 F&O using X++.

Modify ExchangeRateProvider Enum to add your custom type : CustomOanda.

Then Duplicate standard class ExchangeRateProviderOanda to CustomExchangeRateProviderOanda and change all the reference.

Next you have to make change in API URL and request string.

private const URL ServiceURL = ‘https://www.oanda.com/rates/api/v1/rates/%1.xml?quote=%2&start=%3&end=%4&fields=%5&decimal_places=%6&Data_set=%7’;

You can add all possible parameters in URL like I added Data_Set=%7.

Next setup to change following method.

public IExchangeRateResponse GetExchangeRates(IExchangeRateRequest _request, IExchangeRateProviderConfig _config)
{

while(currencyPairsEnumerator.MoveNext())
{
URL OandaUrl = ServiceURL;

// Change Build URL Request to add value related to your parameters.

// Build the request URL.
str oandaRequestString;
if (singleRateForDateRange)
{
// getting an average rate for the date range so we invoke the service
// only once per currency pair using the from and to date
oandaRequestString = strFmt(OandaUrl,
currencyPairRequest.get_FromCurrency(),
currencyPairRequest.get_ToCurrency(),
fromDateForRequest,
toDateForRequest,
quoteTypeParameterForOANDA,
decimalPlaces,
data_set);
}
else
{
// invoke the service once for each day.
oandaRequestString = strFmt(OandaUrl,
currencyPairRequest.get_FromCurrency(),
currencyPairRequest.get_ToCurrency(),
fromDateForRequest,
fromDateForRequest,
quoteTypeParameterForOANDA,
decimalPlaces,
data_set);
}

}

}

Make sure you change all reference and Build and synch your project, New type will be visible in user interface to use and download exchange rate.

Happy to help


This was originally posted here.

Comments

*This post is locked for comments