dbn_live

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DATABENTO_VERSION = "0.18.1"

	DATABENTO_API_ENV_KEY    = "DATABENTO_API_KEY"
	DATABENTO_CLIENT_ENV_KEY = "DATABENTO_CLIENT"

	LIVE_HOST_SUFFIX = ".lsg.databento.com"
	LIVE_API_PORT    = 13000

	SYSTEM_MSG_SIZE_V1 = 64
	SYSTEM_MSG_SIZE_V2 = 303

	ERROR_ERR_SIZE_V1 = 64
	ERROR_ERR_SIZE_V2 = 302

	BUCKET_ID_LENGTH = 5

	API_VERSION     = 0
	API_VERSION_STR = "0"
	API_KEY_LENGTH  = 32

	MAX_STR_LENGTH = 24 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationRequestMsg

type AuthenticationRequestMsg struct {
	Auth     string       // key: auth
	Dataset  string       // key: dataset
	Encoding dbn.Encoding // key: encoding
	Details  string       // key: details
	TsOut    bool         // key: ts_out
	Client   string       // key: client
}

AuthenticationRequestMsg is an authentication request is sent to the gateway after a challenge response is received. This is required to authenticate a user.

func NewAuthenticationRequestMsg

func NewAuthenticationRequestMsg() AuthenticationRequestMsg

NewAuthenticationRequestMsg parses a control message and returns a AuthenticationRequestMsg Returns nil if required fields are missing.

func (*AuthenticationRequestMsg) Encode

func (m *AuthenticationRequestMsg) Encode() []byte

Encode converts AuthenticationRequestMsg to its line protocol representation.

type AuthenticationResponseMsg

type AuthenticationResponseMsg struct {
	Success   string // key: success
	Error     string // key: error
	SessionID string // key: session_id
}

AuthenticationResponseMsg is an authentication response is sent by the gateway after a valid authentication request is sent to the gateway.

func NewAuthenticationResponseMsgFromBytes

func NewAuthenticationResponseMsgFromBytes(b []byte) *AuthenticationResponseMsg

NewAuthenticationResponseMsgFromBytes parses a control message and returns a AuthenticationResponseMsg Returns nil if required fields are missing.

type ChallengeRequestMsg

type ChallengeRequestMsg struct {
	Cram string // key: cram
}

ChallengeRequestMsg is sent by the gateway upon connection.

func NewChallengeRequestMsgFromBytes

func NewChallengeRequestMsgFromBytes(b []byte) *ChallengeRequestMsg

NewChallengeRequestMsgFromBytes parses a control message and returns a ChallengeRequestMsg Returns nil if required fields are missing.

type ErrorMsgV1

type ErrorMsgV1 struct {
	Err [ERROR_ERR_SIZE_V1]byte `json:"err"` // The error message
}

type ErrorMsgV2

type ErrorMsgV2 struct {
	Err    [ERROR_ERR_SIZE_V2]byte `json:"err"`     // The error message
	Code   uint8                   `json:"code"`    // Reserved for future use
	IsLast uint8                   `json:"is_last"` // Boolean flag indicating whther this is the last in a series of error records.
}

type GreetingMsg

type GreetingMsg struct {
	LsgVersion string // key: lsg_version
}

GreetingMsg is a greeting message sent by the gateway upon connection.

func NewGreetingMsgFromBytes

func NewGreetingMsgFromBytes(b []byte) *GreetingMsg

NewGreetingMsgFromBytes parses a control message and returns a GreetingMsg Returns nil if required fields are missing.

type LiveClient

type LiveClient struct {
	// contains filtered or unexported fields
}

LiveClient interfaces with Databento's real-time and intraday replay market data API. This client provides a blocking API for getting the next record. Unlike Historical, each instance of LiveClient is associated with a particular dataset.

func NewLiveClient

func NewLiveClient(config LiveConfig) (*LiveClient, error)

NewLiveClient takes a LiveConfig, creates a LiveClient and tries to connect. Returns an error if connection fails.

