Skip to Main Content

.NET SDK

.NET wrapper (NorenRestApiWrapper) for the Shoonya OAuth API — combines REST calls and a WebSocket client behind a callback-based NorenRestApi class.

Overview

The .NET SDK is a wrapper of the Noren API combining REST calls and WebSocket streaming for trading. It targets .NET Standard 2.0, built on Visual Studio 2019, with a dependency on Newtonsoft.Json 9.0.1. The namespace is NorenRestApiWrapper; the primary class is NorenRestApi.

Callback-based, not async/awaitEvery request method takes a delegate — public delegate void OnResponse(NorenResponseMsg Response, bool ok) — rather than returning a Task. Structure your calling code around callbacks, not await, when integrating this SDK.

Installation

Repositorygithub.com/Shoonya-API-OAuth-Python/ShoonyaApidotNet
Target framework.NET Standard 2.0
DependencyNewtonsoft.Json 9.0.1
NamespaceNorenRestApiWrapper
Primary classNorenRestApi

Clone the repository and reference the project directly, or pull the compiled dependency from the Deps folder — there's no NuGet package as of this writing. Example projects are included: Example1, Example2_InlineHandler, Example3_Websocket, and Example4_oauth for the OAuth flow specifically.

Initialization

ParameterDescription
endPoint https://api.shoonya.com/OAuthlogin/authorize/oauth.
AppkeyThe secret key issued to you — do not append the user ID to it.

Create an instance of NorenRestApi to make requests. Every request method takes an OnResponse callback delegate as its first argument.

OAuth & Session Methods

MethodDescription
SendgetOAuthURL(oauth_url, client_id)Requests the OAuth provider to initiate verification with the end user. Returns a URL to open in a browser; on success, the redirect provides auth_code.
SendgetAccessToken(response, endPoint, authCode, secretcode, client_id, uid)Exchanges auth_code for an access token via the OnResponse callback, returning a GetAccessTokenResponse with access_token, susertoken, refresh_token, and actid.
SendGetUserDetails(response)Fetches enabled exchanges, order types, and product types for the logged-in user.
SendLogout(response)Terminates the current session.
SetSession(endpoint, uid, pwd, usertoken)Initializes the API with an existing session instead of creating a new one via login.

Available Functionality

CategoryMethods
WatchListsSendGetMWList, SendGetMarketWatch, SendAddMultiScripsToMW, SendDeleteMultiMWScrips
MarketSendSearchScrip, SendGetSecurityInfo, GetQuote, time/daily price series, GetOptionChain, GetIndexList, ExchMsg, top-list methods
Calculatorsspan_calculator, get_option_greek, GetBrokerage
Orders & TradesSendPlaceOrder, SendModifyOrder, SendCancelOrder, SendExitSNOOrder, SendProductConversion, SendGetOrderMargin, SendGetOrderBook, SendGetTradeBook, SendGetOrderHistory, SendGetMultiLegOrderBook, SendGetPositionBook, SendGetHoldings, SendGetLimits
StreamingConnect, SubscribeMarketData, UnSubscribeMarketData, SubscribeOrderUpdate

Order types beyond a plain LMT/SL-LMT buy/sell are supported here — PlaceOrder covers Cover Orders (prd = H) and Bracket Orders (prd = B) with blprc/bpprc/trailprc fields, unlike the REST Place Order endpoint documented elsewhere on this site, which rejects CO/BO. Confirm which product types your account is enabled for before relying on this.

Quick Start Example

Best Practices

  • Design around the callback signature (OnResponse) from the start — retrofitting async/await over a callback-based SDK later is more work than structuring for it up front.
  • Cast the NorenResponseMsg in your callback to the specific response type documented for that call (e.g. GetAccessTokenResponse, PlaceOrderResponse) and check stat == "Ok" before reading any other field.
  • Cover Orders and Bracket Orders (prd = H / B) are supported here but not on the plain REST Place Order endpoint — don't assume feature parity between this SDK and the raw HTTP API when porting code between platforms.
  • Reference the Example4_oauth project in the repository for a complete working OAuth handshake — it's the fastest way to confirm your endPoint and Appkey are configured correctly before writing your own integration.
  • Same as the Python SDK, this wrapper doesn't auto-refresh an expired token — pair it with Token Renewal for unattended processes.