-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsjx.py
More file actions
36 lines (33 loc) · 1.11 KB
/
sjx.py
File metadata and controls
36 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'chengzhi'
from tqsdk import TqApi
'''
如果当前价格大于10秒K线的MA15则开多仓 (使用 insert_order() 函数)
如果小于则平仓
'''
api = TqApi()
# 获得 m2005 10秒K线的引用
klines = api.get_kline_serial("DCE.m2009", 10)
# 判断开仓条件
while True:
api.wait_update()
if api.is_changing(klines):
ma = sum(klines.close.iloc[-15:]) / 15
print("最新价", klines.close.iloc[-1], "MA", ma)
if klines.close.iloc[-1] > ma:
print("最新价大于MA: 市价开仓")
api.insert_order(symbol="DCE.m2009", direction="BUY", offset="OPEN", volume=5)
break
# 判断平仓条件
while True:
api.wait_update()
if api.is_changing(klines):
ma = sum(klines.close.iloc[-15:]) / 15
print("最新价", klines.close.iloc[-1], "MA", ma)
if klines.close.iloc[-1] < ma:
print("最新价小于MA: 市价平仓")
api.insert_order(symbol="DCE.m2009", direction="SELL", offset="CLOSE", volume=5)
break
# 关闭api,释放相应资源
api.close()