金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 119|回复: 5

total_seconds()的使用问题

[复制链接]

6

主题

14

帖子

14

积分

Rank: 1

等级: 新手上路

注册:
2024-12-12
曾用名:
发表于 2025-3-27 14:58 | 显示全部楼层 |阅读模式
根据返回history bar取最后一个20分钟数据的时间,判断当前时间是否在下一个数据的周期内,一旦seconds加入if语句运行会一直循环??????
# 判断是否在一个周期内
def is_trade_in_period(bar):
    current_time = datetime.now()
    print("current_time: " + str(current_time))

    bar_time_last = bar["datetime"].values[-1]
    time_float = np.float64(bar_time_last)   
    time_str = str(int(bar_time_last))
    bar_time_last2 = datetime.strptime(time_str, "%Y%m%d%H%M%S")
    print("bar_time_last2: " + str(bar_time_last2))

    seconds = (current_time - bar_time_last2).total_seconds()
    print("seconds: " + str(seconds))
    if seconds < 1200 :
        print("!!!!!!!!!!!!!!!!!!")
        return True
    else :
        print("@@@@@@@@@")
        return False
log:
14:49:30 > 策略启动
14:49:31 > current_time: 2025-03-27 14:49:31.183962
14:49:31 > bar_time_last2: 2025-03-27 14:30:00
14:49:31 > seconds: 1171.183962
14:49:31 > !!!!!!!!!!!!!!!!!!
14:49:31 > current_time: 2025-03-27 14:49:31.198922
14:49:31 > bar_time_last2: 2025-03-27 14:30:00
14:49:31 > seconds: 1171.198922
14:49:31 > !!!!!!!!!!!!!!!!!!
14:49:31 > current_time: 2025-03-27 14:49:31.212885
14:49:31 > bar_time_last2: 2025-03-27 14:30:00
14:49:31 > seconds: 1171.212885
14:49:31 > !!!!!!!!!!!!!!!!!!
14:49:31 > current_time: 2025-03-27 14:49:31.226858
14:49:31 > bar_time_last2: 2025-03-27 14:30:00
14:49:31 > seconds: 1171.226858
14:49:31 > !!!!!!!!!!!!!!!!!!
14:49:31 > current_time: 2025-03-27 14:49:31.240814
14:49:31 > bar_time_last2: 2025-03-27 14:30:00
14:49:31 > seconds: 1171.240814
14:49:31 > !!!!!!!!!!!!!!!!!!

回复

使用道具 举报

20

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2025-3-27 15:36 | 显示全部楼层
你条件满足了当然会持续执行了。

本身handle_bar 就是在根据设置的模式 会持续执行的。你在handle_bar中直接或者间接调用的代码

都会一直执行。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

6

主题

14

帖子

14

积分

Rank: 1

等级: 新手上路

注册:
2024-12-12
曾用名:
 楼主| 发表于 2025-3-27 15:49 | 显示全部楼层
只执行这个,后面的语句不执行
回复

使用道具 举报

20

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2025-3-27 15:50 | 显示全部楼层
你这里都 返回了,后面当然不执行了。
截图202503271550181396.png
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

6

主题

14

帖子

14

积分

Rank: 1

等级: 新手上路

注册:
2024-12-12
曾用名:
 楼主| 发表于 2025-3-27 15:56 | 显示全部楼层
得到 seconds 的值是0.几的时候就只执行这个循环,其他不执行
回复

使用道具 举报

20

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2025-3-27 16:03 | 显示全部楼层
你这里满足了条件   就返回一个True。你要看下这个函数返回值为True  时候 你外部的逻辑是怎么走的。

你如果外部逻辑一直被卡在,当然什么都不执行了,只执行这个函数了。  



金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-4-10 11:20 , Processed in 0.249252 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表