Skip to main content

lightweight-chart custom python server

Project description

lightweight-charts-server

lightweight-charts-python based chart hosting library

Installation

pip install --upgrade lightweight-charts-server

Examples

Examples of usage are in examples/

Get examples through git clone

git clone https://github.com/vegaxholdings/lightweight-charts-server.git

cd lightweight-charts-server

pip install -r requirements.txt

Run Examples

  1. python -m examples.1_setting_data.setting_data
  2. python -m examples.2_live_data.live_data
  3. python -m examples.3_tick_data.tick_data
  4. python -m examples.4_line_indicators.line_indicators
  5. python -m examples.5_styling.styling

Advanced

There are two types of Display: View and Stream.

View can receive values ​​through HTML Form and reflect them on the chart.

Stream can receive values ​​from outside and update the chart in real time.

View

graph LR
	wb("Web Form")
	subgraph Server
		dy("HTML")
		ftype
		subgraph display
			view
		end
		subgraph lightweight-charts code
			create("create(a,b,c) -> Chart")
		end
	end
	wb --> ftype --> create
	create --> view
	view --> dy
	
	dy --> Web

This code demonstrates how to interact with a Form through ftype.

from datetime import timedelta

from lightweight_charts import Chart
from lightweight_charts_server import ftype, View, Server

intervals = ftype.options("1m", "15m")

def create(
    option: intervals = intervals("15m"),
    color: ftype.Color = ftype.Color("#1B2E00"),
    boolean: ftype.Bool = ftype.Bool(False),
    num_int: ftype.Int = ftype.Int(14),  
    num_float: ftype.Int = ftype.Float(3.14),  
    string: ftype.Str = ftype.Str("apple"),  
    time: ftype.DateTime = ftype.DateTime.now() - timedelta(days=10),  
    df: ftype.DataFrame = ftype.DataFrame({"a": [], "b": [], "c": []}),
) -> Chart:

    option.selected # -> str
    color.hex # -> str
    boolean.value # -> bool

    num_int # -> int
    num_float # -> float
    string # -> str
    time # -> datetime

    df # -> DataFrame

    ...

    return chart

display = View(callback=create)
server = Server(display)

if __name__ == "__main__":
    server.serve()

Stream

graph LR
	subgraph Server
		subgraph display
			stream
		end
		subgraph lightweight-charts code
			update("update(chart)")
			Chart
		end
	end
	subgraph External
		Upbit
	end
		Chart --> stream
	update --> stream
	stream <--->|websocket| Web
	External --> update

This code streams prices in real time through the upbit exchange.

import time
from datetime import date, datetime, timedelta

import pyupbit
import pandas as pd
from lightweight_charts import Chart
from lightweight_charts_server import Stream, Server

TICKER = "KRW-XRP"

init_df = pyupbit.get_ohlcv(ticker=TICKER, interval="minute")


def update(chart: Chart):
    while True:
        update_df = pyupbit.get_ohlcv(ticker=TICKER, count=1, interval="minute")
        tick = pd.Series(
            {
                "time": date.today().isoformat(), 
                "price": update_df.iloc[0]["close"],
            }
        )
        chart.update_from_tick(tick)
        time.sleep(0.1)


chart = Chart(toolbox=True)
chart.set(init_df)

display = Stream(chart, callback=update)
server = Server(display)

if __name__ == "__main__":
    server.serve()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lightweight_charts_server-0.1.5.tar.gz (89.4 kB view details)

Uploaded Source

Built Distribution

lightweight_charts_server-0.1.5-py3-none-any.whl (91.0 kB view details)

Uploaded Python 3

File details

Details for the file lightweight_charts_server-0.1.5.tar.gz.

File metadata

File hashes

Hashes for lightweight_charts_server-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9ca99fbd8d7059d5ec11696d9df41ab36cbd9bf4b28d683e70b25dcecd94847c
MD5 7a8457642d664852f340260833433dcd
BLAKE2b-256 31a02481fdc2a085bae864e58c9bb9fd67cad748e3720e191da11b994a10a0ac

See more details on using hashes here.

File details

Details for the file lightweight_charts_server-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for lightweight_charts_server-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 07b58c51ebaa908d3710dda99ddb819b2e3368edf4e0e3070fd88d06e56cd939
MD5 85b8c00c6a20b0712b5dc4249d2640cb
BLAKE2b-256 6596c287516a59e195a8997afafa4870333f83c01b6cf4fe43bb9e14fddc2067

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page