func (*LiveClient) Authenticate

func (c *LiveClient) Authenticate(apiKey string) (string, error)

Authenticate performs read/write with the server to authenticate. Returns a sessionID or an error.

func (*LiveClient) GetConfig

func (c *LiveClient) GetConfig() LiveConfig

GetConfig returns the LiveConfig used to create the LiveClient.

func (*LiveClient) GetDbnScanner

func (c *LiveClient) GetDbnScanner() *dbn.DbnScanner

GetDbnScanner returns the DbnScanner Returns nil if the encoding is JSON

func (*LiveClient) GetGateway

func (c *LiveClient) GetGateway() string

GetGateway returns the gateway host for connection.

func (*LiveClient) GetJsonScanner added in v0.1.0

func (c *LiveClient) GetJsonScanner() *dbn.JsonScanner

GetJsonScanner returns a JsonScanner Returns nil if the encoding is DBN

func (*LiveClient) GetLsgVersion

func (c *LiveClient) GetLsgVersion() string

GetLsgVersion returns the version of the LSG server

func (*LiveClient) GetPort

func (c *LiveClient) GetPort() uint16

GetPort returns the port for connection.

func (*LiveClient) GetSessionID

func (c *LiveClient) GetSessionID() string

GetSessionID returns the session ID

func (*LiveClient) Start

func (c *LiveClient) Start() error

Notifies the gateway to start sending messages for all subscriptions. This method should only be called once per instance.

func (*LiveClient) Stop

func (c *LiveClient) Stop() error

Stops the session with the gateway. Once stopped, the session cannot be restarted.

func (*LiveClient) Subscribe

func (c *LiveClient) Subscribe(sub SubscriptionRequestMsg) error

Subscribe adds a new subscription for a set of symbols with a given schema and stype. Returns an error if any. A single client instance supports multiple subscriptions. Note there is no unsubscribe method. Subscriptions end when the client disconnects with Stop or the LiveClient instance is garbage collected.

type LiveConfig

type LiveConfig struct {
	Logger               *slog.Logger
	ApiKey               string
	Dataset              string
	Client               string
	Encoding             dbn.Encoding // nil mean Encoding_Dbn
	SendTsOut            bool
	VersionUpgradePolicy dbn.VersionUpgradePolicy
	Verbose              bool
}

func (*LiveConfig) SetFromEnv added in v0.0.13

func (c *LiveConfig) SetFromEnv() error

SetFromEnv fills in the LiveConfig from environment variables. `DATABENTO_API_KEY` holds the Databento API key. `DATABENTO_CLIENT` holds the Client name.

type SessionStartMsg

type SessionStartMsg struct {
	StartSession string // key: start_session
}

A session start message is sent to the gateway upon request from the client.

func (*SessionStartMsg) Encode

func (m *SessionStartMsg) Encode() []byte

Encode converts SessionStartMsg to its line protocol representation.

type SubscriptionRequestMsg

type SubscriptionRequestMsg struct {
	Schema   string    // key: schema
	StypeIn  dbn.SType // key: stype_in
	Symbols  []string  // key: symbols (comma separated)
	Start    time.Time // key: time (nanoseconds since epoch)
	Snapshot bool      // key: snapshot (int)
}

A subscription request is sent to the gateway upon request from the client.

func (*SubscriptionRequestMsg) Encode

func (m *SubscriptionRequestMsg) Encode() []byte

Encode converts SubscriptionRequestMsg to its line protocol representation.

type SystemMsgV1

type SystemMsgV1 struct {
	Msg [SYSTEM_MSG_SIZE_V1]byte `json:"msg"` // The message from the gateway
}

type SystemMsgV2

type SystemMsgV2 struct {
	Msg  [SYSTEM_MSG_SIZE_V2]byte `json:"msg"`  // The message from the gateway
	Code uint8                    `json:"code"` // Reserved for future use
}

Jump to

Keyboard shortcuts

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