Analyzing the latest "barchart.com" website

Is there a way to extract data daily from barchart.com, specifically the close/open/high prices? I can't find the values in the page code or the JavaScript script that loads it. Maybe downloading the Excel file using the "download" button is easier, but I can't locate the download link either as it seems to be processed by a script. I'm working with C#, so any suggestions or tips would be greatly appreciated. Thanks.

Answer №1

If you inspect the network tab in your browser's developer tools, you'll uncover the URL used for fetching the data. You can simply make a direct call to that URL and manipulate the data as needed. While I'm showcasing a jQuery example here (using the snippet tool), executing this from C# is straightforward with the WebClient.DownloadString() method.

var url = 'https://core-api.barchart.com/v1/quotes/get?fields=symbol%2CcontractName%2ClastPrice%2CpriceChange%2CopenPrice%2ChighPrice%2ClowPrice%2CpreviousPrice%2Cvolume%2CopenInterest%2CtradeTime%2CsymbolCode%2CsymbolType%2ChasOptions&list=futures.contractInRoot&root=HG&meta=field.shortName%2Cfield.description&hasOptions=true&raw=1';

$('#data').load(url);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Data: <br />
<textarea id="data" cols="50" rows="8"></textarea>

C# example:

public static void DownloadString(string address)
{
    WebClient client = new WebClient();
    string response = client.DownloadString(address);

    Console.WriteLine(response);
    return response;
}

var url = 'https://core-api.barchart.com/v1/quotes/get?fields=symbol%2CcontractName%2ClastPrice%2CpriceChange%2CopenPrice%2ChighPrice%2ClowPrice%2CpreviousPrice%2Cvolume%2CopenInterest%2CtradeTime%2CsymbolCode%2CsymbolType%2ChasOptions&list=futures.contractInRoot&root=HG&meta=field.shortName%2Cfield.description&hasOptions=true&raw=1';

var data = DownloadString(url);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to display a message or alert after a page has been re

I've implemented Jquery Toastr to display success messages, functioning similarly to an alert for a brief period. My objective is to display a message after the page reloads. The issue arises when the page is reloaded, causing the JavaScript to reloa ...

"Exploring the Magic of Jquery's Fadein() Animation

i have experience with writing code for a jQuery fadein effect. imagine I have an HTML element stored in a variable, like this: var sHtml="<div>Other content</<div><div id='frm'>hello</<div>"; modal.load(jQuery(sHt ...

How can I repeatedly send a request without having to do a hard refresh using AJAX?

Whenever I send an AJAX request to delete a file, everything works fine the first time. However, the second time it does not work anymore and I end up having to do a "hard refresh". This is the code snippet in question: <?php if(isset($_POST['del ...

HTML slider overlaps fixed buttons

I have a fixed button on my HTML site that redirects to another link. It appears correctly on most pages, but overlaps with the slider on my index page. $(document).ready(function(){ // hide #back-top first //$(".back-top").hide(); // fade in # ...

Are there any additional built-in features for the HttpServletResponse object in Struts2?

Currently, I am using the code below to retrieve JSON data using struts2-hibernate. In the getZone method, I have utilized HttpServletResponse response= (HttpServletResponse) ActionContext.getContext().get(StrutsStatics.HTTP_RESPONSE); to send back the JSO ...

Instead of using a string in the createTextNode() function, consider utilizing a variable

I am attempting to use JavaScript to add another list item to an unordered list. I want the list item to display dynamic content based on a pre-existing variable. While I can successfully append a list item by using a string, things go awry when I try to i ...

Unveiling the Art of JSON Parsing and Effectively Accessing

I am currently using CURL for sending a request and the response received is in JSON format. I need help with parsing this data and inserting it into my database. <?php $url = 'http://example.com/api/endpoint'; $phoneNumber = '123456789 ...

Create a structured HTML list dynamically with JavaScript

Currently, I am attempting to showcase my JavaScript array in an ordered list format, like you would typically see in an HTML element. For example, if the array of strings passed is: pets(['cat', 'dog', 'mouse']), I aim to dis ...

What is the best way to create a button that can cycle through various divs?

Suppose I want to create a scroll button that can navigate through multiple div elements. Here is an example code snippet: <div id="1"></div> <div id="2"></div> <div id="3"></div> <div id="4"></div> <div ...

`Finding values in JMeter JSON response using a conditional JSON Extractor`

When I receive a JSON string, it looks something like this: [{"id":123,"name":"XX","default":false,"type":"other"},{"id":789,"name":"ZZ","default":false,"type":"first"}] I am trying to extract the id where the name is ZZ, which should result in 789. I at ...

Exploring the features of AngularJS, one can delve into the ControllerAs syntax

Currently, I am in the process of developing a directive and following the guidelines outlined in the John Papa style guide. In line with this, I have adopted the ControllerAs syntax approach and implemented a small directive as shown below: (function() { ...

How to use the ObjC RestKit library for object mapping to a JSON NSString?

I'm currently utilizing RestKit on iOS. I've set up an object and its mapping, allowing me to communicate data with the server. Now, I'd like to have the -description method of my mapped objects return the JSON mapping for easier logging to ...

Problems with script-driven dynamic player loading

I am attempting to load a dynamic player based on the browser being used, such as an ActiveX plugin for Internet Explorer using the object tag and VLC plugin for Firefox and Google Chrome using the embed tag. In order to achieve this, I have included a scr ...

Struggling with incorporating a button into a ReactJS table

I am trying to display a (view) button in the table, but I encountered the following error: Module parse failed: Unexpected token < in JSON at position 165 while parsing near '...2021", "view": <button type="submit...' You m ...

Issue with React component not updating when the "Date" value in its state is changed

Disclaimer: I am currently working with React using Typescript. I have a particular component that, upon mounting, initializes state with a date like this: constructor(props: SomeProps) { super(props); const fromDate = new Date(); fromDat ...

Implement the retrofit function to fetch and update with fresh data

Recently, I have been facing an issue with my Retrofit implementation where it used to work perfectly a few weeks ago. Now, whenever I run the code, it only loads the data once. Even if I make changes to the text or add new values in the JSON data, it stil ...

In JavaScript, the clearInterval function does not halt the execution of the

I am working with a JavaScript code that displays messages every 6 seconds using the setInterval function. Here is the code snippet: $(function () { count = 0; wordsArray = ["<h1>Offer received</h1>", "<h1>Offer reviewed</h1&g ...

Using Angular template reference variables for inputs to bind specific buttons with the same structure

Currently, I am exploring how to connect an input with a button in a row of buttons for opening images, inspired by an example shared by Mr. ruth. The layout of buttons in my web application resembles the following structure: topnav.component.html: <but ...

Is it true that Javascript's onclick global event handlers fire prior to the page being fully loaded

I'm trying to set a global event handler for an image, but running into issues. When I use the code document.getElementById("post_image").onclick = photoEnlarge;, it returns an error saying Uncaught TypeError: Cannot set property 'onclick' ...

Error: Unable to locate module - Invalid generator instance detected. The Asset Modules Plugin has been started with a generator object that does not adhere to the API standards

Encountering an issue in nextjs when utilizing the 'asset/inline' Asset Module Type within a custom webpack configuration while running yarn dev. I attempted to utilize the 'asset/inline' asset module type to output the URI of the impor ...