lightweight-charts-python
lightweight-charts-python copied to clipboard
How to update precission after remove Series
Question
How to properly upate precision after removing series ?
this could also be an feature to request, since data do not need any changes from candle to bar type
https://github.com/user-attachments/assets/0c60f100-355f-4eb0-8202-4283d40e9216
thank you !
Code example
after your bundle.js - function createCandlestickSeries
`
createBarSeries() {
const t = "rgba(39, 157, 130, 100)",
e = "rgba(200, 97, 100, 100)",
i = this.chart.addBarSeries({
upColor: t,
borderUpColor: t,
wickUpColor: t,
downColor: e,
borderDownColor: e,
wickDownColor: e
});
return i.priceScale().applyOptions({
scaleMargins: {
top: .2,
bottom: .2
}
}), i
}
createSeries(chartType) {
if (chartType === "candle") {
return this.createCandlestickSeries();
} else if (chartType === "bar") {
return this.createBarSeries();
} else {
throw new Error("Invalid series type specified: " + this.seriesType);
}
}
switchSeriesType(type) {
if (type === "candle" || type === "bar") {
this.seriesType = type;
this.chart.removeSeries(this.series);
this.series = this.createSeries(type);
} else {
throw new Error("Invalid series type specified: " + type);
}
}
# then on abstract.py - class Abstract as last function
def switch_chart_type(self, type: str):
"""
Switches the chart type to either 'candle' or 'bar'.
"""
self.run_script(f"{self.id}.switchSeriesType('{type}')")
# and this is how i currently update precision
def get_chart_precision(self, symbol):
"""
Sets the precision of the chart based on the symbol's precision.
Args:
chart: The chart object that requires precision setting.
symbol (str): The symbol for which the precision is to be determined.
Returns:
None
"""
# chart precision
digits = self.getSymbolInfo(symbol=symbol, asDict=True)["digits"]
if self.chart is not None:
print(f"precision {digits} symbol {symbol}")
self.chart.precision(digits)
`