tradingview

package module
v0.0.0-...-440b9f3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

README

TradingView Library

  • tradingview-lib is a Go based library that sends and receives messages from TradingView using websockets. To fully understand and utilise this project, we suggest understanding how TradingView receives and sends data via its websockets (specifically what it is sending/receiving)

Installation

  • go get github.com/VictorVictini/tradingview-lib
  • import github.com/VictorVictini/tradingview-lib

Features

  • Open a connection to TradingView to send/receive messages such as:
    • Receive stock data
      • Symbol, High, Low, Open, Close, Volume and seconds elapsed from Jan 1st 1970 (Unix time standard)
    • Add/Remove real-time tracking of stock changes
      • Will output the most recent change to a stock. Will output <nil> for entries that have no change.
      • Choose the stock via AddRealtimeSymbols(), RemoveRealtimeSymbols() to stop receiving data about the stock.
    • Get historical stock data from a specific point in time.
      • You can decide the stock, date, timeframe between each candle and session type using the GetHistory() function.
      • To receive further historical data, you can invoke RequestMoreCandles() with a specific count to view even more data for the current GetHistory() options.
    • Change Timezone
      • SwitchTimezone() allows accurate assignment of stock data to specific times.
    • Error handling for most functions that handle data transfer between TradingView and this library
      • Keep in mind the program will perform unexpectedly if an invalid input is received into these functions.

Documentation

Index

Constants

View Source
const DEFAULT_INITIAL_HISTORY_CANDLES = 10

default history initial candles amount if not specified

View Source
const HISTORY_TOKEN = "sds_1"
View Source
const SEPARATOR = "~m~"

random constants

View Source
const TOKEN_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789"
View Source
const TOKEN_LENGTH = 12

constants for token creation

View Source
const TV_ORIGIN_URL = "https://www.tradingview.com"
View Source
const TV_URL = "wss://data.tradingview.com/socket.io/websocket"

URL data for initialisation

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Channels Channels
	// contains filtered or unexported fields
}

Handles data associated with an instance of the websocket

func (*API) AddRealtimeSymbols

func (api *API) AddRealtimeSymbols(symbols []string) error

Retrieves real-time data for the given stocks/symbols which is then provided to the read channel

func (*API) GetHistory

func (api *API) GetHistory(symbol string, timeframe Timeframe, startFrom time.Time, sessionType SessionType) error

Retrieves 10 candles from history for the provided symbol/stock Provides candles for the requested timeframe

sessionType is only used once per symbol. startFrom is used only when GetHistory is first invoked, never after. (pass time.Time{} for current time)

func (*API) OpenConnection

func (api *API) OpenConnection(settings map[string]interface{}) error

Creates an active websocket connection (settings param can be nil if you want to use default settings)

func (*API) RemoveRealtimeSymbols

func (api *API) RemoveRealtimeSymbols(symbols []string) error

func (*API) RequestMoreData

func (api *API) RequestMoreData(candleCount int) error

Retrieves more data of the most recently loaded symbol, requires GetHistory() to have been used before it

func (*API) SwitchTimezone

func (api *API) SwitchTimezone(timezone string) error

Switches the timezone the data is viewed on for the current session

type Channels

type Channels struct {
	Read chan map[string]interface{}

	Error chan error // receives errors that occurred in read/write threads
	// contains filtered or unexported fields
}

Handles data transferring between threads as well as the channels the user will be able to utilise

type SessionType

type SessionType string

session data

const (
	Regular  SessionType = "regular"
	Extended SessionType = "extended"
)

type Timeframe

type Timeframe string
const (
	OneMinute        Timeframe = "1"
	ThreeMinutes     Timeframe = "3"
	FiveMinutes      Timeframe = "5"
	FifteenMinutes   Timeframe = "15"
	ThirtyMinutes    Timeframe = "30"
	FortyFiveMinutes Timeframe = "45"

	OneHour    Timeframe = "60"
	TwoHours   Timeframe = "120"
	ThreeHours Timeframe = "180"
	FourHours  Timeframe = "240"

	OneDay       Timeframe = "1D"
	OneWeek      Timeframe = "1W"
	OneMonth     Timeframe = "1M"
	ThreeMonths  Timeframe = "3M"
	SixMonths    Timeframe = "6M"
	TwelveMonths Timeframe = "12M"
)

timeframe data

Jump to

Keyboard shortcuts

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