Click or drag to resize

KotakNet Core

KotakNet DotNet Library

KotakNet.Core.dll wraps all the methods supported by Kotak API. This is where the user session is maintained. It has all methods that are necessary to build a standard trading platform

DotNet developers can build console or Winform or WPF application on the top of KotakNet.Core, build and deploy customized execution algos (like Spread orders, P2M etc) or build personalized trading platforms for clients.

DotNet developers can get started with KotakTrader or build from the scratch.

KotakTrader is a lightweight trading platform built with KotakNet. It's a winform and supports all the standard features of a trading platform. You can preview the demo here https://www.youtube.com/watch?v=VXgyNz0nZg4

Github Repo: https://github.com/howutrade/kotak-trader

Core Docs: Kotak

Dependency
  • WebSocket4Net.dll

  • SuperSocket.ClientEngine.dll

  • Newtonsoft.Json.dll

Login Flow
  • Set User Credentails

  • Call Kotak.Login

  • Call Kotak.GetMasterContract

Symbols will be downloaded in the background, please wait for the symbols to download before making any calls. Check SymbolStatus property for the download status

Common Parameters

Parameter

Value

Exch

NSE|NFO|BSE|CDS|MCX

Trdsym

CASH: Symbol (Ex: ITC)

FUT: [SYMBOL][YYMMMDD][FUT] (Ex: NIFTY22FEB24FUT)

OPT: [SYMBOL][YYMMMDD][STRIKE][OPT] (Ex: NIFTY22FEB2417300CE)

Transactions

BUY|SELL (SHORT|COVER)

Order Type

LIMIT|MARKET|SL|SL-M

Product Type

MIS|NRML

Quantity

CASH: Number of shares to Buy or Sell

FNO: Number of lots to Buy or Sell (Not LotSize)

Validity

DAY|IOC

Limit/Trigger Price

Number (KotakNet will automatically round the price to ticksize)

Stgycode

Alphanumeric, must be 3 characters

Tag

Alphanumeric, must be 3-24 characters

Quick Start (Building From Scratch)

Create a new project in Visual Studio, add reference to the below DLLs

  • KotakNet.Core.dll

  • WebSocket4Net.dll

  • SuperSocket.ClientEngine.dll

  • Newtonsoft.Json.dll

VB
Imports KotakNet.Core
Imports System.Threading

Module Demo
    Public Kotak As New Kotak

    ''' This is a basic example without any error handling
    Sub Main()
        '///Set Credentials
        '///set UserID property first before other properties as the settings are saved to file with 'UserID' as name
        Kotak.UserID = "XXXXXXXXX"
        Kotak.ConsumerKey = "xxxxxxxxxxxxxxxxxxxx"
        Kotak.ConsumerSecret = "xxxxxxxxxxxxxxxxxx"
        Kotak.AccessToken = "xxxxxxxxxx"
        Kotak.Password = "xxxx"

        '///Subscribe to Events
        AddHandler Kotak.AppUpdateEvent, AddressOf AppUpdate
        AddHandler Kotak.OrderUpdateEvent, AddressOf OrderUpdate
        AddHandler Kotak.QuotesReceivedEvent, AddressOf QuotesReceived

        '///Login to get Session Token
        Kotak.Login()

        '///Download Symbols
        Kotak.GetMasterContract()

        '/// Wait for the symbols to download
        Dim count As Integer = 0
        Do
            count = count + 1
            Thread.Sleep(1000)
            If (Kotak.SymbolStatus OrElse count > 300) Then Exit Do
        Loop

        If Not Kotak.SymbolStatus Then
            MsgBox("Symbol download fail", MsgBoxStyle.Exclamation, "KotakNet")
            Exit Sub
        End If

        '///Subscribe for Quotes
        Kotak.SubscribeQuotes("NSE", "ITC")
        Kotak.SubscribeQuotes("MCX", "CRUDEOIL22FEB18FUT")

        '///Place an order
        Dim OrderId As String = Kotak.PlaceRegularOrder("NSE", "ITC", "BUY", "MARKET", 1, "NRML", 0, 0)
        Console.WriteLine("OrderID: " & OrderId)

        Console.WriteLine("Press Any Key to exit")
        Console.ReadKey()
    End Sub

    Private Sub OrderUpdate(sender As Object, e As OrderUpdateEventArgs)
        Console.WriteLine("OrderUpdate - OrderId: " & e.OrderId & " Status: " & e.Status)
    End Sub

    Private Sub AppUpdate(sender As Object, e As AppUpdateEventArgs)
        Console.WriteLine("AppUpdate - Message: " & e.EventMessage)
    End Sub

    Private Sub QuotesReceived(sender As Object, e As QuotesReceivedEventArgs)
        Console.WriteLine("QuotesReceived - Symbol: " & e.TrdSym & " Ltp: " & e.LTP & " LTT: " & e.LTT.ToString("HH:mm:ss"))
    End Sub
End Module
Note Note

set UserID property first before other properties as the settings are saved to file with 'UserID' as name

Caution note Caution

In real case scenario, you need to add static variables (wherever applicable) to remove redundant calls

Security note Security Note

Store your credentials in a safe place, make sure you removed/masked any sensitve informations while sharing your project/code with others or while making video content