Giant spring sale! Up to 50% off!
Home Buy Data Subscribe API Support My Account

Sample source code

Use the code provided below as a starting point for creating your own applications. We also have an open-source Kibot API Client application written in .NET that further demonstrates the communication between the client application and our servers. All data from our servers can be sent in a compressed format making the client-server communication and data download more efficient.

The source code below performs the following actions:

  1. Logs in to the server using the Guest account
  2. Downloads the last 10 days of daily data for MSFT (Microsoft)
  3. Decompresses the Gzip data stream automatically
  4. Saves decompressed data to a text file


VB.NET version of the source code

You can find the C# version of the same code below.

Private Sub Download()
        Dim UrlLogin As String
        Dim UrlDataRequest As String
        Dim FileName As String
        Dim Request As System.Net.HttpWebRequest
        Dim Response As System.Net.WebResponse
        Dim Stream As System.IO.Stream
        Dim FileStream As System.IO.FileStream
        Dim Text As String
        Dim UserAgent As String
        Dim BytesRead As Integer
        Dim Buffer As Byte()
        UrlLogin = "" & _
        UrlDataRequest = "" & _
        FileName = "c:\MSFT.txt"
        UserAgent = "Your application name or id"
        'Login to the server first
            Request = System.Net.WebRequest.Create(UrlLogin)
            Request.UserAgent = UserAgent
            Response = Request.GetResponse
            Text = New System.IO.StreamReader(Response.GetResponseStream, _
            'Check response
            If Not Text.StartsWith("200") Then
                Throw New Exception("Cannot login to the server. " & Text)
            End If
        Catch ex As System.Net.WebException
            Throw ex
        End Try
        'Delete existing file
        If System.IO.File.Exists(FileName) Then
        End If
        'Download data
            Request = System.Net.WebRequest.Create(UrlDataRequest)
            Request.AutomaticDecompression = _
                System.Net.DecompressionMethods.Deflate Or _
            Request.Headers.Add("Accept-Encoding", "gzip,deflate")
            Request.UserAgent = UserAgent
            FileStream = System.IO.File.Create(FileName)
            Response = Request.GetResponse()
            Stream = Response.GetResponseStream()
            Buffer = New Byte(4 * 1024 - 1) {}
            BytesRead = Stream.Read(Buffer, 0, Buffer.Length)
            While BytesRead > 0
                FileStream.Write(Buffer, 0, BytesRead)
                BytesRead = Stream.Read(Buffer, 0, Buffer.Length)
            End While
        Catch ex As System.Net.WebException
            Throw ex
            If FileStream IsNot Nothing Then
            End If
        End Try
    End Sub

C# version of the source code:

private void Download()
    string UrlLogin = null;
    string UrlDataRequest = null;
    string FileName = null;
    System.Net.HttpWebRequest Request = null;
    System.Net.WebResponse Response = null;
    System.IO.Stream Stream = null;
    System.IO.FileStream FileStream = null;
    string Text = null;
    string UserAgent = null;
    int BytesRead = 0;
    byte[] Buffer = null;
    UrlLogin = "" + 
    UrlDataRequest = "" + 
    FileName = "c:\\MSFT.txt";
    UserAgent = "Your application name or id";
    //Login to the server first
    try {
        Request = System.Net.WebRequest.Create(UrlLogin);
        Request.UserAgent = UserAgent;
        Response = Request.GetResponse();
        Text = new System.IO.StreamReader(Response.GetResponseStream(), 
        //Check response
        if (!Text.StartsWith("200")) {
            throw new Exception("Cannot login to the server. " + Text);
    } catch (System.Net.WebException ex) {
        throw ex;
    //Delete existing file
    if (System.IO.File.Exists(FileName)) {
    //Download data
    try {
        Request = System.Net.WebRequest.Create(UrlDataRequest);
        Request.AutomaticDecompression = 
         System.Net.DecompressionMethods.Deflate | 
        Request.Headers.Add("Accept-Encoding", "gzip,deflate");
        Request.UserAgent = UserAgent;
        FileStream = System.IO.File.Create(FileName);
        Response = Request.GetResponse();
        Stream = Response.GetResponseStream();
        Buffer = new byte[4 * 1024];
        BytesRead = Stream.Read(Buffer, 0, Buffer.Length);
        while (BytesRead > 0) {
            FileStream.Write(Buffer, 0, BytesRead);
            BytesRead = Stream.Read(Buffer, 0, Buffer.Length);
    } catch (System.Net.WebException ex) {
        throw ex;
    } finally {
        if (FileStream != null) {

Historical Data API - Table of Contents

    Historical data API  
    How to get access
    Login request
    Download historical data
    Stock data adjustments
    Logout request
    Sample source code
    Sample client application
    Data compression
    Server responses