-
Notifications
You must be signed in to change notification settings - Fork 21
/
testparse.py
89 lines (60 loc) · 1.26 KB
/
testparse.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#test lex parse
from Klang.lang import kparser,setPY,Kexec
from Klang import (Kl,Klang,
C,O,V,H,L, CLOSE,HIGH,
MA,CROSS,BARSLAST,HHV,COUNT,
MAX,MIN,MACD)
from Klang.Kfeature import TRANSVERSE
Klang.Klang_init()
def getpyglobals(name):
return globals().get(name)
def setpyglobals(name,val):
globals()[name]=val
setPY(getpyglobals,setpyglobals)
def getstockinfo(a):
return Kl.currentdf['name'] + "-" + Kl.currentdf['code']
pi=3.1415926
#print(C/C[1])
testblock=\
"""
kloop
ret = CROSS(C,MA(C,60))
ma5 := MA(C,5)
ma10 = MA(C,10)
ma20 = MA(C,20)
ma60 = MA(C,60)
ret1 = (C - C[1])/C[1]
ret2 = (C - C[1])/C[1] > 0.05
info = getstockinfo(0)
if ma60[-1] < ma20[-1] and ma20[-1] < ma10[-1] and ma10[-1] < ma5[-1] and ret2 :
print(info,ret1*100)
endp
print("计算完成")
"""
testblock1 =\
"""
a,b,c = MACD(C)
a = 1
e = C[1]
Kl.date('2021-10-01','2022-05-22')
print(str(e)+":"+str(1))
"""
Kexec(testblock1)
print(a)
Kexec("""\n
kloop
info = getstockinfo(0)
istran = TRANSVERSE(H,L,60,15)
if istran:
print(info,istran)
endp
""")
while True:
# 通过Klang谁知一个变量
Kexec("ABCD=pi+1;")
s = input("Kl:>")
if s == "quit":
break
Kexec(s+";")
#python里获取klang设置的变量值
print(ABCD)