Skip to content

Commit fc84cc7

Browse files
committed
lotta changes
1 parent 4c6a838 commit fc84cc7

File tree

13 files changed

+529
-581
lines changed

13 files changed

+529
-581
lines changed

stock_market_dashboard/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ __pycache__/
44
*.db
55
assets/external/
66
.web
7+
.DS_Store
8+
.idea/

stock_market_dashboard/rxconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import reflex as rx
22

3-
config = rx.Config(app_name="stock_market_dashboard")
3+
config = rx.Config(app_name="stock_market_dashboard")

stock_market_dashboard/stock_market_dashboard/components/line_chart.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import reflex as rx
2-
from typing import List
3-
from stock_market_dashboard.states.trading_state import TradingState, StockInfo
2+
43
from stock_market_dashboard.components.tooltip_props import TOOLTIP_PROPS
4+
from stock_market_dashboard.states.trading_state import StockInfo, TradingState
55

66

77
def stock_info_header(stock: StockInfo) -> rx.Component:
@@ -103,9 +103,7 @@ def trading_line_chart() -> rx.Component:
103103
f"Math.max(...{TradingState.chart_data.to_string()}.map(p => p.price))"
104104
).to(int)
105105
padding = (max_price - min_price) * 0.1
106-
y_domain = rx.Var.create(
107-
f"[{min_price} - {padding}, {max_price} + {padding}]"
108-
)
106+
y_domain = rx.Var.create(f"[{min_price} - {padding}, {max_price} + {padding}]")
109107
return rx.el.div(
110108
stock_info_header(TradingState.stock_info),
111109
rx.recharts.line_chart(
@@ -158,4 +156,4 @@ def trading_line_chart() -> rx.Component:
158156
),
159157
chart_controls(),
160158
class_name="bg-gray-800 p-4 rounded-lg border border-gray-700 flex-grow",
161-
)
159+
)

stock_market_dashboard/stock_market_dashboard/components/main_header.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import reflex as rx
2+
23
from stock_market_dashboard.states.trading_state import TradingState
34

45

@@ -19,12 +20,9 @@ def main_header() -> rx.Component:
1920
tabs,
2021
lambda tab: rx.el.button(
2122
tab,
22-
on_click=TradingState.set_active_main_tab(
23-
tab
24-
),
23+
on_click=TradingState.set_active_main_tab(tab),
2524
class_name=rx.cond(
26-
TradingState.active_main_tab
27-
== tab,
25+
TradingState.active_main_tab == tab,
2826
"px-3 py-2 text-sm font-medium text-white border-b-2 border-green-500",
2927
"px-3 py-2 text-sm font-medium text-gray-400 hover:text-white hover:border-b-2 hover:border-gray-500",
3028
),
@@ -49,9 +47,7 @@ def main_header() -> rx.Component:
4947
),
5048
rx.el.div(
5149
rx.el.select(
52-
rx.el.option(
53-
"Individual", value="individual"
54-
),
50+
rx.el.option("Individual", value="individual"),
5551
default_value="individual",
5652
class_name="bg-gray-700 text-white text-xs rounded border-0 focus:ring-0 mr-3 py-1",
5753
),
@@ -66,4 +62,4 @@ def main_header() -> rx.Component:
6662
class_name="flex justify-between items-center w-full",
6763
),
6864
class_name="bg-gray-900 text-gray-300 px-4 py-2 border-b border-gray-700",
69-
)
65+
)

stock_market_dashboard/stock_market_dashboard/components/options_table.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import reflex as rx
2-
from stock_market_dashboard.states.trading_state import TradingState, Option
3-
from typing import List
2+
3+
from stock_market_dashboard.states.trading_state import TradingState
44

55

