Global
Unix()
获取当前时刻的 Unix 时间戳(秒)。
语法
python
timestamp = Unix()参数
无参数。
返回值
返回整数,表示当前 Unix 时间戳(秒)
示例
基本用法
python
def main():
timestamp = Unix()
Log("当前时间戳:", timestamp)计算时间间隔
python
def main():
start_time = Unix()
# 执行交易...
exchange.Buy(50000, 0.01)
end_time = Unix()
elapsed = end_time - start_time
Log(f"交易耗时: {elapsed} 秒")定时任务
python
def main():
last_check_time = Unix()
while True:
current_time = Unix()
# 每小时执行一次
if current_time - last_check_time >= 3600:
Log("执行每小时任务")
last_check_time = current_time
Sleep(10000)时间过滤
python
def main():
# 只在特定时间段交易(UTC时间)
while True:
current_time = Unix()
hour = (current_time // 3600) % 24
if 8 <= hour < 20:
Log("交易时间,执行策略")
# 交易逻辑...
else:
Log("非交易时间,休眠")
Sleep(60000)相关函数
- UnixNano() - 获取纳秒级时间戳
- Sleep() - 休眠函数