.NET
OpenAlgo.NET
OpenAlgo.NET SDK for algorithmic trading - C# client for OpenAlgo API
Installation
To install the OpenAlgo.NET library, use NuGet:
dotnet add package OpenAlgo.NETOr via Package Manager:
Install-Package OpenAlgo.NETCompatibility
.NET
6.0
LTS (Long Term Support)
.NET
7.0
STS (Standard Term Support)
.NET
8.0
LTS (Long Term Support) - Recommended
The SDK is built using only built-in .NET libraries with no external dependencies.
Get the OpenAlgo apikey
Make Sure that your OpenAlgo Application is running. Login to OpenAlgo Application with valid credentials and get the OpenAlgo apikey
For detailed function parameters refer to the API Documentation
Getting Started with OpenAlgo.NET
First, import the Api class from the OpenAlgo.NET library and initialize it with your API key:
Examples
Please refer to the documentation on order constants, and consult the API reference for details on optional parameters
Sync API Reference
PlaceOrder example
To place a new market order:
Place Market Order Response
To place a new limit order:
Place Limit Order Response
PlaceSmartOrder Example
To place a smart order considering the current position size:
Place Smart Market Order Response
OptionsOrder Example
To place ATM options order
Place Options Order Response
To place ITM options order
Place Options Order Response
To place OTM options order
Place Options Order Response
OptionsMultiOrder Example
To place Iron Condor options order (Same Expiry)
OptionsMultiOrder Response
To place Diagonal Spread options order (Different Expiry)
OptionsMultiOrder Response
BasketOrder example
To place a new basket order:
Basket Order Response
SplitOrder example
To place a new split order:
SplitOrder Response
ModifyOrder Example
To modify an existing order:
Modify Order Response
CancelOrder Example
To cancel an existing order:
CancelOrder Response
CancelAllOrder Example
To cancel all open orders and trigger pending orders
CancelAllOrder Response
ClosePosition Example
To close all open positions across various exchanges
ClosePosition Response
OrderStatus Example
To Get the Current OrderStatus
OrderStatus Response
OpenPosition Example
To Get the Current OpenPosition
OpenPosition Response
Quotes Example
Quotes response
MultiQuotes Example
MultiQuotes Response
Depth Example
Depth Response
History Example
History Response
Intervals Example
Intervals Response
intervals reports only what the connected broker supports. The interval field of /history accepts this full set, and rejects anything else: 1s, 5s, 10s, 15s, 30s, 45s, 1m, 2m, 3m, 5m, 10m, 15m, 20m, 30m, 1h, 2h, 3h, 4h, D, W, M, Q, Y.
OptionChain Example
Note : To fetch entire option chain for a expiry remove the strikeCount (optional) parameter
OptionChain Response
Symbol Example
Symbol Response
Search Example
Search Response
OptionSymbol Example
ATM Option
OptionSymbol Response
ITM Option
OptionSymbol Response
OTM Option
OptionSymbol Response
SyntheticFuture Example
SyntheticFuture Response
OptionGreeks Example
OptionGreeks Response
Expiry Example
Expiry Response
Instruments Example
/instruments is the one v1 market-data endpoint that is a GET rather than a POST. It takes apikey, an optional exchange and an optional format (json or csv) as query parameters, and the SDK issues that GET for you. Omitting exchange makes the SDK loop over every supported exchange and combine the results client-side.
Instruments Response
Telegram Alert Example
Telegram Alert Response
Funds Example
Funds Response
Margin Example
Margin Response
OrderBook Example
OrderBook Response
TradeBook Example
TradeBook Response
PositionBook Example
PositionBook Response
Holdings Example
Holdings Response
Holidays Example
Holidays Response
Timings Example
Timings Response
Analyzer Status Example
Analyzer Status Response
Analyzer Toggle Example
Analyzer Toggle Response
Endpoints not wrapped by the SDK
The OpenAlgo.NET SDK does not expose helpers for the GTT endpoints, multioptiongreeks or ping. Reach them by posting to the REST endpoint directly at http://127.0.0.1:5000/api/v1/<endpoint>, passing the same apikey field the SDK sends.
GTT (Good Till Triggered)
Four endpoints, all POST with a flat JSON body: placegttorder, modifygttorder, cancelgttorder and gttorderbook. trigger_type is SINGLE or OCO, and product accepts only CNC or NRML; MIS is rejected because a GTT can sit with the broker for days.
SINGLE, buy IDEA if it dips to 9.55:
For SINGLE send exactly one of triggerprice_sl (trigger sits below LTP) or triggerprice_tg (trigger sits above LTP) and leave the other at 0. For OCO send all four of triggerprice_sl, stoploss, triggerprice_tg and target, with triggerprice_sl strictly less than triggerprice_tg. modifygttorder takes the same body plus trigger_id, cancelgttorder takes apikey, strategy and trigger_id, and gttorderbook takes apikey alone and returns the active triggers under data.
MultiOptionGreeks
optiongreeks prices one symbol at a time. multioptiongreeks prices 1 to 50 option symbols in a single call, with interest_rate and expiry_time set once for the whole batch:
Individual items can fail while the batch still returns "status": "success", so inspect each entry in data and the summary block.
Ping
ping confirms the API key is valid and reports the connected broker:
Async API Reference
All methods have async versions with the Async suffix. For example:
Available Async Methods
PlaceOrder()
PlaceOrderAsync()
PlaceSmartOrder()
PlaceSmartOrderAsync()
OptionsOrder()
OptionsOrderAsync()
OptionsMultiOrder()
OptionsMultiOrderAsync()
BasketOrder()
BasketOrderAsync()
SplitOrder()
SplitOrderAsync()
ModifyOrder()
ModifyOrderAsync()
CancelOrder()
CancelOrderAsync()
CancelAllOrder()
CancelAllOrderAsync()
ClosePosition()
ClosePositionAsync()
OrderStatus()
OrderStatusAsync()
OpenPosition()
OpenPositionAsync()
Quotes()
QuotesAsync()
MultiQuotes()
MultiQuotesAsync()
Depth()
DepthAsync()
History()
HistoryAsync()
Intervals()
IntervalsAsync()
OptionChain()
OptionChainAsync()
Symbol()
SymbolAsync()
Search()
SearchAsync()
OptionSymbol()
OptionSymbolAsync()
SyntheticFuture()
SyntheticFutureAsync()
OptionGreeks()
OptionGreeksAsync()
Expiry()
ExpiryAsync()
Instruments()
InstrumentsAsync()
Telegram()
TelegramAsync()
Funds()
FundsAsync()
Margin()
MarginAsync()
OrderBook()
OrderBookAsync()
TradeBook()
TradeBookAsync()
PositionBook()
PositionBookAsync()
Holdings()
HoldingsAsync()
Holidays()
HolidaysAsync()
Timings()
TimingsAsync()
AnalyzerStatus()
AnalyzerStatusAsync()
AnalyzerToggle()
AnalyzerToggleAsync()
WebSocket Streaming
LTP Data (Streaming Websocket)
LTP Response
Quotes (Streaming Websocket)
Quote Response
Depth (Streaming Websocket)
Depth Response
WebSocket connection notes
The proxy listens on ws://127.0.0.1:8765. Every client authenticates with its OpenAlgo API key before subscribing, and a connection that has not authenticated within 15 seconds is closed. Subscriptions carry a mode: 1 for LTP, 2 for Quote and 3 for Depth. The strings LTP, Quote and Depth are accepted as well and are matched case-insensitively; Quote is the default when the field is omitted. LTP updates are throttled to one per symbol per 50 ms, so a fast-moving symbol delivers at most 20 LTP messages a second.
Order Updates (Streaming WebSocket)
The same proxy on port 8765 also carries account-scoped order updates. The OpenAlgo.NET SDK does not wrap them, so send the raw frames on your own WebSocket connection: authenticate first, then subscribe.
The server acknowledges the subscription:
Every subsequent status change on any order in the account then arrives as:
{"action": "unsubscribe_orders"} stops the stream. Unlike a market-data subscription there is no symbol, exchange or mode: the subscription covers the whole account.
WebSocket Methods Summary
Connect() / ConnectAsync()
Connect to WebSocket server
Disconnect() / DisconnectAsync()
Disconnect from WebSocket server
SubscribeLtp(instruments, callback)
Subscribe to LTP updates
UnsubscribeLtp(instruments)
Unsubscribe from LTP updates
SubscribeQuote(instruments, callback)
Subscribe to Quote updates
UnsubscribeQuote(instruments)
Unsubscribe from Quote updates
SubscribeDepth(instruments, callback)
Subscribe to Market Depth updates
UnsubscribeDepth(instruments)
Unsubscribe from Market Depth updates
GetLtp(exchange, symbol)
Get cached LTP data
GetQuotes(exchange, symbol)
Get cached Quote data
GetDepth(exchange, symbol)
Get cached Depth data
Error Handling
Complete API Reference
Order Management
PlaceOrder()
PlaceOrderAsync()
Place a new order
PlaceSmartOrder()
PlaceSmartOrderAsync()
Place a smart order with position sizing
ModifyOrder()
ModifyOrderAsync()
Modify an existing order
CancelOrder()
CancelOrderAsync()
Cancel a specific order
CancelAllOrder()
CancelAllOrderAsync()
Cancel all open orders
ClosePosition()
ClosePositionAsync()
Close all open positions
OrderStatus()
OrderStatusAsync()
Get status of a specific order
OpenPosition()
OpenPositionAsync()
Get current open position quantity
Basket & Split Orders
BasketOrder()
BasketOrderAsync()
Place multiple orders in a single request
SplitOrder()
SplitOrderAsync()
Split large order into smaller chunks
Options Trading
OptionsOrder()
OptionsOrderAsync()
Place ATM/ITM/OTM option order
OptionsMultiOrder()
OptionsMultiOrderAsync()
Place multi-leg option strategy
OptionSymbol()
OptionSymbolAsync()
Get option symbol by offset
OptionChain()
OptionChainAsync()
Get full option chain data
OptionGreeks()
OptionGreeksAsync()
Calculate option Greeks
SyntheticFuture()
SyntheticFutureAsync()
Calculate synthetic future price
Expiry()
ExpiryAsync()
Get expiry dates for symbol
Market Data
Quotes()
QuotesAsync()
Get real-time quotes for a symbol
MultiQuotes()
MultiQuotesAsync()
Get quotes for multiple symbols
Depth()
DepthAsync()
Get market depth (order book)
History()
HistoryAsync()
Get historical OHLCV data
Intervals()
IntervalsAsync()
Get supported time intervals
Symbol & Search
Symbol()
SymbolAsync()
Get symbol details
Search()
SearchAsync()
Search for symbols
Instruments()
InstrumentsAsync()
Download all instruments
Account & Portfolio
Funds()
FundsAsync()
Get funds and margin details
Margin()
MarginAsync()
Calculate margin requirements
OrderBook()
OrderBookAsync()
Get order book
TradeBook()
TradeBookAsync()
Get trade book
PositionBook()
PositionBookAsync()
Get position book
Holdings()
HoldingsAsync()
Get stock holdings
Utilities
Holidays()
HolidaysAsync()
Get trading holidays for a year
Timings()
TimingsAsync()
Get exchange timings for a date
Telegram()
TelegramAsync()
Send Telegram alert message
AnalyzerStatus()
AnalyzerStatusAsync()
Get analyzer mode status
AnalyzerToggle()
AnalyzerToggleAsync()
Toggle analyze/live mode
WebSocket Streaming
Connect()
ConnectAsync()
Connect to WebSocket server
Disconnect()
DisconnectAsync()
Disconnect from WebSocket
SubscribeLtp()
SubscribeLtpAsync()
Subscribe to LTP updates
UnsubscribeLtp()
UnsubscribeLtpAsync()
Unsubscribe from LTP
SubscribeQuote()
SubscribeQuoteAsync()
Subscribe to Quote updates
UnsubscribeQuote()
UnsubscribeQuoteAsync()
Unsubscribe from Quote
SubscribeDepth()
SubscribeDepthAsync()
Subscribe to Depth updates
UnsubscribeDepth()
UnsubscribeDepthAsync()
Unsubscribe from Depth
GetLtp()
-
Get cached LTP data
GetQuotes()
-
Get cached Quote data
GetDepth()
-
Get cached Depth data
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
Last updated
Was this helpful?