Official Go SDK for OpenAlgo - the open source algorithmic trading platform.
# Create a new project directory
mkdir my-trading-app
cd my-trading-app
# Initialize Go module
go mod init my-trading-app
# Install OpenAlgo Go SDK
go get github.com/marketcalls/openalgo-go
# Clean up dependencies
go mod tidy# Clone the repository
git clone https://github.com/marketcalls/openalgo-go.git
cd openalgo-go
# Install dependencies
go mod download
# Clean up dependencies
go mod tidy
# Run the example
go run example.gopackage main
import (
"fmt"
"log"
"github.com/marketcalls/openalgo-go/openalgo"
)
func main() {
// Initialize the client
client := openalgo.NewClient(
"YOUR_API_KEY", // Your OpenAlgo API key
"http://127.0.0.1:5000", // OpenAlgo server URL
"v1", // API version
"ws://127.0.0.1:8765", // WebSocket URL (optional)
)
// Fetch account funds
funds, err := client.Funds()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Funds: %+v\n", funds)
}import "github.com/marketcalls/openalgo-go/openalgo"
fmt.Printf("Version: %s\n", openalgo.Version)PlaceOrder- Place a new orderPlaceSmartOrder- Place a smart order considering position sizeBasketOrder- Place multiple orders at onceSplitOrder- Split a large order into smaller chunksModifyOrder- Modify an existing orderCancelOrder- Cancel a specific orderCancelAllOrder- Cancel all pending ordersClosePosition- Close all open positionsOrderStatus- Get status of a specific orderOpenPosition- Get open position for a symbolOptionsOrder- Place an options order with automatic strike selection (optionalstrike_int,price,trigger_price,disclosed_quantity)OptionsMultiOrder- Place a multi-leg options order (Iron Condor, spreads, etc.)
Quotes- Get real-time quotesDepth- Get market depth (order book)History- Get historical data (optionalsource:"api"default or"db")Intervals- Get available time intervalsSymbol- Get symbol detailsSearch- Search for symbolsExpiry- Get expiry dates for derivativesInstruments- Download instruments for an exchange, or all exchanges when called with""MultiQuotes- Get quotes for multiple symbols in one callOptionChain- Get the full option chain for an underlying/expiryOptionSymbol- Resolve an option symbol from underlying + strike offset (optionalstrike_int)OptionGreeks- Calculate Delta/Gamma/Theta/Vega/Rho and IV (all params beyondsymbol/exchangeoptional:interest_rate,forward_price,underlying_symbol,underlying_exchange,expiry_time)SyntheticFuture- Calculate synthetic future price from ATM options
Funds- Get account fundsOrderBook- Get all ordersTradeBook- Get all tradesPositionBook- Get all positionsHoldings- Get holdingsMargin- Calculate margin requirements for a basket of positions (optionalPrice/TriggerPriceper position, default"0")
AnalyzerStatus- Get analyzer statusAnalyzerToggle- Toggle analyzer mode
Ping- Check API connectivityHolidays- Get market holidays for a year; omit the argument to default to the current yearTimings- Get exchange trading timings for a date; omit the argument to default to today
Telegram/TelegramWithPriority- Send a Telegram notificationWhatsApp- Send a WhatsApp message (text/image/document) via the OpenAlgo paired device
NewStrategy- Create a standalone TradingView-style webhook client (host URL + webhook ID, no API key needed)StrategyOrder- Send a BUY/SELL signal (with optional position size) to the strategy's webhook
-
Connect- Connect to WebSocket -
Disconnect- Disconnect from WebSocket -
SubscribeLTP- Subscribe to LTP updates -
UnsubscribeLTP- Unsubscribe from LTP -
SubscribeQuote- Subscribe to quote updates -
UnsubscribeQuote- Unsubscribe from quotes -
SubscribeDepth- Subscribe to market depth -
UnsubscribeDepth- Unsubscribe from depth -
GetLTP(exchange, symbol string)- Read the latest cached LTP snapshot(s); pass""for either argument to skip that filter -
GetQuotes(exchange, symbol string)- Read the latest cached Quote snapshot(s), same filtering rules -
GetDepth(exchange, symbol string)- Read the latest cached Market Depth snapshot(s) (5-levelbuyBook/sellBook), same filtering rulesThese three read from a local cache that is populated automatically as WebSocket market data messages arrive (mirroring the Python SDK's
ltp_data/quotes_data/depth_data) - no callback wiring required if you just want the latest snapshot.
- Update
example.gowith your API key:
client := openalgo.NewClient(
"YOUR_API_KEY", // Replace with your actual API key
"http://127.0.0.1:5000", // Your OpenAlgo server URL
"v1", // API version
"ws://127.0.0.1:8765", // WebSocket URL (optional)
)- Run the example:
go run example.goAll functions match the Python SDK exactly with the same mandatory and optional parameters. Optional parameters are passed as a map[string]interface{} in Go.
Mandatory:
- strategy (string)
- symbol (string)
- action (string) - BUY/SELL
- exchange (string) - NSE/BSE/NFO/MCX/CDS
- price_type (string) - MARKET/LIMIT/SL/SL-M
- product (string) - MIS/CNC/NRML
- quantity (string/int/float64)
Optional:
- price (float64) - Required for LIMIT orders
- trigger_price (float64) - Required for SL orders
- disclosed_quantity (string)
greeks, err := client.OptionGreeks("NIFTY02DEC2526000CE", "NFO", map[string]interface{}{
"interest_rate": 6.5, // optional, defaults to 0 server-side
"forward_price": 26350, // optional, skips underlying LTP fetch
"underlying_symbol": "NIFTY30DEC25FUT",
"underlying_exchange": "NFO",
"expiry_time": "19:00", // optional, needed for MCX
})All parameters after symbol/exchange are optional - omit the map entirely for the simplest case: client.OptionGreeks("NIFTY02DEC2526000CE", "NFO").
// strike_int is DEPRECATED (matches the Python SDK) but still supported
symbolInfo, err := client.OptionSymbol("NIFTY", "NSE_INDEX", "28OCT25", "ATM", "CE", map[string]interface{}{
"strike_int": 50,
})
orderResp, err := client.OptionsOrder(
"test_strategy", "NIFTY", "NSE_INDEX", "28NOV24", "ATM", "CE", "BUY",
75, "LIMIT", "MIS", 0,
map[string]interface{}{
"strike_int": 50,
"price": "50.0",
},
)Price and TriggerPrice on MarginPosition are optional and default to "0" (set Price for LIMIT orders, TriggerPrice for SL/SL-M orders):
resp, err := client.Margin([]openalgo.MarginPosition{
{
Symbol: "NIFTY30DEC2526000CE", Exchange: "NFO", Action: "SELL",
Product: "NRML", PriceType: "LIMIT", Quantity: "75",
Price: "150.75",
},
})// source is optional: "api" (default) or "db" (OpenAlgo DuckDB/Historify)
hist, err := client.History("SBIN", "NSE", "5m", "2025-04-01", "2025-04-08", "db")
// Instruments("") downloads and combines instruments from every supported exchange
allInstruments, err := client.Instruments("")
nseOnly, err := client.Instruments("NSE")// Both default client-side when omitted: current year / today
holidays, err := client.Holidays() // current year
holidays2025, err := client.Holidays(2025)
timings, err := client.Timings() // today
timingsOn, err := client.Timings("2025-12-25")// Send to self (the paired device's own number)
client.WhatsApp("Build #482 deployed. P&L: +1.2%")
// Send to a single number with an image
client.WhatsApp("NIFTY end-of-day chart", map[string]interface{}{
"to": "919876543210",
"image": "/srv/charts/nifty_eod.png",
})
// Fire-and-forget broadcast (up to 5 numbers) for time-critical alerts
client.WhatsApp("Stop-loss hit on BANKNIFTY!", map[string]interface{}{
"to": []string{"919876543210", "919812345678"},
"wait_for_delivery": false,
})Strategy is a standalone client (separate from Client) for posting TradingView-style
signals to an OpenAlgo strategy webhook - it only needs the server host and the
strategy's webhook ID, not an API key:
strategy := openalgo.NewStrategy("http://127.0.0.1:5000", "your-webhook-id")
// The strategy mode (LONG_ONLY, SHORT_ONLY, BOTH) is configured in OpenAlgo.
// position_size is required for BOTH mode; pass nil to omit it otherwise.
resp, err := strategy.StrategyOrder("RELIANCE", "BUY", nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Strategy order response: %+v\n", resp)client.Connect()
client.SubscribeLTP([]openalgo.Instrument{{Exchange: "NSE", Symbol: "RELIANCE"}}, nil)
client.SubscribeQuote([]openalgo.Instrument{{Exchange: "NSE", Symbol: "RELIANCE"}}, nil)
client.SubscribeDepth([]openalgo.Instrument{{Exchange: "NSE", Symbol: "RELIANCE"}}, nil)
// Later, read the latest cached snapshots without wiring up a callback:
ltpSnapshot := client.GetLTP("NSE", "RELIANCE") // {"ltp": {"NSE": {"RELIANCE": {"timestamp": ..., "ltp": ...}}}}
allLTP := client.GetLTP("", "") // every cached LTP symbol
quoteSnapshot := client.GetQuotes("NSE", "RELIANCE") // {"quote": {"NSE": {"RELIANCE": {"open": ..., "high": ..., "low": ..., "close": ..., "ltp": ..., "volume": ...}}}}
allQuotes := client.GetQuotes("", "") // every cached quote symbol
depthSnapshot := client.GetDepth("NSE", "RELIANCE") // {"depth": {"NSE": {"RELIANCE": {"ltp": ..., "buyBook": {"1": {...}, ...}, "sellBook": {"1": {...}, ...}}}}}
allDepth := client.GetDepth("", "") // every cached depth symbolThis project is licensed under the MIT License - see the LICENSE file for details.