GO

Go SDK for OpenAlgo

To install the OpenAlgo Go library, use go get:

go get github.com/marketcalls/openalgo-go

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

First, import the OpenAlgo package and initialize it with your API key:

package main

import (
    "github.com/marketcalls/openalgo-go/openalgo"
    "encoding/json"
)

// Replace 'your_api_key_here' with your actual API key
// Specify the host URL with your hosted domain or ngrok domain.
// If running locally then use the default host value.
// Parameters: apiKey, host, version, websocketURL (optional)
client := openalgo.NewClient(
    "your_api_key_here",
    "http://127.0.0.1:5000",
    "v1",                    // API version
    "ws://127.0.0.1:8765",   // WebSocket URL (optional)
)

Check OpenAlgo Version

Complete List of Implemented Functions

Order Management

  • PlaceOrder - Place a new order

  • PlaceSmartOrder - Place a smart order with position sizing

  • BasketOrder - Place multiple orders at once

  • SplitOrder - Split large orders into smaller chunks

  • ModifyOrder - Modify an existing order

  • CancelOrder - Cancel a specific order

  • CancelAllOrder - Cancel all pending orders

  • ClosePosition - Close all open positions

  • OrderStatus - Get order status

  • OpenPosition - Get open position for a symbol

Market Data

  • Quotes - Get real-time quotes

  • Depth - Get market depth

  • History - Get historical data

  • Intervals - Get available time intervals

  • Symbol - Get symbol information

  • Search - Search for symbols

  • Expiry - Get expiry dates

Account Information

  • Funds - Get account funds

  • OrderBook - Get all orders

  • TradeBook - Get all trades

  • PositionBook - Get all positions

  • Holdings - Get holdings

Utility

  • Ping - Check API connectivity

  • AnalyzerStatus - Get analyzer status

  • AnalyzerToggle - Toggle analyzer mode (requires boolean: true to enable, false to disable)

WebSocket Streaming

  • 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

Examples

Please refer to the documentation on order constants, and consult the API reference for details on optional parameters

Ping Example

Check API connectivity:

Ping Response

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

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

Depth Example

Depth Response

History Example

History Response

Intervals Example

Intervals response

Symbol Example

Symbols Response

Search Example

Search Response

Expiry Example

Expiry Response

Funds Example

Funds Response

OrderBook Example

TradeBook Example

TradeBook Response

PositionBook Example

PositionBook Response

Holdings Example

Holdings Response

Analyzer Status Example

Analyzer Status Response

Analyzer Toggle Example

Analyzer Toggle Response

LTP Data (Streaming Websocket)

Quotes (Streaming Websocket)

Depth (Streaming Websocket)

Last updated

Was this helpful?