Skip to content

Commit

Permalink
Merge pull request #18 from Wollala/dev
Browse files Browse the repository at this point in the history
Change PNL info display location to calculate_console_widget
  • Loading branch information
wollala authored Apr 14, 2023
2 parents aa6d515 + 32fe85b commit a702142
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def api_key_menu_clicked(self, s): # noqa
def info_menu_clicked(self, s): # noqa
self.program_info_dialog.show()

@QtCore.Slot()
def model_Updated(self, first_order_day, last_order_day, pnl_krw, pnl_btc):
self.calculate_console_widget.append("======== 수익률 ========")
self.calculate_console_widget.append(f'기간 : <b><font color="#f3f3f4">{first_order_day.strftime("%Y-%m-%d %H:%M:%S")}</font></b> ~ <b><font color="#f3f3f4">{last_order_day.strftime("%Y-%m-%d %H:%M:%S")}</font></b>'
f' ({last_order_day - first_order_day})')
self.calculate_console_widget.append(f'KRW : <b><font color="#f3f3f4">{pnl_krw:>,.0f}</font></b> ₩')
self.calculate_console_widget.append(f'BTC : <b><font color="#f3f3f4">{pnl_btc:>,.8f}</font></b> btc')

@QtCore.Slot()
def krw_sum_finished(self, df, result):
df = df.reset_index(drop=True)
Expand Down Expand Up @@ -250,6 +258,7 @@ def create_main_tab0(self):
# 코인별 수익률 Widget
self.period_pnl_widget = PeriodPnLWidget(parent=self)
self.period_pnl_widget.period_pnl_table_view.sumFinished.connect(self.sum_finished)
self.period_pnl_widget.modelUpdated.connect(self.model_Updated)

# Layout
mid_tab_widget = QtWidgets.QTabWidget(parent=self)
Expand All @@ -275,6 +284,7 @@ def create_main_tab0(self):
"background-color: rgb(34, 40, 64);"
"color: rgb(157, 159, 170)"
)
self.calculate_console_widget.setFont(QtGui.QFont('Consolas', 11))
self.calculate_console_widget.setAcceptRichText(True)
bottom_frame = QtWidgets.QFrame(parent=self)
bottom_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Expand All @@ -287,7 +297,7 @@ def create_main_tab0(self):
splitter.addWidget(mid_tab_widget)
splitter.addWidget(bottom_frame)
splitter.setHandleWidth(5)
splitter.setSizes([300, 600, 100])
splitter.setSizes([300, 600, 125])

layout = QtWidgets.QHBoxLayout()
layout.addWidget(splitter)
Expand Down
5 changes: 3 additions & 2 deletions util/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def create_asset_period_pnl_df(self, filterd_order_history_df):
pnl_krw = 0
pnl_btc = 0

since = filterd_order_history_df["주문시간"].sort_values().iloc[0]
first_order_day = filterd_order_history_df["주문시간"].sort_values().iloc[0]
last_order_day = filterd_order_history_df["주문시간"].sort_values().iloc[-1]

result_df = pd.DataFrame(
columns=["마켓", "총 매수수량", "총 매도수량", "미실현수량", "총 매수금액", "총 매도금액", "매수 평단가", "매도 평단가",
Expand Down Expand Up @@ -230,4 +231,4 @@ def create_asset_period_pnl_df(self, filterd_order_history_df):
except Exception as e:
logging.exception(e)
finally:
return result_df, since, pnl_krw, pnl_btc
return result_df, first_order_day, last_order_day, pnl_krw, pnl_btc
18 changes: 4 additions & 14 deletions widget/period_pnl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class PeriodPnLWidget(QtWidgets.QWidget):
modelUpdated = QtCore.Signal(pd.Timestamp, pd.Timestamp, float, float)

def __init__(self, parent=None):
super(PeriodPnLWidget, self).__init__(parent=parent)
self.dm = DataManager()
Expand Down Expand Up @@ -46,19 +48,10 @@ def set_to_date(to_date):
self.period_pnl_table_view.setColumnWidth(8, 150) # 실현손익
self.period_pnl_table_view.setColumnWidth(9, 70) # 수익률

self.pnl_title = QtWidgets.QLabel("[PNL]")
self.pnl_since = QtWidgets.QLabel("SINCE: ")
self.pnl_krw_layout = QtWidgets.QLabel("KRW: " + str(0), self)
self.pnl_btc_layout = QtWidgets.QLabel("BTC: " + str(0), self)

# 레이아웃
self.main_layout = QtWidgets.QVBoxLayout()
self.main_layout.addWidget(self.date_filter_widget)
self.main_layout.addWidget(self.period_pnl_table_view)
self.main_layout.addWidget(self.pnl_title)
self.main_layout.addWidget(self.pnl_since)
self.main_layout.addWidget(self.pnl_krw_layout)
self.main_layout.addWidget(self.pnl_btc_layout)
self.setLayout(self.main_layout)

@property
Expand Down Expand Up @@ -99,11 +92,8 @@ def filtering_df(self, df):
def update_model(self):
if self.dm.order_history_df is not None:
filterd_df = self.filtering_df(self.dm.order_history_df)
self.dm.asset_period_pnl_df, since, pnl_krw, pnl_btc = self.dm.create_asset_period_pnl_df(filterd_df)

self.pnl_since.setText("SINCE: " + str(since))
self.pnl_krw_layout.setText("KRW: " + "{:,}".format(pnl_krw))
self.pnl_btc_layout.setText("BTC: " + "{:,}".format(pnl_btc))
self.dm.asset_period_pnl_df, first_order_day, last_order_day, pnl_krw, pnl_btc = self.dm.create_asset_period_pnl_df(filterd_df)

model = PeriodPnLPandasModel(self.dm.asset_period_pnl_df)
self.period_pnl_table_view.setModel(model)
self.modelUpdated.emit(first_order_day, last_order_day, pnl_krw, pnl_btc)

0 comments on commit a702142

Please sign in to comment.