ODINMarketFeed

package module
v0.0.0-...-799c0c8 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 13 Imported by: 0

README

ODIN Market Feed Client (Go Library)

A robust Go Library for connecting to ODIN Market Feed WebSocket API. This library provides real-time market data streaming with built-in compression, fragmentation handling, and subscription management.

Features

  • 🚀 WebSocket Connectivity - Reliable WebSocket connection with automatic reconnection
  • 📦 Compression Support - Built-in ZLIB compression/decompression
  • 🔀 Message Fragmentation - Automatic handling of fragmented messages
  • 📊 Market Data Subscriptions - Subscribe to ChannelNum, SnapQuote, and BestFive feeds
  • ❤️ Heartbeat Management - Automatic heartbeat to keep connection alive
  • 🔒 Thread-Safe - Concurrent-safe operations with mutex locks
  • High Performance - Efficient binary data parsing

Installation

go get github.com/SIPL-Dev/go-odinmarketfeedclient

Quick Start

package main

import (
    "fmt"
    "time"
    
    odin "github.com/SIPL-Dev/go-odinmarketfeedclient"
)

func main() {
    // Create a new client
    client := odin.NewODINMarketFeedClient()
    
    // Set up event handlers
    client.OnOpen = func() {
        fmt.Println("✓ Connected to ODIN Market Feed")
    }
    
    client.OnMessage = func(message string) {
        fmt.Println("📨 Message:", message)
    }
    
    client.OnError = func(err string) {
        fmt.Println("❌ Error:", err)
    }
    
    client.OnClose = func(code int, reason string) {
        fmt.Printf("🔌 Connection closed: %d - %s\n", code, reason)
    }
    
    // Connect to the server
    err := client.Connect("your-host.com", 8080, true, "your_user_id")
    if err != nil {
        panic(err)
    }
    
    // Subscribe to market data
    client.SubscribeLTPTouchline("token1,token2", 1)
    
    // Keep connection alive
    time.Sleep(60 * time.Second)
    
    // Disconnect when done
    client.Disconnect()
}

API Reference

Client Creation
NewODINMarketFeedClient() *ODINMarketFeedClient

Creates a new instance of the ODIN Market Feed client.

client := odin.ODINMarketFeedClient()
Connection Management
Connect(host string, port int, ssl bool, userID string) error

Establishes a WebSocket connection to the ODIN Market Feed server.

