to show current date time
This commit is contained in:
parent
eb07932a3c
commit
b2f227cdf4
Binary file not shown.
Binary file not shown.
|
|
@ -13,7 +13,8 @@ def create_metrics_report(
|
||||||
next_bar_row: pd.Series,
|
next_bar_row: pd.Series,
|
||||||
btc_bar_row: pd.Series,
|
btc_bar_row: pd.Series,
|
||||||
only_output_huge_volume: bool = False,
|
only_output_huge_volume: bool = False,
|
||||||
only_output_rise: bool = False
|
only_output_rise: bool = False,
|
||||||
|
now_datetime_str: str = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
创建指标报告
|
创建指标报告
|
||||||
|
|
@ -42,11 +43,11 @@ def create_metrics_report(
|
||||||
# fill -1 to nan
|
# fill -1 to nan
|
||||||
row = row.fillna(1)
|
row = row.fillna(1)
|
||||||
|
|
||||||
close = row["close"]
|
close = round(float(row["close"]), 10)
|
||||||
open = row["open"]
|
open = round(float(row["open"]), 10)
|
||||||
high = row["high"]
|
high = round(float(row["high"]), 10)
|
||||||
low = row["low"]
|
low = round(float(row["low"]), 10)
|
||||||
pct_chg = row["pct_chg"]
|
pct_chg = round(float(row["pct_chg"]), 4)
|
||||||
if only_output_rise and pct_chg < 0:
|
if only_output_rise and pct_chg < 0:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"symbol: {symbol} {bar} window_size: {window_size} date_time: {date_time} 下跌,不发送相关数据"
|
f"symbol: {symbol} {bar} window_size: {window_size} date_time: {date_time} 下跌,不发送相关数据"
|
||||||
|
|
@ -56,16 +57,19 @@ def create_metrics_report(
|
||||||
contents.append(f"## 交易巨量报告")
|
contents.append(f"## 交易巨量报告")
|
||||||
else:
|
else:
|
||||||
contents.append(f"## 交易量报告")
|
contents.append(f"## 交易量报告")
|
||||||
contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 时间: {date_time}")
|
if now_datetime_str is not None:
|
||||||
|
contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 最新数据时间: {now_datetime_str}")
|
||||||
|
else:
|
||||||
|
contents.append(f"## {symbol} {bar} 滑动窗口: {window_size} 交易周期时间: {date_time}")
|
||||||
contents.append(f"### 价格信息")
|
contents.append(f"### 价格信息")
|
||||||
contents.append(f"当前价格: {close}, 开盘价: {open}, 最高价: {high}, 最低价: {low}")
|
contents.append(f"当前价格: {close}, 开盘价: {open}, 最高价: {high}, 最低价: {low}")
|
||||||
contents.append(f"涨跌幅: {pct_chg}")
|
contents.append(f"涨跌幅: {pct_chg}")
|
||||||
|
|
||||||
volume = row["volume"]
|
volume = round(float(row["volume"]), 4)
|
||||||
volCcy = row["volCcy"]
|
volCcy = round(float(row["volCcy"]), 4)
|
||||||
volCCyQuote = row["volCCyQuote"]
|
volCCyQuote = round(float(row["volCCyQuote"]), 4)
|
||||||
volume_ratio = row["volume_ratio"]
|
volume_ratio = round(float(row["volume_ratio"]), 4)
|
||||||
spike_intensity = row["spike_intensity"]
|
spike_intensity = round(float(row["spike_intensity"]), 4)
|
||||||
close_80_high = int(row["close_80_high"])
|
close_80_high = int(row["close_80_high"])
|
||||||
close_20_low = int(row["close_20_low"])
|
close_20_low = int(row["close_20_low"])
|
||||||
close_90_high = int(row["close_90_high"])
|
close_90_high = int(row["close_90_high"])
|
||||||
|
|
@ -270,10 +274,10 @@ def create_metrics_report(
|
||||||
|
|
||||||
if next_bar_row is not None:
|
if next_bar_row is not None:
|
||||||
contents.append(f"## {symbol} 与更长周期技术形态对比")
|
contents.append(f"## {symbol} 与更长周期技术形态对比")
|
||||||
contents.extend(get_long_short_over_buy_sell(next_bar_row))
|
contents.extend(get_long_short_over_buy_sell(next_bar_row, now_datetime_str))
|
||||||
if btc_bar_row is not None:
|
if btc_bar_row is not None:
|
||||||
contents.append(f"## {symbol} 与BTC相同周期技术形态对比")
|
contents.append(f"## {symbol} 与BTC相同周期技术形态对比")
|
||||||
contents.extend(get_long_short_over_buy_sell(btc_bar_row))
|
contents.extend(get_long_short_over_buy_sell(btc_bar_row, now_datetime_str))
|
||||||
|
|
||||||
mark_down_text = "\n\n".join(contents)
|
mark_down_text = "\n\n".join(contents)
|
||||||
return mark_down_text
|
return mark_down_text
|
||||||
|
|
@ -281,6 +285,7 @@ def create_metrics_report(
|
||||||
|
|
||||||
def get_long_short_over_buy_sell(
|
def get_long_short_over_buy_sell(
|
||||||
row: pd.Series,
|
row: pd.Series,
|
||||||
|
now_datetime_str: str = None,
|
||||||
):
|
):
|
||||||
result = {}
|
result = {}
|
||||||
symbol = row["symbol"]
|
symbol = row["symbol"]
|
||||||
|
|
@ -295,7 +300,10 @@ def get_long_short_over_buy_sell(
|
||||||
boll_signal = str(row["boll_signal"])
|
boll_signal = str(row["boll_signal"])
|
||||||
boll_pattern = str(row["boll_pattern"])
|
boll_pattern = str(row["boll_pattern"])
|
||||||
contents = []
|
contents = []
|
||||||
contents.append(f"### {symbol} {bar} 对比形态 {date_time}")
|
if now_datetime_str is not None:
|
||||||
|
contents.append(f"### {symbol} {bar} 对比形态 最新数据时间: {now_datetime_str}")
|
||||||
|
else:
|
||||||
|
contents.append(f"### {symbol} {bar} 对比形态 交易周期时间: {date_time}")
|
||||||
if ma_long_short in ["多", "空"]:
|
if ma_long_short in ["多", "空"]:
|
||||||
contents.append(f"均线形态: {ma_long_short}")
|
contents.append(f"均线形态: {ma_long_short}")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ class MarketMonitorMain:
|
||||||
latest_reatime_datetime = timestamp_to_datetime(latest_realtime_timestamp)
|
latest_reatime_datetime = timestamp_to_datetime(latest_realtime_timestamp)
|
||||||
if latest_record_timestamp is not None:
|
if latest_record_timestamp is not None:
|
||||||
latest_record_timestamp = int(latest_record_timestamp)
|
latest_record_timestamp = int(latest_record_timestamp)
|
||||||
|
|
||||||
latest_record_datetime = timestamp_to_datetime(latest_record_timestamp)
|
latest_record_datetime = timestamp_to_datetime(latest_record_timestamp)
|
||||||
if (
|
if (
|
||||||
latest_record_timestamp is not None
|
latest_record_timestamp is not None
|
||||||
|
|
@ -106,10 +106,12 @@ class MarketMonitorMain:
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
logging.info(
|
logging.info(
|
||||||
f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间 {latest_record_datetime}")
|
f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间 {latest_record_datetime}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间为空")
|
f"最新市场数据时间 {latest_reatime_datetime}, 上一次记录时间为空"
|
||||||
|
)
|
||||||
|
|
||||||
real_time_data = self.market_data_main.add_new_columns(real_time_data)
|
real_time_data = self.market_data_main.add_new_columns(real_time_data)
|
||||||
logging.info(f"开始计算技术指标: {symbol} {bar}")
|
logging.info(f"开始计算技术指标: {symbol} {bar}")
|
||||||
|
|
@ -134,23 +136,35 @@ class MarketMonitorMain:
|
||||||
if realtime_row["huge_volume"] == 1:
|
if realtime_row["huge_volume"] == 1:
|
||||||
logging.info(f"监控到巨量: {symbol} {bar} 窗口大小: {self.window_size}")
|
logging.info(f"监控到巨量: {symbol} {bar} 窗口大小: {self.window_size}")
|
||||||
else:
|
else:
|
||||||
logging.info(f"监控到非巨量: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控")
|
logging.info(
|
||||||
|
f"监控到非巨量: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if only_output_rise:
|
if only_output_rise:
|
||||||
if realtime_row["pct_change"] > 0:
|
if realtime_row["pct_change"] > 0:
|
||||||
logging.info(f"监控到上涨: {symbol} {bar} 窗口大小: {self.window_size}")
|
logging.info(f"监控到上涨: {symbol} {bar} 窗口大小: {self.window_size}")
|
||||||
else:
|
else:
|
||||||
logging.info(f"监控到下跌: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控")
|
logging.info(
|
||||||
|
f"监控到下跌: {symbol} {bar} 窗口大小: {self.window_size},退出本次监控"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
next_bar_row = self.get_other_realtime_data(symbol, bar, end_time, next=True)
|
next_bar_row = self.get_other_realtime_data(symbol, bar, end_time, next=True)
|
||||||
if 'BTC-USDT' in symbol:
|
if "BTC-USDT" in symbol:
|
||||||
btc_bar_row = None
|
btc_bar_row = None
|
||||||
else:
|
else:
|
||||||
btc_bar_row = self.get_other_realtime_data('BTC-USDT', bar, end_time, next=False)
|
btc_bar_row = self.get_other_realtime_data(
|
||||||
|
"BTC-USDT", bar, end_time, next=False
|
||||||
|
)
|
||||||
|
|
||||||
|
report = create_metrics_report(
|
||||||
report = create_metrics_report(realtime_row, next_bar_row, btc_bar_row, only_output_huge_volume, only_output_rise)
|
realtime_row,
|
||||||
|
next_bar_row,
|
||||||
|
btc_bar_row,
|
||||||
|
only_output_huge_volume,
|
||||||
|
only_output_rise,
|
||||||
|
now_datetime_str,
|
||||||
|
)
|
||||||
text_length = len(report.encode("utf-8"))
|
text_length = len(report.encode("utf-8"))
|
||||||
|
|
||||||
logging.info(f"发送报告到企业微信,字节数: {text_length}")
|
logging.info(f"发送报告到企业微信,字节数: {text_length}")
|
||||||
|
|
@ -158,9 +172,7 @@ class MarketMonitorMain:
|
||||||
|
|
||||||
# remove punction in latest_reatime_datetime
|
# remove punction in latest_reatime_datetime
|
||||||
file_datetime = re.sub(r"[\:\-\s]", "", latest_reatime_datetime)
|
file_datetime = re.sub(r"[\:\-\s]", "", latest_reatime_datetime)
|
||||||
report_file_name = (
|
report_file_name = f"{symbol}_{bar}_{self.window_size}_{file_datetime}.md"
|
||||||
f"{symbol}_{bar}_{self.window_size}_{file_datetime}.md"
|
|
||||||
)
|
|
||||||
report_file_path = os.path.join(self.output_folder, report_file_name)
|
report_file_path = os.path.join(self.output_folder, report_file_name)
|
||||||
with open(report_file_path, "w", encoding="utf-8") as f:
|
with open(report_file_path, "w", encoding="utf-8") as f:
|
||||||
f.write(report)
|
f.write(report)
|
||||||
|
|
@ -186,7 +198,9 @@ class MarketMonitorMain:
|
||||||
with open(self.latest_record_file_path, "w", encoding="utf-8") as f:
|
with open(self.latest_record_file_path, "w", encoding="utf-8") as f:
|
||||||
json.dump(self.latest_record, f, ensure_ascii=False, indent=4)
|
json.dump(self.latest_record, f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
def get_other_realtime_data(self, symbol: str, bar: str, end_time: int, next: bool = True):
|
def get_other_realtime_data(
|
||||||
|
self, symbol: str, bar: str, end_time: int, next: bool = True
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
获取下一个长周期实时数据
|
获取下一个长周期实时数据
|
||||||
"""
|
"""
|
||||||
|
|
@ -218,7 +232,9 @@ class MarketMonitorMain:
|
||||||
):
|
):
|
||||||
for symbol in self.market_data_main.symbols:
|
for symbol in self.market_data_main.symbols:
|
||||||
for bar in self.market_data_main.bars:
|
for bar in self.market_data_main.bars:
|
||||||
logging.info(f"开始监控: {symbol} {bar} 窗口大小: {self.window_size} 行情数据")
|
logging.info(
|
||||||
|
f"开始监控: {symbol} {bar} 窗口大小: {self.window_size} 行情数据"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
self.monitor_realtime_market(
|
self.monitor_realtime_market(
|
||||||
symbol,
|
symbol,
|
||||||
|
|
@ -227,7 +243,9 @@ class MarketMonitorMain:
|
||||||
only_output_rise,
|
only_output_rise,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"监控失败: {symbol} {bar} 窗口大小: {self.window_size} 行情数据: {e}")
|
logging.error(
|
||||||
|
f"监控失败: {symbol} {bar} 窗口大小: {self.window_size} 行情数据: {e}"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ def monitor_schedule():
|
||||||
only_output_huge_volume=True,
|
only_output_huge_volume=True,
|
||||||
only_output_rise=False,
|
only_output_rise=False,
|
||||||
)
|
)
|
||||||
logging.info("本次循环监控结束,等待1分钟")
|
logging.info("本次循环监控结束,等待30秒")
|
||||||
time.sleep(60)
|
time.sleep(30)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
monitor_schedule()
|
monitor_schedule()
|
||||||
Loading…
Reference in New Issue