July 23, 2024

Hot to create a Plugin in Dynamics 365 Sales to Store Daily Market Prices from Yahoo
Finance

As a sales professional, it’s important to keep track of the market prices of your accounts to make informed decisions about pricing and sales strategies. One way to do this is to fetch daily market prices from Yahoo Finance API and store them in Dynamics 365 Sales. In this article, we’ll walk you through the steps to create a plugin that fetches daily market prices from Yahoo Finance API and stores them in a custom time series entity related to the Account entity.

Step 1: Set up the integration with Yahoo Finance API

First, you need to set up the integration with the Yahoo Finance API to fetch the daily market prices of your accounts. You can use the REST API provided by Yahoo Finance to fetch the data. You will need to register for an API key and use it to authenticate your API requests.

Step 2: Create a custom time series entity

Next, you need to create a custom time series entity to store the daily market prices of your accounts. This entity will have a relationship with the Account entity to link each time series record with its corresponding account. You can create fields to store data such as date, closing price, high price, low price, and volume.

Step 3: Create a plugin to fetch daily market prices

Create a plugin that fetches the daily market prices of an account from Yahoo Finance API. This plugin should trigger when a new account is created or when an existing account is updated. You can use the HttpClient class in C# to make API requests and fetch the data from Yahoo Finance. Here’s an example code snippet that fetches the closing price of a stock from Yahoo Finance:

using System;

using System.Net.Http;

// Replace YOUR_API_KEY with your actual API key

string url = “https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-quotes?region=US&symbols=MSFT”;

string apiKey = “YOUR_API_KEY”;

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Add(“X-RapidAPI-Key”, apiKey);

HttpResponseMessage response = await client.GetAsync(url);

string responseBody = await response.Content.ReadAsStringAsync();

// Parse the JSON response to get the closing price

double closingPrice = 0;

if (response.IsSuccessStatusCode)

{

    dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody);

    closingPrice = json.quoteResponse.result[0].regularMarketPrice;

}

Step 4: Store the daily market prices in the time series entity

Once you have fetched the daily market prices, store them in the time series entity related to the account. You can create a new time series record for each day and link it with the corresponding account record. Here’s an example code snippet that creates a new time series record and links it with the corresponding account record:

// Replace ACCOUNT_ID with the actual account ID

EntityReference accountRef = new EntityReference(“account”, new Guid(“ACCOUNT_ID”));

// Create a new time series record and set the fields

Entity timeSeriesRecord = new Entity(“new_time_series”);

timeSeriesRecord.Attributes[“new_date”] = DateTime.Today;

timeSeriesRecord.Attributes[“new_closing_price”] = closingPrice;

timeSeriesRecord.Attributes[“new_account”] = accountRef;

// Save the new time series record

service.Create(timeSeriesRecord);

About The Author

Founder & CEO of Logol AG www.logol.com Microsoft MVP Business Solutions Active member of Scrum Alliance with the certifications CSM and CSP I got Microsoft MCP, MCPD, MCTS certifications as well.Logol, pioneering specialist in the field of cloud-enabled digital transformation, is the first operator specifically created to implement modular programs designed to unleash breakthrough innovation and rationalize business processes. Founded and directed by an award-winning expert tapping directly into the vision of leading IT companies and spearheading forward-thinking digitalization projects, Logol addresses the needs of enterprises in all sectors as they embrace new technologies and organizational change in the era big data and artificial intelligence. Logol helps organizations leverage the power of the most advanced cloud technologies, offering end-to-end consultancy for total digital transformation and business process automation, employing agile methodologies and change management techniques for smooth transitions towards new business paradigms. Digital transformation programs are a milestone in a company’s business evolution and can be the basis of their success. Accompanying clients as they transform their business processes, Logol assists them in rethinking not only the scope of their technologies, but also the strategy, mindset and company culture that make digital transformation viable and effective. As digital transformation programs are successful only if approached with the highest professional competence, Logol selects and employs brilliant professionals who demonstrate outstanding technical expertise in the most advanced information technologies, in depth strategic knowledge of business processes and innovation, and refined soft skills to better support people and organizations facing change. Logol is headquartered in Switzerland and addresses the needs of both public and private sector players by promoting a comprehensive and proactive approach to digital transformation as a necessary step for inclusion and competitiveness in today’s digital economy.

Related posts