jainam

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 15 Imported by: 0

README

Jainam API Go

Go CI Go Reference

A fast, reusable Go SDK for the Jainam ProTrade Open API v2.

Developed by Sreenivasulu Malkari.

Features

  • Jainam SSO URL, SHA-256 checksum, and session exchange
  • Profile, funds, holdings, and positions
  • Orders, history, trades, margin, modification, cancellation, and square-off
  • Historical candles and contract-master downloads
  • Market tick/depth and order-status WebSockets
  • Context-aware HTTP requests and structured API errors
  • Explicit confirmation guard for live trading mutations
  • Tests, go vet, formatting checks, examples, and CI

Install

go get github.com/malkarisreenivasulu/jainam-api-go@v0.1.0

First read-only request

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    jainam "github.com/malkarisreenivasulu/jainam-api-go"
)

func main() {
    api := jainam.New(
        os.Getenv("JAINAM_USER_SESSION"),
        os.Getenv("JAINAM_USER_ID"),
    )

    profile, err := api.Profile(context.Background())
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(profile)
}

Follow the Go beginner guide and API reference. Always resolve instruments from the current contract master before creating an order.

Open a Jainam account

These are referral links. The developer may receive a benefit if you use them. Verify current fees, terms, and features directly with Jainam.

Disclaimer

This project and documentation are not investment advice. Trading and automated trading involve risk and can result in financial loss. The confirmation argument helps prevent accidental calls; it is not a complete risk-management system.

Developed by Sreenivasulu Malkari and released under the MIT License. Jainam and ProTrade are trademarks of their respective owner.

Documentation

Overview

Package jainam provides Jainam API Go, developed by Sreenivasulu Malkari.

Index

Constants

View Source
const DefaultBaseURL = "https://protrade.jainam.in/"

Variables

This section is empty.

Functions

func Checksum

func Checksum(userID, authCode, apiSecret string) string

func DoubleSHA256

func DoubleSHA256(v string) string

func LoginURL

func LoginURL(appCode string) string

func ParseContractCSV

func ParseContractCSV(r io.Reader) ([]map[string]string, error)

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Payload    json.RawMessage
}

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL, UserSession, UserID string
	HTTPClient                   *http.Client
}

func New

func New(userSession, userID string, opts ...Option) *Client

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, id string, confirmed bool) (map[string]any, error)

func (*Client) ContractURL

func (c *Client) ContractURL(exchange, format string) (string, error)

func (*Client) CreateOrderWSToken

func (c *Client) CreateOrderWSToken(ctx context.Context) (map[string]any, error)

func (*Client) CreateWSSession

func (c *Client) CreateWSSession(ctx context.Context) (map[string]any, error)

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body any, result any) error

func (*Client) DownloadContracts

func (c *Client) DownloadContracts(ctx context.Context, exchange, format, destination string) error

func (*Client) ExchangeAuthCode

func (c *Client) ExchangeAuthCode(ctx context.Context, userID, authCode, secret string) (map[string]any, error)

func (*Client) Funds

func (c *Client) Funds(ctx context.Context) (map[string]any, error)

func (*Client) HistoricalData

func (c *Client) HistoricalData(ctx context.Context, token, resolution string, from, to int64, exchange string) (map[string]any, error)

func (*Client) Holdings

func (c *Client) Holdings(ctx context.Context, product string) (map[string]any, error)

func (*Client) InvalidateWSSession

func (c *Client) InvalidateWSSession(ctx context.Context) (map[string]any, error)

func (*Client) ModifyOrder

func (c *Client) ModifyOrder(ctx context.Context, id string, changes map[string]any, confirmed bool) (map[string]any, error)

func (*Client) OrderBook

func (c *Client) OrderBook(ctx context.Context) (map[string]any, error)

func (*Client) OrderHistory

func (c *Client) OrderHistory(ctx context.Context, id string) (map[string]any, error)

func (*Client) OrderMargin

func (c *Client) OrderMargin(ctx context.Context, o Order) (map[string]any, error)

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(ctx context.Context, o Order, confirmed bool) (map[string]any, error)

func (*Client) Positions

func (c *Client) Positions(ctx context.Context) (map[string]any, error)

func (*Client) Profile

func (c *Client) Profile(ctx context.Context) (map[string]any, error)

func (*Client) SquareOff

func (c *Client) SquareOff(ctx context.Context, o Order, confirmed bool) (map[string]any, error)

func (*Client) TradeBook

func (c *Client) TradeBook(ctx context.Context) (map[string]any, error)

type MarketTicker

type MarketTicker struct {
	UserID, UserSession string
	Conn                *websocket.Conn
	OnMessage           MessageHandler
	// contains filtered or unexported fields
}

func (*MarketTicker) Close

func (t *MarketTicker) Close() error

func (*MarketTicker) Connect

func (t *MarketTicker) Connect() error

func (*MarketTicker) Subscribe

func (t *MarketTicker) Subscribe(tokens [][2]string, depth bool) error

func (*MarketTicker) Unsubscribe

func (t *MarketTicker) Unsubscribe(tokens [][2]string, depth bool) error

type MessageHandler

type MessageHandler func(map[string]any)

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(v string) Option

func WithHTTPClient

func WithHTTPClient(v *http.Client) Option

type Order

type Order struct {
	Exchange                string `json:"exchange"`
	InstrumentID            string `json:"instrumentId"`
	TransactionType         string `json:"transactionType"`
	Quantity                int    `json:"quantity"`
	Product                 string `json:"product"`
	OrderComplexity         string `json:"orderComplexity"`
	OrderType               string `json:"orderType"`
	Price                   any    `json:"price"`
	Validity                string `json:"validity"`
	SLTriggerPrice          any    `json:"slTriggerPrice"`
	TrailingSLAmount        any    `json:"trailingSlAmount,omitempty"`
	APIOrderSource          string `json:"apiOrderSource,omitempty"`
	AlgoID                  string `json:"algoId,omitempty"`
	MarketProtectionPercent any    `json:"marketProtectionPercent,omitempty"`
	DisclosedQuantity       any    `json:"disclosedQuantity,omitempty"`
	OrderTag                string `json:"orderTag,omitempty"`
}

type OrderTicker

type OrderTicker struct {
	UserID, OrderToken string
	Conn               *websocket.Conn
	OnMessage          MessageHandler
	// contains filtered or unexported fields
}

func (*OrderTicker) Close

func (t *OrderTicker) Close() error

func (*OrderTicker) Connect

func (t *OrderTicker) Connect() error

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL