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.go
package 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 symbol
Quotes
- Get real-time quotesDepth
- Get market depth (order book)History
- Get historical dataIntervals
- Get available time intervalsSymbol
- Get symbol detailsSearch
- Search for symbolsExpiry
- Get expiry dates for derivatives
Funds
- Get account fundsOrderBook
- Get all ordersTradeBook
- Get all tradesPositionBook
- Get all positionsHoldings
- Get holdings
AnalyzerStatus
- Get analyzer statusAnalyzerToggle
- Toggle analyzer mode
Connect
- Connect to WebSocketDisconnect
- Disconnect from WebSocketSubscribeLTP
- Subscribe to LTP updatesUnsubscribeLTP
- Unsubscribe from LTPSubscribeQuote
- Subscribe to quote updatesUnsubscribeQuote
- Unsubscribe from quotesSubscribeDepth
- Subscribe to market depthUnsubscribeDepth
- Unsubscribe from depth
- Update
example.go
with 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.go
All 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)
This project is licensed under the MIT License - see the LICENSE file for details.