2023-12-29 13:38:45 +00:00
|
|
|
from chart import Chart
|
|
|
|
from pandas import Series
|
|
|
|
from plotly.graph_objects import Candlestick
|
2024-01-01 14:00:09 +00:00
|
|
|
from typing import List
|
2023-12-29 13:38:45 +00:00
|
|
|
|
|
|
|
class CandlestickChart(Chart):
|
|
|
|
|
2024-01-03 14:32:29 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
x: Series,
|
|
|
|
opens: Series,
|
|
|
|
highs: Series,
|
|
|
|
lows: Series,
|
|
|
|
closes: Series,
|
|
|
|
title: str = ''
|
|
|
|
):
|
2023-12-29 13:38:45 +00:00
|
|
|
self.x = x
|
|
|
|
self.opens = opens
|
|
|
|
self.highs = highs
|
|
|
|
self.lows = lows
|
|
|
|
self.closes = closes
|
2024-01-03 14:32:29 +00:00
|
|
|
self.title = title
|
2023-12-29 13:38:45 +00:00
|
|
|
|
2024-01-01 14:00:09 +00:00
|
|
|
def traces(self) -> List[Candlestick]:
|
|
|
|
return [Candlestick(
|
2023-12-29 13:38:45 +00:00
|
|
|
x = self.x,
|
|
|
|
open = self.opens,
|
|
|
|
high = self.highs,
|
|
|
|
low = self.lows,
|
|
|
|
close = self.closes, # TODO: Make colors configurable.
|
|
|
|
increasing = dict(line = dict(color = 'limegreen', width = 1), fillcolor = 'limegreen'),
|
2024-01-05 14:19:49 +00:00
|
|
|
decreasing = dict(line = dict(color = 'red', width = 1), fillcolor = 'red'),
|
|
|
|
name = ''
|
2024-01-01 14:00:09 +00:00
|
|
|
)]
|