Click here to Login




Step by step on how to get free realtime/delayed data for stocks, futures and currencies

Updated on 2011-07-26





While waiting for the release of the real-time version of QuantShare, we will show you how to implement a script to get free real-time (Example: From Bats Exchange) and delayed snapshot data for open charts.
This step-by-step article will explain to you the different script's instructions and it will show you how easy it is to implement such script.

The complete script is available here: Link. I suggest you look at it then complete reading this step-by-step guide to get a full understanding on how it works.


Script Loop

The first thing that we should do is to create a loop. Within this loop, we will check open charts and download real-time or delayed for the corresponding stocks, futures, ETFs or currencies.
The infinite loop can be implemented using "while(true)" instruction. The code within this loop will then be executed indefinitely.


Snapshot and Pausing

Because we are going to execute silently a downloader to get quotes, we should "pause" the thread a few seconds to avoid application crash. We can implement this using the "Sleep" method of the "App.Main" class. This method gets the number of milliseconds to pause the thread. In our script will multiply the variable "seconds" by 1000 and then initialize "seconds" at the beginning of the script. This variable will define the interval at which the data snapshots will be taken.


Getting Open Charts

The "Charts" class is used to get and manipulate QuantShare charts. The "GetAllCharts" method gets an array of "Chart" objects. Each "Chart" object contains a reference to an existing (open) chart. The different methods available within this class allow you to perform several actions/operation (move, translate, close, refresh...).
Once we get all open charts, we should loop through each one and check whether the chart time-frame is set to Historical or Intraday. If intraday data is referenced then we call the "GetNewData" function, which in turn will call our downloader to get the appropriate real-time/delayed data.


Downloading Realtime/Delayed Data

The "GetNewData" is a custom function, which means that it is implemented by us and it should appear after the "#functions#" tag.

The "Chart" object is passed to this function for two reasons:
- To get the ticker symbol that is used by the chart
- To pass it to the downloader callback function. The callback function will then be executed by the downloader when the downloading process is completed.

The role of the "GetNewData" function is to create the different parameters that will be passed to the "Downloader.DownloadData" function. Some of these parameters vary depending on the downloader we are going to use. In this article, we will use the Intraday Data for US Stocks item.

Here is a brief description of the different parameters:
- Category: The category under which you saved this item
- Name: The downloader item name
- Silent: Specify whether to display the downloader progress form or not
- Symbols: Specify for which stocks, futures or Forex currencies you want to get real-time or delayed data
- Fields: An array that contains the fields that will be passed to downloader. Each downloader has its own fields (Different tabs at the top when you open a downloader in the "Download Manager").
In this example, we have set the field "Number of past days" to "1" to instruct the downloader to get only one day worth of one-minute bars.

Downloader.DownloadData("", "Intraday Data for US Stocks", true, symbols, fields, DownloadComplete, chart);

Here is another example that uses a downloader to get free futures data:

Downloader.DownloadData("", "Intraday Data for Futures Contracts", true, symbols, null, DownloadComplete, chart);

Differences with the previous example:
- Downloader name (2nd parameter)
- Null (no data) passed to "Fields" (fifth parameter)

The item can be downloaded here: Intraday Data for Futures Contracts


Downloader Callback Function

As we said previously, this function is executed once the downloading and data insertion process is completed successfully. At that moment, new data is not yet visible on the chart. We have to call the "Update" method of the "Chart" object to instruct the chart to reload data and refresh the different OHLC and technical indicators graphs.


Important Information

You can try different snapshot intervals, but be aware that setting low values can hang-up or crash your computer.




How to execute the Script

In QuantShare main menu, select "Tools" then "Script Editor".
Select "File" then "New" to create a new script. Enter the script name then click on "OK".

Copy the complete script (Link) then paste it in the script editor control.

To add the script to the bookmark panel, select "Settings" then "Add current script to bookmark panel".
QuantShare bookmark panel is located under QuantShare main menu; it is similar to your browser's bookmark panel that is situated under the URL bar.

To run the script and get real-time or delayed data for your favorite securities, open one or several charts, select one-minute or a higher time-frame then double click on the script shortcut (In the bookmark panel).

You can also use the "Task Manager" to create a new task that will automatically execute the script at application startup. The "Task Manager" form can be opened by selecting "Analysis" then "Task Manager".











one comment (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1461 days ago

Profile Graphs
Posted 1566 days ago

QuantShare
Previous Posts

More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.