How TvDatafeedLive works
mainTvDatafeedLive is a subclass of TvDatafeed that provides a live data feed feature. It uses a Seis (symbol-exchange-interval-set) and Consumer model:
- Seis: A unique combination of
symbol,exchange, andinterval. Creating aseisviatvl.new_seisstarts a background thread that waits for new data bars from TradingView. - Consumer: A callback function registered to a
seis. When a new data bar is retrieved, the consumer function is called with theseisobject and the new data as a pandas DataFrame.
Note: This provides data as close to real-time as possible via threading, but it is not true real-time data.
from tvDatafeed import TvDatafeedLive, Interval
tvl = TvDatafeedLive('username', 'password')
seis = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_1_hour)
def my_callback(seis, data):
print(f"New price: {data.close[0]}")
tvl.new_consumer(seis, my_callback)