66
def options_header(
@@ -51,9 +51,7 @@ def options_sub_tabs() -> rx.Component:
5151
tabs,
5252
lambda tab: rx.el.button(
5353
tab,
54-
on_click=TradingState.set_active_sub_tab(
55-
tab
56-
),
54+
on_click=TradingState.set_active_sub_tab(tab),
5755
class_name=rx.cond(
5856
TradingState.active_sub_tab == tab,
5957
"text-xs text-white bg-gray-700 px-3 py-1 rounded",
@@ -219,9 +217,7 @@ def render_combined_option_row(
219217
call_option,
220218
rx.fragment(
221219
*[
222-
render_option_cell(
223-
call_option[key], cn, *fmt
224-
)
220+
render_option_cell(call_option[key], cn, *fmt)
225221
for key, cn, *fmt in call_headers_config
226222
]
227223
),
@@ -247,9 +243,7 @@ def render_combined_option_row(
247243
put_option,
248244
rx.fragment(
249245
*[
250-
render_option_cell(
251-
put_option[key], cn, *fmt
252-
)
246+
render_option_cell(put_option[key], cn, *fmt)
253247
for key, cn, *fmt in put_headers_config
254248
]
255249
),
@@ -351,4 +345,4 @@ def options_table() -> rx.Component:
351345
class_name="overflow-y-auto max-h-[280px]",
352346
),
353347
class_name="bg-gray-800 p-3 rounded-lg border border-gray-700 flex-grow lg:min-w-[600px]",
354-
)
348+
)

stock_market_dashboard/stock_market_dashboard/components/orders_table.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import reflex as rx
2-
from stock_market_dashboard.states.trading_state import TradingState, Order
2+
3+
from stock_market_dashboard.states.trading_state import Order, TradingState
34

45

56
def get_status_color(status: rx.Var[str]) -> rx.Var[str]:
@@ -14,9 +15,7 @@ def get_status_color(status: rx.Var[str]) -> rx.Var[str]:
1415

1516

1617
def get_side_color(side: rx.Var[str]) -> rx.Var[str]:
17-
return rx.cond(
18-
side == "Buy", "text-green-400", "text-red-400"
19-
)
18+
return rx.cond(side == "Buy", "text-green-400", "text-red-400")
2019

2120

2221
def render_order_row(order: Order) -> rx.Component:
@@ -96,12 +95,8 @@ def orders_table() -> rx.Component:
9695
rx.el.thead(
9796
rx.el.tr(
9897
rx.foreach(
99-
list(
100-
zip(headers, header_classes)
101-
),
102-
lambda item: rx.el.th(
103-
item[0], class_name=item[1]
104-
),
98+
list(zip(headers, header_classes)),
99+
lambda item: rx.el.th(item[0], class_name=item[1]),
105100
),
106101
class_name="sticky top-0 bg-gray-800 z-10",
107102
)
@@ -117,4 +112,4 @@ def orders_table() -> rx.Component:
117112
class_name="overflow-y-auto max-h-[200px]",
118113
),
119114
class_name="bg-gray-800 p-3 rounded-lg border border-gray-700",
120-
)
115+
)

stock_market_dashboard/stock_market_dashboard/components/positions_table.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import reflex as rx
2-
from stock_market_dashboard.states.trading_state import TradingState, Position
31
from typing import Union
42

3+
import reflex as rx
4+
5+
from stock_market_dashboard.states.trading_state import Position, TradingState
6+
57

68
def format_currency(
79
value: rx.Var[Union[float, None]],
810
) -> rx.Var[str]:
9-
return rx.cond(value != None, value.to_string(), "-")
11+
return rx.cond(value is not None, value.to_string(), "-")
1012

1113

1214
def format_signed_currency(
1315
value: rx.Var[Union[float, None]],
1416
) -> rx.Var[str]:
15-
return rx.cond(value != None, value.to_string(), "-")
17+
return rx.cond(value is not None, value.to_string(), "-")
1618

1719

1820
def format_float(
1921
value: rx.Var[Union[float, None]],
2022
format_spec: str = ".2f",
2123
) -> rx.Var[str]:
22-
return rx.cond(value != None, value.to_string(), "-")
24+
return rx.cond(value is not None, value.to_string(), "-")
2325

2426

2527
def format_signed_percent(
2628
value: rx.Var[Union[float, None]],
2729
) -> rx.Var[str]:
28-
return rx.cond(value != None, value.to_string(), "-")
30+
return rx.cond(value is not None, value.to_string(), "-")
2931

3032

3133
def get_return_color(
3234
value: rx.Var[Union[float, None]],
3335
) -> rx.Var[str]:
3436
return rx.cond(
35-
value != None,
36-
rx.cond(
37-
value >= 0, "text-green-400", "text-red-400"
38-
),
37+
value is not None,
38+
rx.cond(value >= 0, "text-green-400", "text-red-400"),
3939
"text-gray-300",
4040
)
4141

