-
Notifications
You must be signed in to change notification settings - Fork 84
/
iq.py
118 lines (91 loc) · 3.36 KB
/
iq.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
# -*- coding: utf-8 -*-
"""
Spyder Editor
Este é um arquivo de script temporário.
"""
import logging
import time
from iqoptionapi.stable_api import IQ_Option
import pandas as pd
def login(verbose = False, iq = None, checkConnection = False):
if verbose:
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
if iq == None:
print("Trying to connect to IqOption")
iq=IQ_Option('USERNAME','PASSWORD') # YOU HAVE TO ADD YOUR USERNAME AND PASSWORD
iq.connect()
if iq != None:
while True:
if iq.check_connect() == False:
print('Error when trying to connect')
print(iq)
print("Retrying")
iq.connect()
else:
if not checkConnection:
print('Successfully Connected!')
break
time.sleep(3)
iq.change_balance("PRACTICE") #or real
return iq
def higher(iq,Money,Actives):
done,id = iq.buy(Money,Actives,"call",1)
if not done:
print('Error call')
print(done, id)
exit(0)
return id
def lower(iq,Money,Actives):
done,id = iq.buy(Money,Actives,"put",1)
if not done:
print('Error put')
print(done, id)
exit(0)
return id
def get_candles(iq,Actives):
login(iq = iq, checkConnection = True)
return iq.get_candles(Actives, 60, 1000, time.time())
def get_all_candles(iq,Actives,start_candle):
#demora um minuto
final_data = []
for x in range(1):
login(iq = iq, checkConnection = True)
data = iq.get_candles(Actives, 60, 1000, start_candle)
start_candle = data[0]['to']-1
final_data.extend(data)
return final_data
def get_data_needed(iq): #function to gather all the data
start_candle = time.time()
actives = ['EURUSD','GBPUSD','EURJPY','AUDUSD']
final_data = pd.DataFrame()
for active in actives:
current = get_all_candles(iq,active,start_candle)
main = pd.DataFrame()
useful_frame = pd.DataFrame()
for candle in current:
useful_frame = pd.DataFrame(list(candle.values()),index = list(candle.keys())).T.drop(columns = ['at'])
useful_frame = useful_frame.set_index(useful_frame['id']).drop(columns = ['id'])
main = main.append(useful_frame)
main.drop_duplicates()
if active == 'EURUSD':
final_data = main.drop(columns = {'from','to'})
else:
main = main.drop(columns = {'from','to','open','min','max'})
main.columns = [f'close_{active}',f'volume_{active}']
final_data = final_data.join(main)
final_data = final_data.loc[~final_data.index.duplicated(keep = 'first')]
return final_data
def fast_data(iq,ratio): #function to gather reduced data for the testing
login(iq = iq, checkConnection = True)
candles = iq.get_candles(ratio,60,300,time.time())
useful_frame = pd.DataFrame()
main = pd.DataFrame()
for candle in candles:
useful_frame = pd.DataFrame(list(candle.values()),index = list(candle.keys())).T.drop(columns = ['at'])
useful_frame = useful_frame.set_index(useful_frame['id']).drop(columns = ['id'])
main = main.append(useful_frame)
return main
def get_balance(iq):
return iq.get_balance()
def get_profit(iq):
return iq.get_all_profit()['EURUSD']['turbo']