For the complete documentation index, see llms.txt. This page is also available as Markdown.

GO

Go

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 the client with your API key:

package main

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

func main() {
    // Replace 'your_api_key_here' with your actual API key
    // Default host is http://127.0.0.1:5000
    client := openalgo.NewClient("your_api_key_here", "http://127.0.0.1:5000")

    // Or with an explicit API version and WebSocket URL:
    // client := openalgo.NewClient("your_api_key_here", "http://127.0.0.1:5000", "v1", "ws://127.0.0.1:8765")
    _ = client
}

NewClient takes the API key and host, then optional strings and integers. Version defaults to v1 and the WebSocket port to 8765, so the WebSocket URL is derived from the host as ws://127.0.0.1:8765 unless you pass one explicitly.

Check OpenAlgo Version

Examples

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

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

OptionsMultiOrder Example

To place Iron Condor options order (Same Expiry)

Place OptionsMultiOrder Response

To place Diagonal Spread options order (Different Expiry)

Place 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 an expiry, omit the strikeCount 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:

The Go SDK currently POSTs to this endpoint, which the server answers with HTTP 405. Until that is fixed, fetch the instrument master with a plain GET.

Instruments Response

Telegram Alert Example

Telegram Alert Response

With priority:

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

Ping Example

Ping confirms the API key is valid and reports the connected broker.

Ping Response

Endpoints not wrapped by the SDK

The Go SDK does not expose helpers for the GTT endpoints or multioptiongreeks. 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.

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.

LTP Data (Streaming WebSocket)

Quotes (Streaming WebSocket)

Depth (Streaming WebSocket)

Order Updates (Streaming WebSocket)

The same proxy on port 8765 also carries account-scoped order updates. The Go 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.

Last updated