Java
OpenAlgo Java SDK
OpenAlgo Java SDK for algorithmic trading - Java client library for OpenAlgo API. Supports order placement, market data, options trading, and real-time WebSocket streaming.
Installation
Maven
Add the following dependency to your pom.xml:
<dependency>
<groupId>in.openalgo</groupId>
<artifactId>openalgo</artifactId>
<version>1.0.1</version>
</dependency>Gradle
Add the following to your build.gradle:
implementation 'in.openalgo:openalgo:1.0.1'Compatibility
Java 11
LTS (Long Term Support)
Java 17
LTS (Long Term Support)
Java 21
LTS (Long Term Support) - Recommended
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 Java SDK
First, import the OpenAlgo class 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
API Reference
PlaceOrder Example
To place a new market order (simplest form):
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
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 order status:
OrderStatus Response
OpenPosition Example
To get the current open position:
OpenPosition Response
Quotes Example
Quotes Response
Depth Example
Depth Response
History Example
History Response
Intervals Example
Intervals Response
Symbol Example
Symbol Response
Search Example
Search Response
OptionsOrder Example
To place ATM options order:
OptionsOrder Response
OptionsMultiOrder Example
To place multi-leg options strategy (e.g., Bull Call Spread):
OptionsMultiOrder Response
OptionChain Example
OptionChain Response
OptionGreeks Example
OptionGreeks Response
Funds Example
Funds Response
OrderBook Example
OrderBook Response
TradeBook Example
TradeBook Response
PositionBook Example
PositionBook Response
Holdings Example
Holdings Response
Telegram Alert Example
Telegram Alert Response
Holidays Example
Holidays Response
Timings Example
Timings Response
Analyzer Status Example
Analyzer Status Response
Analyzer Toggle Example
Analyzer Toggle Response
WebSocket Streaming
LTP Data (Streaming WebSocket)
LTP Response
Quotes (Streaming WebSocket)
Quote Response
Depth (Streaming WebSocket)
Depth Response
Error Handling
Complete API Reference
Order Management
placeorder()
Place a new order
placesmartorder()
Place a smart order with position sizing
modifyorder()
Modify an existing order
cancelorder()
Cancel a specific order
cancelallorder()
Cancel all open orders
closeposition()
Close all open positions
orderstatus()
Get status of a specific order
openposition()
Get current open position quantity
Basket & Split Orders
basketorder()
Place multiple orders in a single request
splitorder()
Split large order into smaller chunks
Options Trading
optionsorder()
Place ATM/ITM/OTM option order
optionsmultiorder()
Place multi-leg option strategy
optionsymbol()
Get option symbol by offset
optionchain()
Get full option chain data
optiongreeks()
Calculate option Greeks
syntheticfuture()
Calculate synthetic future price
expiry()
Get expiry dates for symbol
Market Data
quotes()
Get real-time quotes for a symbol
multiquotes()
Get quotes for multiple symbols
depth()
Get market depth (order book)
history()
Get historical OHLCV data
intervals()
Get supported time intervals
Symbol & Search
symbol()
Get symbol details
search()
Search for symbols
instruments()
Download all instruments
Account & Portfolio
funds()
Get funds and margin details
margin()
Calculate margin requirements
orderbook()
Get order book
tradebook()
Get trade book
positionbook()
Get position book
holdings()
Get stock holdings
Utilities
holidays()
Get trading holidays for a year
timings()
Get exchange timings for a date
telegram()
Send Telegram alert message
analyzerstatus()
Get analyzer mode status
analyzertoggle()
Toggle analyze/live mode
WebSocket Streaming
connect()
Connect to WebSocket server
disconnect()
Disconnect from WebSocket
subscribeLtp()
Subscribe to LTP updates
unsubscribeLtp()
Unsubscribe from LTP
subscribeQuote()
Subscribe to Quote updates
unsubscribeQuote()
Unsubscribe from Quote
subscribeDepth()
Subscribe to Depth updates
unsubscribeDepth()
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?