如何在 python 交易模型中创建功能时间条件
How do I create functioning time conditional in python trading model?
我正在尝试创建一个交易模型,我想在一定时间后执行交易。如何运行控制台,并让订单在特定时间执行?请展示代码实现的示例?
localtime = time.asctime(time.localtime(time.time()))
if localtime >"time":
#execute order
最简单的实现是使用线程。打开一个线程,每隔一秒左右根据您的条件检查时间,例如
while (localtime < time_to_execute):
time.sleep(1)
localtime = (refresh the local time value)
*some code to execute a trade*
链接的资源包含有关如何打开和加入线程的大量信息,因此您可以将其设置为随心所欲地运行(连续、交易后退出等(
我想通了。不是最好的,但仍然有效。请告知是否有更好的方法。谢谢。
方法:Order_execution_function先行,因为它将保存运行条件订单的代码。然而,要在指定的时间段运行代码,执行条件(if 语句,price>200...(必须包装在Time_Conditional函数中,以便仅在满足Time_Conditional函数时才读取执行代码,然后允许Order_execution_function执行。
from datetime import datetime
from threading import Timer
def Order_execution_function(self):
x = datetime.today()
y = x.replace(year=2019, month=7, day=26, hour=15, minute=36, second=15, microsecond=0)
delta_t = y - x
secs = delta_t.seconds + 1
def Time_Conditional():
#execute code, if statements...
#execute code, if statements...
#execute code, if statements...
t = Timer(secs, Time_Conditional)
t.start()
相关文章:
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- C++ - 为文本RPG创建基本战斗功能
- 我在 C++ 中创建了一个函数来递归反转字符串,但是之后如何使功能打印一个 endl?
- 如果在创建对象时创建了 VPTR,那么为什么具有虚拟功能的类的大小在 32 位系统上为 4,在 64 位机器上为 8
- 创建类成员功能
- 插入功能保持重新创建根节点
- 如何在 python 交易模型中创建功能时间条件
- 如何为带有计时功能的程序创建计时器?
- Protobuf的反序列化功能之一可以使用Cereal重新创建吗?
- 如何使用Sfinae为容器创建模板功能,并根据操作员推断返回类型
- 类自动创建基于成员名称的功能
- 在功能中创建一个数组,然后将其返回到main()
- 从没有预处理器的HANA元组中创建功能签名
- 如何创建功能以用受保护或私人侵犯的对象在对象内部操纵对象
- 在堆中创建功能指针的数组
- 是否有一种方法可以避免在RVALUE和LVALUE参考中创建功能时避免重复的代码
- WXWIDGETS WXPANEL访问创建功能中创建的WXPanelNamest
- 在C 中的预局体中创建功能
- 在Windows中创建功能齐全的MP3播放器
- 在c++中使用字符串,分析字符并通过类创建功能