@@ -57,7 +57,7 @@ def render_position_row(pos: Position) -> rx.Component:
5757
rx.el.td(
5858
format_signed_currency(pos["day_return"]),
5959
class_name=rx.cond(
60-
pos["day_return"] != None,
60+
pos["day_return"] is not None,
6161
rx.cond(
6262
pos["day_return"] >= 0,
6363
"px-3 py-2 whitespace-nowrap text-sm text-right text-green-400",
@@ -69,7 +69,7 @@ def render_position_row(pos: Position) -> rx.Component:
6969
rx.el.td(
7070
format_signed_percent(pos["day_percent"]),
7171
class_name=rx.cond(
72-
pos["day_percent"] != None,
72+
pos["day_percent"] is not None,
7373
rx.cond(
7474
pos["day_percent"] >= 0,
7575
"px-3 py-2 whitespace-nowrap text-sm text-right text-green-400",
@@ -112,9 +112,8 @@ def render_position_row(pos: Position) -> rx.Component:
112112
),
113113
rx.el.td(
114114
rx.cond(
115-
pos["iv"] != None,
116-
format_float(pos["iv"].to(float), ".2f")
117-
+ "%",
115+
pos["iv"] is not None,
116+
format_float(pos["iv"].to(float), ".2f") + "%",
118117
"-",
119118
),
120119
class_name="px-3 py-2 whitespace-nowrap text-sm text-gray-300 text-right",
@@ -182,12 +181,8 @@ def positions_table() -> rx.Component:
182181
rx.el.thead(
183182
rx.el.tr(
184183
rx.foreach(
185-
list(
186-
zip(headers, header_classes)
187-
),
188-
lambda item: rx.el.th(
189-
item[0], class_name=item[1]
190-
),
184+
list(zip(headers, header_classes)),
185+
lambda item: rx.el.th(item[0], class_name=item[1]),
191186
),
192187
class_name="sticky top-0 bg-gray-800 z-10",
193188
)
@@ -203,4 +198,4 @@ def positions_table() -> rx.Component:
203198
class_name="overflow-x-auto overflow-y-auto max-h-[200px]",
204199
),
205200
class_name="bg-gray-800 p-3 rounded-lg border border-gray-700",
206-
)
201+
)

stock_market_dashboard/stock_market_dashboard/components/tooltip_props.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import reflex as rx
2-
31
TOOLTIP_PROPS = {
42
"separator": ": ",
53
"cursor": False,
@@ -29,4 +27,4 @@
2927
"padding": "0.375rem 0.625rem",
3028
"position": "relative",
3129
},
32-
}
30+
}

stock_market_dashboard/stock_market_dashboard/models/__init__.py

Whitespace-only changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from typing import Literal, TypedDict, Union
2+
3+
4+
class ChartDataPoint(TypedDict):
5+
time: str
6+
price: float
7+
8+
9+
class Option(TypedDict):
10+
type: Literal["Call", "Put"]
11+
mark: float
12+
percent_change_to: float
13+
delta: float
14+
oi: int
15+
volume: int
16+
iv: float
17+
low: float
18+
high: float
19+
bid: float
20+
ask: float
21+
strike: float
22+
gamma: float
23+
24+
25+
class Order(TypedDict):
26+
symbol: str
27+
status: Literal["Sending", "Working", "Filled", "Canceled"]
28+
side: Literal["Buy", "Sell"]
29+
type: Literal["Market", "Limit", "Stop market"]
30+
qty: int
31+
total_cost: float
32+
33+
34+
class Position(TypedDict):
35+
symbol: str
36+
qty: float
37+
mkt_val: float
38+
day_return: float
39+
day_percent: float
40+
total_ret: float
41+
mark: float
42+
avg_cost: float
43+
bid: float
44+
ask: float
45+
delta: float
46+
gamma: float
47+
theta: float
48+
iv: Union[float, None]
49+
type: Literal["Equities", "Options"]
50+
dte: Union[int, str]
51+
52+
53+
class StockInfo(TypedDict):
54+
symbol: str
55+
price: float
56+
change: float
57+
change_percent: float
58+
volume: str
59+
open: float
60+
high: float
61+
low: float
62+
close: float

0 commit comments

Comments
 (0)