-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrow.py
149 lines (148 loc) · 5.51 KB
/
drow.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import asyncio
import os
from datetime import timedelta
from tinkoff.invest import AsyncClient, CandleInterval
from tinkoff.invest.utils import now
import matplotlib.pyplot as plt
candels_g = []
candels_r = []
candels_k = []
nomers_g = []
nomers_r = []
nomers_k = []
candels = []
cans = []
take_profit = 0.058
stop_los = 1.18
nomer=0
pos = 1
plt.ion()
TOKEN = ""
async def main():
global nomer
global pos
global otkitie
global nomers_g
global nomers_r
global nomers_k
global candels_g
global candels_r
global candels_k
global cans
async with AsyncClient(TOKEN) as client:
async for candle in client.get_all_candles(
#id акции
figi="BBG000B9XRY4",
#время
from_=now() - timedelta(days=10),
#промежуток
interval=CandleInterval.CANDLE_INTERVAL_5_MIN,
):
#вывод
low = float(candle.low.units)+(float(candle.low.nano)*0.000000001)
hight = float(candle.high.units)+(float(candle.high.nano)*0.000000001)
cena = low+((hight-low)/2)
candels.append(cena)
if take_profit>stop_los:
if nomer ==0:
otkitie = candels[0]
plt.plot([0], [candels[0]], 'ro',color="k")
if pos ==1:
if cena <= otkitie-stop_los:
#g продажа на повышение
nomers_g.append(nomer)
candels_g.append(cena)
pos =2
if cena >= otkitie+stop_los:
#r продажа на понижение
nomers_r.append(nomer)
candels_r.append(cena)
pos =3
if pos ==2:
#k продать на понижение
if cena <= otkitie-take_profit:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("+")
elif cena >= otkitie+stop_los:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("-")
#k продать на повыщение
if pos ==3:
if cena >= otkitie+take_profit:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("+")
elif cena <= otkitie-stop_los:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("-")
elif take_profit<stop_los:
if nomer ==0:
otkitie = candels[0]
plt.plot([0], [candels[0]], 'ro',color="k")
if pos ==1:
if cena >= otkitie+take_profit:
#g продажа на повышение
nomers_g.append(nomer)
candels_g.append(cena)
pos =2
if cena <= otkitie-take_profit:
#r продажа на понижение
nomers_r.append(nomer)
candels_r.append(cena)
pos =3
if pos ==2:
#k продать на понижение
if cena <= otkitie-take_profit:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("+")
elif cena >= otkitie+stop_los:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("-")
#k продать на повыщение
if pos ==3:
if cena >= otkitie+take_profit:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("+")
elif cena <= otkitie-stop_los:
nomers_k.append(nomer)
candels_k.append(cena)
pos =1
otkitie=cena
print("-")
plt.clf()
plt.plot(nomers_g, candels_g,'ro',color='g')
plt.plot(nomers_r, candels_r,'ro',color='r')
plt.plot(nomers_k, candels_k,'ro',color='k')
plt.plot(candels)
plt.draw()
plt.gcf().canvas.flush_events()
nomer+=1
if __name__ == "__main__":
asyncio.run(main())
#plt.axhline(y=(otkitie-mal),color="r")
#plt.axhline(y=(otkitie+mal),color="b")
#plt.axhline(y=(otkitie-bol),color="b")
#plt.axhline(y=(otkitie+bol),color="r")
#plt.axhline(y=(otkitie),color="k")
plt.ioff()
plt.show()