Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vegaxholdings/lightweight-charts-server
Python Web Chart Library
https://github.com/vegaxholdings/lightweight-charts-server
fastapi lightweight-charts python
Last synced: 10 days ago
JSON representation
Python Web Chart Library
- Host: GitHub
- URL: https://github.com/vegaxholdings/lightweight-charts-server
- Owner: vegaxholdings
- Created: 2024-07-31T06:33:02.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-12T05:11:04.000Z (11 days ago)
- Last Synced: 2024-12-12T06:19:23.419Z (11 days ago)
- Topics: fastapi, lightweight-charts, python
- Language: JavaScript
- Homepage: https://pypi.org/project/lightweight-charts-server/
- Size: 7.58 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## lightweight-charts-server
[lightweight-charts-python](https://github.com/louisnw01/lightweight-charts-python) based chart hosting library
### Installation
```
pip install --upgrade lightweight-charts-server
```### Examples
Examples of usage are in [examples/](examples/)
**Get examples through git clone**
```
git clone https://github.com/vegaxholdings/lightweight-charts-server.gitcd 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
```mermaid
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.
```python
from datetime import timedeltafrom lightweight_charts import Chart
from lightweight_charts_server import ftype, View, Serverintervals = 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": []}),
config: ftype.JSON = ftype.JSON([1, 2, 3]),
) -> Chart:option.selected # -> str
color.hex # -> str
boolean.value # -> boolnum_int # -> int
num_float # -> float
string # -> str
time # -> datetimedf # -> DataFrame
config.obj # -> list or dict...
return chart
display = View(callback=create)
server = Server(display)if __name__ == "__main__":
server.serve()```
## Stream
```mermaid
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.
```python
import time
from datetime import date, datetime, timedeltaimport pyupbit
import pandas as pd
from lightweight_charts import Chart
from lightweight_charts_server import Stream, ServerTICKER = "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()
```