Parameters:

  • host - Server hostname (e.g., "market.example.com")
  • port - Server port (e.g., 8080)
  • ssl - Use secure WebSocket (true for wss://, false for ws://)
  • userID - Your user identifier

Example:

err := client.Connect("market.example.com", 8080, true, "USER123")
Disconnect()

Gracefully closes the WebSocket connection.

client.Disconnect()

Requirements

  • Go 1.21 or higher
  • github.com/gorilla/websocket v1.5.1

Examples

See the examples directory for more detailed usage examples:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For issues, questions, or contributions, please open an issue on GitHub.

Disclaimer

This SDK is provided as-is. Please ensure you comply with ODIN Market Feed's terms of service and usage policies. The authors are not responsible for any financial losses or damages resulting from the use of this library.

Changelog

v1.0.0 (Initial Release)
  • WebSocket connectivity with SSL support
  • ZLIB compression/decompression
  • Message fragmentation handling
  • ChannelNum, SnapQuote, and BestFive subscriptions
  • Automatic heartbeat management
  • Thread-safe operations

Documentation

Overview

Package ODINMarketFeed provides a Go Library for connecting to ODIN Market Feed WebSocket API. This library enables real-time market data streaming with built-in compression, fragmentation handling, and subscription management for trading applications.

Features:

  • WebSocket connectivity with SSL/TLS support
  • ZLIB compression and decompression
  • Automatic message fragmentation handling
  • Multiple subscription types (ChannelNum, SnapQuote, BestFive)
  • Heartbeat mechanism for connection maintenance
  • Thread-safe operations
  • Binary data parsing for market data

Basic Usage:

client := odinclient.NewODINMarketFeedClient()

client.OnOpen = func() {
    fmt.Println("Connected")
    client.SubscribeChannelNum("1234,5678", 1)
}

client.OnMessage = func(message string) {
    fmt.Println("Received:", message)
}

client.Connect("host.com", 8080, true, "user_id")
defer client.Disconnect()

For detailed examples and documentation, visit: https://github.com/SIPL-Dev/go-odinmarketfeedclient

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressionStatus

type CompressionStatus int

CompressionStatus represents compression state

const (
	CompressionON CompressionStatus = iota
	CompressionOFF
)

type FragmentationHandler

type FragmentationHandler struct {
	UnCompressMsgLength int
	HeaderLength        int

	IsUncompress bool
	// contains filtered or unexported fields
}

FragmentationHandler handles message fragmentation

func NewFragmentationHandler

func NewFragmentationHandler() *FragmentationHandler

NewFragmentationHandler creates a new FragmentationHandler

func (*FragmentationHandler) Defragment

func (fh *FragmentationHandler) Defragment(data []byte) ([][]byte, error)

Defragment defragments received data

func (*FragmentationHandler) FragmentData

func (fh *FragmentationHandler) FragmentData(data []byte) ([]byte, error)

FragmentData fragments and compresses data for sending

func (*FragmentationHandler) GetMessageLength

func (fh *FragmentationHandler) GetMessageLength(messageData []byte) int

GetMessageLength extracts the message length from the message data You'll need to implement this based on your protocol

type MarketData

type MarketData struct {
	MktSegID       uint32
	Token          uint32
	LUT            uint32
	LTP            uint32
	ClosePrice     uint32
	DecimalLocator uint32
}

MarketData represents market data structure

type ODINMarketFeedClient

type ODINMarketFeedClient struct {
	OnOpen    func()
	OnMessage func(message string)
	OnError   func(err string)
	OnClose   func(code int, reason string)
	// contains filtered or unexported fields
}

ODINMarketFeedClient represents the WebSocket client

func NewODINMarketFeedClient

func NewODINMarketFeedClient() *ODINMarketFeedClient

NewODINMarketFeedClient creates a new ODINMarketFeedClient instance

func (*ODINMarketFeedClient) Connect

func (tw *ODINMarketFeedClient) Connect(host string, port int, useSSL bool, userID string, apiKey string) error

Connect connects to the WebSocket server

func (*ODINMarketFeedClient) Disconnect

func (tw *ODINMarketFeedClient) Disconnect() error

Disconnect disconnects from the WebSocket server

func (*ODINMarketFeedClient) Dispose

func (tw *ODINMarketFeedClient) Dispose()

Dispose releases resources

func (*ODINMarketFeedClient) SendMessage

func (tw *ODINMarketFeedClient) SendMessage(message string) error

SendMessage sends a message to the WebSocket server

func (*ODINMarketFeedClient) SetCompression

func (tw *ODINMarketFeedClient) SetCompression(enabled bool)

SetCompression enables or disables compression

func (*ODINMarketFeedClient) SubscribeBestFive

func (tw *ODINMarketFeedClient) SubscribeBestFive(token string, marketSegmentID int) error

SubscribeBestFive subscribes to Market Depth (Best Five) for the provided token and market segment

func (*ODINMarketFeedClient) SubscribeLTPTouchline

func (c *ODINMarketFeedClient) SubscribeLTPTouchline(tokenList []string) error

SubscribeLTPTouchline sends LTP touchline request for market data tokenList: List of tokens to subscribe (e.g., "1_22", "1_2885")

func (*ODINMarketFeedClient) SubscribePauseResume

func (c *ODINMarketFeedClient) SubscribePauseResume(isPause bool) error

SubscribePauseResume pauses or resumes the broadcast subscription isPause: true to pause, false to resume

func (*ODINMarketFeedClient) SubscribeTouchline

func (tw *ODINMarketFeedClient) SubscribeTouchline(tokenList []string, responseType string, ltpChangeOnly bool) error

SubscribeTouchline sends touchline request for market data tokenList: List of tokens to subscribe (e.g., "1_22", "1_2885") responseType: "1" = Touchline with fixed length native data, "0" = Normal touchline ltpChangeOnly: Send response on LTP change only if true

func (*ODINMarketFeedClient) SubscribeTouchlineOld

func (tw *ODINMarketFeedClient) SubscribeTouchlineOld(tokenList []string) error

SubscribeTouchline subscribes to touchline for the provided tokens

func (*ODINMarketFeedClient) UnsubscribeBestFive

func (tw *ODINMarketFeedClient) UnsubscribeBestFive(token string, marketSegmentID int) error

UnsubscribeBestFive unsubscribes from Market Depth (Best Five) for the provided token and market segment

func (*ODINMarketFeedClient) UnsubscribeLTPTouchline

func (c *ODINMarketFeedClient) UnsubscribeLTPTouchline(tokenList []string) error

UnsubscribeLTPTouchline unsubscribes from LTP touchline tokens

func (*ODINMarketFeedClient) UnsubscribeTouchline

func (tw *ODINMarketFeedClient) UnsubscribeTouchline(tokenList []string) error

UnsubscribeTouchline unsubscribes from touchline for the provided tokens

type ZLIBCompressor

type ZLIBCompressor struct{}

ZLIBCompressor handles ZLIB compression/decompression

func (*ZLIBCompressor) Compress

func (z *ZLIBCompressor) Compress(data []byte) ([]byte, error)

Compress compresses data using ZLIB

func (*ZLIBCompressor) Uncompress

func (z *ZLIBCompressor) Uncompress(data []byte) ([]byte, error)

Uncompress decompresses data using ZLIB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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