forked from andpena/FinancialData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartConnMktTryd.py
46 lines (40 loc) · 1.44 KB
/
StartConnMktTryd.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
import socket
import win32api
import TypeDataTryd as tdt
from MarketData.OutputMarketData import OutputMarketData
#---ESCOLHER O ATIVO EXEMPLO:-----------#
# PETR4 - Petrobras
# VALE3 - Vale
# ITUB4 - Itau
# INDQ19 - Indice Bovespa
# WINQ19 - Mini Indice Bovespa
#========================================#
ATIVO = ['PETR4','VALE3','ITUB4','BBAS3','CIEL3']
#ATIVO = ['DOLU19']
#========================================#
#---INFORMACOES DO SERVIDOR--------------#
#========================================#
HOST = '127.0.0.1'
PORT = 12002
#========================================#
def ByteConvert(dataInfo, ativo):
return str.encode(dataInfo + ativo + '#')
#Inicia a Execução
oMkt = OutputMarketData()
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
print("Id da thread principal %d" % (win32api.GetCurrentThreadId()))
while True:
arrInfo = []
try:
for item in ATIVO:
s.sendall(ByteConvert(tdt.COTACAO,item) )
data = s.recv(32768)
#Acumulando os ativos
arrInfo.append(data.decode().replace("COT!","").split("|"))
oMkt.OutputData(arrInfo, ATIVO)
except Exception as ex:
print(ex)
except Exception as ex:
print('Não foi possivel conectar no servidor RTD. Erro: ', ex)