ls증권 히스토리 구독 넣음
This commit is contained in:
63
sample_python/tr/k3_real.py
Normal file
63
sample_python/tr/k3_real.py
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
|
||||
#코스닥임
|
||||
class XReal_K3_:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def OnReceiveRealData(self, tr_code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
# self.count += 1
|
||||
stock_code = self.GetFieldData("OutBlock", "shcode")
|
||||
# chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
price = int(self.GetFieldData("OutBlock", "price"))
|
||||
|
||||
if stock_code is not None and price is not None:
|
||||
self.process_balance_change(stock_code,price)
|
||||
|
||||
# open = int(self.GetFieldData("OutBlock", "open"))
|
||||
# drate = float(self.GetFieldData("OutBlock", "drate"))
|
||||
#print('코스닥 코드: ',stock_code)
|
||||
# # #print('drate: ',drate)
|
||||
# # #print('chetime: ',chetime)
|
||||
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
# volume = int(self.GetFieldData("OutBlock", "cvolume"))#cvolume이 체결거래량이고 그냥 볼륨은 누적거래량임
|
||||
# accu_volume = int(self.GetFieldData("OutBlock", "volume"))#누적거래대금
|
||||
# value = int(self.GetFieldData("OutBlock", "value"))#누적거래대금
|
||||
# side = self.GetFieldData("OutBlock", "cgubun")
|
||||
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,stock_code):
|
||||
#print('코스닥 리얼 스타트: ',stock_code)
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')+"\\Res\\K3_.res"
|
||||
self.ResFileName = the_path # RES 파일 등록
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\K3_.res" # RES 파일 등록
|
||||
self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
63
sample_python/tr/s3_real.py
Normal file
63
sample_python/tr/s3_real.py
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
#XReal_S3_
|
||||
class XReal_S3_:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.count = 0
|
||||
# self.tr_0424=tr_0424
|
||||
|
||||
def OnReceiveRealData(self, tr_code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
shcode = self.GetFieldData("OutBlock", "shcode")
|
||||
price = self.GetFieldData("OutBlock", "price")
|
||||
|
||||
if shcode is not None and price is not None:
|
||||
self.process_balance_change(shcode,price)
|
||||
|
||||
# chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
# print('코스피 코드: ',shcode)
|
||||
# print('price: ',price)
|
||||
# #print('chetime: ',chetime)
|
||||
# self.continue_draw_balance_table()
|
||||
|
||||
|
||||
|
||||
def initialize_continue_draw_balance_table(self,continue_draw_balance_table):
|
||||
#print('s3 initialize_continue_draw_balance_table @#@#@#@#@#@#@#')
|
||||
self.continue_draw_balance_table=continue_draw_balance_table
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('s3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,stock_code):
|
||||
#print('코스피 리얼 스타트: ',stock_code)
|
||||
# #print('왜 자꾸 콜하는겨')
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')+"\\Res\\S3_.res"
|
||||
self.ResFileName = the_path # RES 파일 등록
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\S3_.res" # RES 파일 등록
|
||||
|
||||
self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
813
sample_python/tr/tr_0424.py
Normal file
813
sample_python/tr/tr_0424.py
Normal file
@@ -0,0 +1,813 @@
|
||||
#XAQueryEvents
|
||||
|
||||
|
||||
from tr.k3_real import XReal_K3_
|
||||
from tr.s3_real import XReal_S3_
|
||||
from tr.tr_kh import XReal_KH_
|
||||
import math
|
||||
|
||||
# from test import Test
|
||||
|
||||
# test=Test()
|
||||
import win32com.client #이베스트 관련
|
||||
import pythoncom #이베스트 관련
|
||||
# from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.schedulers.qt import QtScheduler
|
||||
from tr.tr_sc1 import Tr_sc1
|
||||
from tr.tr_sc2 import Tr_sc2
|
||||
|
||||
from tr.tr_sc0 import Tr_sc0
|
||||
from tr.tr_sc3 import Tr_sc3
|
||||
|
||||
# from tr.tr_pending import Tr_pending
|
||||
# tr_pending=Tr_pending()
|
||||
|
||||
from tr.tr_master import Tr_master
|
||||
tr_master=Tr_master()
|
||||
|
||||
import json
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
load_dotenv()
|
||||
class Tr_0424:
|
||||
|
||||
# account=os.environ.get('ACCOUNT')
|
||||
# pw=os.environ.get('PW')
|
||||
master_arr=[]
|
||||
master_dict={}
|
||||
query_state = False
|
||||
|
||||
the_balance={}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.xreal = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", XReal_S3_)
|
||||
self.xreal_daq = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", XReal_K3_)
|
||||
|
||||
#프로그램 테스트
|
||||
# self.pro_kh = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", XReal_KH_)
|
||||
|
||||
#프로그램 테스트 끝
|
||||
|
||||
|
||||
|
||||
self.xreal.initialize_process_balance_change(self.process_balance_change)
|
||||
self.xreal.initialize_continue_draw_balance_table(self.continue_draw_balance_table)
|
||||
self.xreal_daq.initialize_process_balance_change(self.process_balance_change)
|
||||
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
self.pw=os.environ.get('PW')
|
||||
|
||||
# scheduler = QtScheduler()
|
||||
# scheduler.add_job(self.yeah, 'interval', seconds=5)
|
||||
# scheduler.start()
|
||||
|
||||
# async_scheduler = AsyncIOScheduler()
|
||||
# async_scheduler.add_job(self.yeah(), 'cron', second='*/3',args=[])
|
||||
# async_scheduler.start()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def init_sc1(self):
|
||||
|
||||
self.sc0_real = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", Tr_sc0)
|
||||
self.sc0_real.start(self.process_pending_change_echo)
|
||||
|
||||
self.sc1_real = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", Tr_sc1)
|
||||
self.sc1_real.start(self.process_balance_change_echo)
|
||||
|
||||
self.sc2_real = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", Tr_sc2)
|
||||
self.sc2_real.start()
|
||||
|
||||
self.sc3_real = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", Tr_sc3)
|
||||
self.sc3_real.start(self.process_pending_cancel_echo)
|
||||
|
||||
|
||||
|
||||
|
||||
# def process_pending_fix_echo(self,orgordno,ord_qty,ord_price):
|
||||
|
||||
|
||||
|
||||
def process_pending_cancel_echo(self,orgordno,volume):
|
||||
|
||||
|
||||
the_pending_list_j=os.environ.get('the_pending_list')
|
||||
the_pending_list=json.loads(the_pending_list_j)
|
||||
|
||||
|
||||
for i,obj in enumerate( the_pending_list):
|
||||
|
||||
|
||||
if obj['ord_no']==orgordno:
|
||||
# print('ord_qty: ',obj['ord_qty'])
|
||||
# print('volume: ',volume)
|
||||
if int(obj['ord_qty']) == int(volume):
|
||||
|
||||
# print('왜 안지우냐: ',i)
|
||||
|
||||
self.balance_window.remove_row_on_pending_table(i)
|
||||
old_length=int(os.environ.get('the_pending_list_length'))
|
||||
#미체결 길이 다시 설정
|
||||
os.environ['the_pending_list_length']=str(old_length-1)
|
||||
|
||||
del the_pending_list[i]
|
||||
os.environ['the_pending_list']=json.dumps(the_pending_list)
|
||||
|
||||
else:
|
||||
new_qty=int(obj['ord_qty'])-int(volume)
|
||||
obj['ord_qty']=new_qty
|
||||
os.environ['the_pending_list']=json.dumps(the_pending_list)
|
||||
|
||||
self.balance_window.set_value_on_pending_table(4,i,new_qty)
|
||||
|
||||
|
||||
def process_pending_change_echo(self,ord_no, ord_qty, ord_price, stock_code, stock_name,side,orgordno,OrdTrxPtnNm):
|
||||
|
||||
|
||||
the_pending_list_j=os.environ.get('the_pending_list')
|
||||
new_pending_list=json.loads(the_pending_list_j)
|
||||
|
||||
obj={
|
||||
"ord_no":ord_no,
|
||||
"ord_qty":ord_qty,
|
||||
"ord_price":int(float(ord_price)),
|
||||
"stock_code":stock_code,
|
||||
"stock_name":stock_name
|
||||
}
|
||||
|
||||
# obj={
|
||||
# "ord_no":ord_no,
|
||||
# "ord_qty":ord_qty,
|
||||
# "ord_price":int(float(ord_price)),
|
||||
# "stock_code":stock_code_from_master,
|
||||
# "stock_name":stock_name,
|
||||
# 'side':side,
|
||||
# 'OrgOrdNo':OrgOrdNo,
|
||||
# 'OrdTrxPtnNm':OrdTrxPtnNm
|
||||
# }
|
||||
|
||||
|
||||
new_pending_list.append(obj)
|
||||
|
||||
|
||||
os.environ['the_pending_list']=json.dumps(new_pending_list)
|
||||
new_index=int(os.environ.get('the_pending_list_length'))
|
||||
|
||||
|
||||
|
||||
self.balance_window.insert_row_on_pending_table()
|
||||
self.balance_window.set_value_on_pending_table(0,new_index,ord_no )
|
||||
self.balance_window.set_value_on_pending_table(1,new_index,stock_name )
|
||||
self.balance_window.set_value_on_pending_table(2,new_index,side)
|
||||
self.balance_window.set_value_on_pending_table(3,new_index,stock_code)
|
||||
self.balance_window.set_value_on_pending_table(4,new_index,ord_qty)
|
||||
self.balance_window.set_value_on_pending_table(5,new_index,ord_price)
|
||||
self.balance_window.set_value_on_pending_table(6,new_index,orgordno)
|
||||
self.balance_window.set_value_on_pending_table(7,new_index,OrdTrxPtnNm)
|
||||
|
||||
|
||||
if OrdTrxPtnNm=='정정확인':
|
||||
the_pending_list_j=os.environ.get('the_pending_list')
|
||||
the_pending_list=json.loads(the_pending_list_j)
|
||||
|
||||
for i,obj in enumerate( the_pending_list):
|
||||
|
||||
|
||||
if obj['ord_no']==orgordno:
|
||||
if int(obj['ord_qty']) <= int(ord_qty):
|
||||
|
||||
self.balance_window.remove_row_on_pending_table(i)
|
||||
old_length=int(os.environ.get('the_pending_list_length'))
|
||||
#미체결 길이 다시 설정
|
||||
os.environ['the_pending_list_length']=str(old_length-1)
|
||||
del the_pending_list[i]
|
||||
|
||||
else:
|
||||
new_qty=int(obj['ord_qty'])-int(ord_qty)
|
||||
|
||||
obj['ord_qty']=new_qty
|
||||
|
||||
self.balance_window.set_value_on_pending_table(4,i,new_qty)
|
||||
|
||||
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
#미체결 길이 다시 설정
|
||||
os.environ['the_pending_list_length']=str(new_index+1)
|
||||
|
||||
|
||||
def process_balance_change_echo(self,stock_code,volume,side,contract_price,stock_name,ord_no_input):
|
||||
|
||||
the_dict=self.the_balance.get(stock_code,None)
|
||||
|
||||
if the_dict is not None:
|
||||
the_index=self.the_balance[stock_code]['the_index']
|
||||
|
||||
pamt=int(self.the_balance[stock_code]['pamt'])#평단가임
|
||||
mamt=int(self.the_balance[stock_code]['mamt'])#매입금액
|
||||
janqty=int(self.the_balance[stock_code]['janqty'])#수량임
|
||||
appamt=int(self.the_balance[stock_code]['appamt'])#평가금액
|
||||
# sunikrt=int(self.the_balance[stock_code]['sunikrt'])#수익률
|
||||
dtsunik=int(self.the_balance[stock_code]['dtsunik'])
|
||||
|
||||
|
||||
|
||||
|
||||
sunikrt=format((int(contract_price)/pamt)*100-100," .2f") #수익률 계산
|
||||
|
||||
if side ==1:
|
||||
janqty=janqty-volume
|
||||
new_pamt=pamt
|
||||
mamt=mamt-(volume*pamt) #새 매입금액
|
||||
elif side==2:
|
||||
# new_pamt=((janqty*pamt) + (volume*contract_price)) / janqty+volume #새 평단가
|
||||
cal1=janqty*pamt
|
||||
cal2=volume*contract_price
|
||||
cal3=cal1+cal2
|
||||
cal4=janqty+volume
|
||||
new_pamt=math.floor( cal3/cal4)
|
||||
|
||||
|
||||
mamt=mamt+(volume*contract_price) #새 매입금액
|
||||
sunikrt=format((int(contract_price)/new_pamt)*100-100," .2f") #새 수익률 계산
|
||||
|
||||
|
||||
janqty=janqty+volume
|
||||
|
||||
|
||||
eval_profit=(int(contract_price)-new_pamt)*janqty#현재가랑 평단가 뺀거에 수량 곱하면 평가손익 됨
|
||||
|
||||
|
||||
eval_profit_diff=eval_profit-dtsunik#이전 평가손익이랑 얼만큼 차이나는지
|
||||
|
||||
new_eval_price=appamt+eval_profit_diff#새 평가금액
|
||||
|
||||
|
||||
if janqty>0:
|
||||
|
||||
self.the_balance[stock_code]['janqty']=janqty
|
||||
|
||||
|
||||
try:
|
||||
# self.the_balance[stock_code]={
|
||||
# 'stock_name':stock_name,
|
||||
# 'stock_code':stock_code,
|
||||
# 'the_index':new_index,
|
||||
# 'pamt':contract_price,
|
||||
# 'mamt':volume*contract_price,
|
||||
# 'janqty':volume,
|
||||
# 'appamt':volume*contract_price,
|
||||
# 'sunikrt':0
|
||||
# }
|
||||
|
||||
self.the_balance[stock_code]['pamt']=new_pamt
|
||||
self.the_balance[stock_code]['mamt']=mamt
|
||||
self.the_balance[stock_code]['janqty']=janqty
|
||||
self.the_balance[stock_code]['appamt']=new_eval_price
|
||||
self.the_balance[stock_code]['sunikrt']=sunikrt
|
||||
self.the_balance[stock_code]['dtsunik']=0
|
||||
|
||||
|
||||
self.balance_window.set_value_on_stocks_table(2,the_index,janqty)
|
||||
self.balance_window.set_value_on_stocks_table(3,the_index,new_pamt)
|
||||
self.balance_window.set_value_on_stocks_table(4,the_index,contract_price)
|
||||
self.balance_window.set_value_on_stocks_table(5,the_index,mamt)
|
||||
self.balance_window.set_value_on_stocks_table(6,the_index,new_eval_price)
|
||||
self.balance_window.set_value_on_stocks_table(7,the_index,sunikrt)
|
||||
|
||||
except Exception as e:
|
||||
#print('process_balance_change_echo err: ',e)
|
||||
pass
|
||||
|
||||
else:
|
||||
remove_res=self.remove_from_the_balance(stock_code)
|
||||
|
||||
if remove_res is None:
|
||||
return
|
||||
|
||||
|
||||
else:
|
||||
|
||||
try:
|
||||
if side==2:
|
||||
#잔고에 없고 신규 매수일 때
|
||||
|
||||
# self.balance_window.insert_row_on_stocks_table()
|
||||
|
||||
new_index=len(self.the_balance)+1
|
||||
# self.balance_window.set_value_on_stocks_table(0,new_index-1,stock_name)
|
||||
|
||||
the_dict_from_master=tr_master.master_dict.get(stock_code,{})
|
||||
|
||||
if the_dict_from_master['gubun']=='1':
|
||||
self.xreal.start(stock_code)
|
||||
elif the_dict_from_master['gubun']=='2':
|
||||
self.xreal_daq.start(stock_code)
|
||||
|
||||
self.the_balance[stock_code]={
|
||||
'stock_name':stock_name,
|
||||
'stock_code':stock_code,
|
||||
'the_index':new_index-1,
|
||||
'pamt':contract_price,
|
||||
'mamt':volume*contract_price,
|
||||
'janqty':volume,
|
||||
'appamt':volume*contract_price,
|
||||
'sunikrt':0,
|
||||
'dtsunik':0
|
||||
}
|
||||
|
||||
self.insert_to_the_balance(stock_code,stock_name,new_index)
|
||||
|
||||
# self.get_account()
|
||||
|
||||
|
||||
except Exception as e:
|
||||
#print('process_balance_change_echo2 err: ',e)
|
||||
pass
|
||||
|
||||
|
||||
#미체결 그리드 지우기
|
||||
the_pending_list_j=os.environ.get('the_pending_list')
|
||||
the_pending_list=json.loads(the_pending_list_j)
|
||||
|
||||
for i,obj in enumerate( the_pending_list):
|
||||
|
||||
# print('들어온거@@ obj: ',obj)
|
||||
|
||||
if obj['ord_no']==ord_no_input:
|
||||
if int(obj['ord_qty']) <= int(volume):
|
||||
|
||||
self.balance_window.remove_row_on_pending_table(i)
|
||||
old_length=int(os.environ.get('the_pending_list_length'))
|
||||
#미체결 길이 다시 설정
|
||||
os.environ['the_pending_list_length']=str(old_length-1)
|
||||
del the_pending_list[i]
|
||||
|
||||
else:
|
||||
new_qty=int(obj['ord_qty'])-int(volume)
|
||||
|
||||
obj['ord_qty']=new_qty
|
||||
|
||||
self.balance_window.set_value_on_pending_table(4,i,new_qty)
|
||||
|
||||
|
||||
break
|
||||
|
||||
|
||||
#미체결 리스트 다시 설정
|
||||
os.environ['the_pending_list']=json.dumps(the_pending_list)
|
||||
|
||||
|
||||
|
||||
|
||||
# tdtsunik=int(self.the_balance['total']['tdtsunik'])
|
||||
# new_tdtsunik=tdtsunik+eval_profit_diff
|
||||
# self.the_balance['total']['tdtsunik']=new_tdtsunik
|
||||
|
||||
def process_balance_change(self,stock_code,price):
|
||||
|
||||
# #print('process balance change: ',self.balance_window)
|
||||
|
||||
the_index=self.the_balance[stock_code]['the_index']
|
||||
# #print('the_index: ',the_index)
|
||||
|
||||
# if stock_code=='000660':
|
||||
# #print('self.the_balance: ',self.the_balance)
|
||||
# #print('the_index: ',the_index)
|
||||
|
||||
pamt=int(self.the_balance[stock_code]['pamt'])#평단가임
|
||||
mamt=int(self.the_balance[stock_code]['mamt'])#매입금액
|
||||
janqty=int(self.the_balance[stock_code]['janqty'])#수량임
|
||||
appamt=int(self.the_balance[stock_code]['appamt'])#평가금액
|
||||
# sunikrt=int(self.the_balance[stock_code]['sunikrt'])#수익률
|
||||
dtsunik=int(self.the_balance[stock_code]['dtsunik'])
|
||||
|
||||
eval_profit=(int(price)-pamt)*janqty#현재가랑 평단가 뺀거에 수량 곱하면 평가손익 됨
|
||||
|
||||
eval_profit_diff=eval_profit-dtsunik#이전 평가손익이랑 얼만큼 차이나는지
|
||||
|
||||
new_eval_price=appamt+eval_profit_diff#새 평가금액
|
||||
|
||||
|
||||
sunikrt=format((int(price)/pamt)*100-100," .2f") #수익률 계산
|
||||
|
||||
# #print('@@평단가: ',pamt)
|
||||
# #print('@@매입금액: ',mamt)
|
||||
# #print('@@평가금액: ',appamt)
|
||||
# #print('@@평가손익: ',eval_profit)
|
||||
# #print('@@new_eval_price: ',new_eval_price)
|
||||
# #print('@@sunikrt: ',sunikrt)
|
||||
|
||||
try:
|
||||
self.balance_window.set_value_on_stocks_table(2,the_index,janqty)
|
||||
self.balance_window.set_value_on_stocks_table(3,the_index,pamt)
|
||||
self.balance_window.set_value_on_stocks_table(4,the_index,price)
|
||||
self.balance_window.set_value_on_stocks_table(5,the_index,mamt)
|
||||
self.balance_window.set_value_on_stocks_table(6,the_index,new_eval_price)
|
||||
self.balance_window.set_value_on_stocks_table(7,the_index,sunikrt)
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
# tdtsunik=int(self.the_balance['total']['tdtsunik'])
|
||||
# new_tdtsunik=tdtsunik+eval_profit_diff
|
||||
# self.the_balance['total']['tdtsunik']=new_tdtsunik
|
||||
|
||||
def continue_draw_balance_table(self):
|
||||
#print('self.the_balance: ',self.the_balance)
|
||||
|
||||
for i,key in enumerate( self.the_balance):
|
||||
try:
|
||||
stock_name=self.the_balance[key]['stock_name']
|
||||
stock_code=self.the_balance[key]['stock_code']
|
||||
janqty=self.the_balance[key]['janqty']
|
||||
pamt=self.the_balance[key]['pamt']
|
||||
price=self.the_balance[key]['price']
|
||||
mamt=self.the_balance[key]['mamt']
|
||||
appamt=self.the_balance[key]['appamt']
|
||||
sunikrt=self.the_balance[key]['sunikrt']
|
||||
|
||||
self.balance_window.insert_row_on_stocks_table()
|
||||
|
||||
self.balance_window.set_value_on_stocks_table(0,i,stock_name)
|
||||
self.balance_window.set_value_on_stocks_table(1,i,stock_code)
|
||||
self.balance_window.set_value_on_stocks_table(2,i,janqty)
|
||||
self.balance_window.set_value_on_stocks_table(3,i,pamt)
|
||||
self.balance_window.set_value_on_stocks_table(4,i,price)
|
||||
self.balance_window.set_value_on_stocks_table(5,i,mamt)
|
||||
self.balance_window.set_value_on_stocks_table(6,i,appamt)
|
||||
self.balance_window.set_value_on_stocks_table(7,i,sunikrt)
|
||||
|
||||
# #print('업뎃한거임?')
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def init_draw_balance_table(self,balance_window):
|
||||
self.balance_window=balance_window
|
||||
#print('init_draw_balance_table: ',self.the_balance)
|
||||
|
||||
for i,key in enumerate( self.the_balance):
|
||||
try:
|
||||
stock_name=self.the_balance[key]['stock_name']
|
||||
stock_code=self.the_balance[key]['stock_code']
|
||||
janqty=self.the_balance[key]['janqty']
|
||||
pamt=self.the_balance[key]['pamt']
|
||||
price=self.the_balance[key]['price']
|
||||
mamt=self.the_balance[key]['mamt']
|
||||
appamt=self.the_balance[key]['appamt']
|
||||
sunikrt=self.the_balance[key]['sunikrt']
|
||||
|
||||
self.balance_window.insert_row_on_stocks_table()
|
||||
|
||||
self.balance_window.set_value_on_stocks_table(0,i,stock_name)
|
||||
self.balance_window.set_value_on_stocks_table(1,i,stock_code)
|
||||
self.balance_window.set_value_on_stocks_table(2,i,janqty)
|
||||
self.balance_window.set_value_on_stocks_table(3,i,pamt)
|
||||
self.balance_window.set_value_on_stocks_table(4,i,price)
|
||||
self.balance_window.set_value_on_stocks_table(5,i,mamt)
|
||||
self.balance_window.set_value_on_stocks_table(6,i,appamt)
|
||||
self.balance_window.set_value_on_stocks_table(7,i,sunikrt)
|
||||
|
||||
|
||||
the_dict=tr_master.master_dict.get(stock_code,{})
|
||||
#print('the_dict: ',the_dict)
|
||||
|
||||
if the_dict['gubun']=='1':
|
||||
self.xreal.start(stock_code)
|
||||
|
||||
|
||||
elif the_dict['gubun']=='2':
|
||||
self.xreal_daq.start(stock_code)
|
||||
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def OnReceiveData(self, tr_code):
|
||||
# Tr_0424.query_state = True
|
||||
block_count=self.GetBlockCount("t0424OutBlock1")
|
||||
# #print('ACCOUNT @@ block_count: ',block_count)
|
||||
|
||||
# sunamt = self.GetFieldData("t0424OutBlock", "sunamt", 0).strip()
|
||||
# dtsunik = self.GetFieldData("t0424OutBlock", "dtsunik", 0).strip()
|
||||
# mamt = self.GetFieldData("t0424OutBlock", "mamt", 0).strip()
|
||||
# sunamt1 = self.GetFieldData("t0424OutBlock", "sunamt1", 0).strip()
|
||||
# cts_expcode = self.GetFieldData("t0424OutBlock", "cts_expcode", 0).strip()
|
||||
# tappamt = self.GetFieldData("t0424OutBlock", "tappamt", 0).strip()
|
||||
# tdtsunik = self.GetFieldData("t0424OutBlock", "tdtsunik", 0).strip()
|
||||
|
||||
# #print('sunamt: ',sunamt)
|
||||
# self.balance_window.set_value_on_table(0,sunamt)
|
||||
# self.balance_window.set_value_on_table(1,dtsunik)
|
||||
# self.balance_window.set_value_on_table(2,mamt)
|
||||
# self.balance_window.set_value_on_table(3,tappamt)
|
||||
# self.balance_window.set_value_on_table(4,tdtsunik)
|
||||
# self.balance_window.set_value_on_table(5,99)
|
||||
|
||||
# self.the_balance['total']={
|
||||
# 'sunamt':sunamt,
|
||||
# 'dtsunik':dtsunik,
|
||||
# 'mamt':mamt,
|
||||
# 'tappamt':tappamt,
|
||||
# 'tdtsunik':tdtsunik,
|
||||
# 'profit':99
|
||||
|
||||
|
||||
# }
|
||||
|
||||
# self.test_ui_class.set_the_stock_code(sunamt)
|
||||
# self.xreal.start('005930')
|
||||
|
||||
|
||||
if block_count is None:
|
||||
return
|
||||
|
||||
|
||||
for i in range(block_count):
|
||||
stock_code = self.GetFieldData("t0424OutBlock1", "expcode", i).strip()
|
||||
|
||||
jangb = self.GetFieldData("t0424OutBlock1", "jangb", i).strip()#잔고구분
|
||||
|
||||
janqty = self.GetFieldData("t0424OutBlock1", "janqty", i).strip()#잔고수량
|
||||
pamt = self.GetFieldData("t0424OutBlock1", "pamt", i).strip()#평단가
|
||||
mamt = self.GetFieldData("t0424OutBlock1", "mamt", i).strip()#매입금액
|
||||
stock_name = self.GetFieldData("t0424OutBlock1", "hname", i).strip()#종목명
|
||||
price = self.GetFieldData("t0424OutBlock1", "price", i).strip()#현재가
|
||||
appamt = self.GetFieldData("t0424OutBlock1", "appamt", i).strip()#평가금액
|
||||
dtsunik = self.GetFieldData("t0424OutBlock1", "dtsunik", i).strip()#평가손익
|
||||
sunikrt = self.GetFieldData("t0424OutBlock1", "sunikrt", i).strip()#수익율
|
||||
|
||||
|
||||
if (stock_code is not None and
|
||||
janqty is not None and
|
||||
pamt is not None and
|
||||
mamt is not None and
|
||||
stock_name is not None and
|
||||
price is not None and
|
||||
appamt is not None and
|
||||
dtsunik is not None and
|
||||
sunikrt is not None):
|
||||
|
||||
|
||||
self.the_balance[stock_code]={
|
||||
'stock_name':stock_name,
|
||||
'stock_code':stock_code,
|
||||
'janqty':janqty,
|
||||
'pamt':pamt,
|
||||
'price':price,
|
||||
'mamt':mamt,
|
||||
'appamt':appamt,
|
||||
'sunikrt':sunikrt,
|
||||
'the_index':i,
|
||||
'dtsunik':dtsunik
|
||||
}
|
||||
|
||||
#print('@@@@self.the_balance: ',self.the_balance)
|
||||
# #print('@@@@self.balance_window: ',self.balance_window)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for i in range(block_count):
|
||||
stock_code = self.GetFieldData("t0424OutBlock1", "expcode", i).strip()
|
||||
janqty = self.GetFieldData("t0424OutBlock1", "janqty", i).strip()#잔고수량
|
||||
pamt = self.GetFieldData("t0424OutBlock1", "pamt", i).strip()#평단가
|
||||
mamt = self.GetFieldData("t0424OutBlock1", "mamt", i).strip()#매입금액
|
||||
stock_name = self.GetFieldData("t0424OutBlock1", "hname", i).strip()#종목명
|
||||
price = self.GetFieldData("t0424OutBlock1", "price", i).strip()#현재가
|
||||
appamt = self.GetFieldData("t0424OutBlock1", "appamt", i).strip()#평가금액
|
||||
dtsunik = self.GetFieldData("t0424OutBlock1", "dtsunik", i).strip()#평가손익
|
||||
sunikrt = self.GetFieldData("t0424OutBlock1", "sunikrt", i).strip()#수익율
|
||||
|
||||
|
||||
|
||||
if (stock_code is not None and
|
||||
janqty is not None and
|
||||
pamt is not None and
|
||||
mamt is not None and
|
||||
stock_name is not None and
|
||||
price is not None and
|
||||
appamt is not None and
|
||||
dtsunik is not None and
|
||||
sunikrt is not None):
|
||||
|
||||
# #print('STOCK_NAME: ',stock_name)
|
||||
the_dict=tr_master.master_dict.get(stock_code,{})
|
||||
#print('the loop stock_name: ',stock_name)
|
||||
|
||||
if the_dict['gubun']=='1':
|
||||
self.xreal.start(stock_code)
|
||||
# #프로그램 테스트
|
||||
# self.pro_kh.start('095340')
|
||||
elif the_dict['gubun']=='2':
|
||||
self.xreal_daq.start(stock_code)
|
||||
|
||||
|
||||
# #print('stock_name: ',stock_name)
|
||||
# #print('stock_code: ',stock_code)
|
||||
# #print('janqty: ',janqty)
|
||||
# #print('pamt: ',pamt)
|
||||
# #print('price: ',price)
|
||||
# #print('mamt: ',mamt)
|
||||
# #print('appamt: ',appamt)
|
||||
# #print('sunikrt: ',sunikrt)
|
||||
|
||||
try:
|
||||
balance_check=self.the_balance.get('stock_code',None)
|
||||
|
||||
if balance_check is None:
|
||||
|
||||
self.balance_window.insert_row_on_stocks_table()
|
||||
|
||||
self.balance_window.set_value_on_stocks_table(0,i,stock_name)
|
||||
self.balance_window.set_value_on_stocks_table(1,i,stock_code)
|
||||
self.balance_window.set_value_on_stocks_table(2,i,janqty)
|
||||
self.balance_window.set_value_on_stocks_table(3,i,pamt)
|
||||
self.balance_window.set_value_on_stocks_table(4,i,price)
|
||||
self.balance_window.set_value_on_stocks_table(5,i,mamt)
|
||||
self.balance_window.set_value_on_stocks_table(6,i,appamt)
|
||||
self.balance_window.set_value_on_stocks_table(7,i,sunikrt)
|
||||
|
||||
#print('업뎃한거임?')
|
||||
|
||||
except Exception as e:
|
||||
#print('잔고 업댓 에러: ',e)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
self.the_balance[stock_code]={
|
||||
'stock_name':stock_name,
|
||||
'stock_code':stock_code,
|
||||
'janqty':janqty,
|
||||
'pamt':pamt,
|
||||
'price':price,
|
||||
'mamt':mamt,
|
||||
'appamt':appamt,
|
||||
'sunikrt':sunikrt,
|
||||
'the_index':i,
|
||||
'dtsunik':dtsunik
|
||||
}
|
||||
# #print('@@@@22222self.the_balance: ',self.the_balance)
|
||||
|
||||
|
||||
#print('작업 다 한 것: self.the_balance: ',self.the_balance)
|
||||
|
||||
|
||||
|
||||
# #print('삼전: ',self.master_dict['005930'])
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
# #print('OnReceiveMessage: ',szMessage)
|
||||
pass
|
||||
|
||||
def insert_to_the_balance(self,stock_code,stock_name,new_index):
|
||||
|
||||
try:
|
||||
|
||||
self.balance_window.insert_row_on_stocks_table()
|
||||
|
||||
# new_index=len(self.the_balance)+1
|
||||
#print('머고@#@#@#@#@: ',stock_name)
|
||||
#print('머고@#@#@#@#@2: ',new_index)
|
||||
self.balance_window.set_value_on_stocks_table(0,new_index-1,stock_name)
|
||||
self.balance_window.set_value_on_stocks_table(1,new_index-1,stock_code)
|
||||
self.balance_window.set_value_on_stocks_table(2,new_index-1,self.the_balance[stock_code]['janqty'])
|
||||
self.balance_window.set_value_on_stocks_table(3,new_index-1,self.the_balance[stock_code]['pamt'])
|
||||
self.balance_window.set_value_on_stocks_table(4,new_index-1,self.the_balance[stock_code]['pamt'])
|
||||
self.balance_window.set_value_on_stocks_table(5,new_index-1,self.the_balance[stock_code]['mamt'])
|
||||
self.balance_window.set_value_on_stocks_table(6,new_index-1,self.the_balance[stock_code]['appamt'])
|
||||
self.balance_window.set_value_on_stocks_table(7,new_index-1,0)
|
||||
|
||||
# self.the_balance[stock_code]={
|
||||
# 'stock_name':stock_name,
|
||||
# 'stock_code':stock_code,
|
||||
# 'the_index':new_index,
|
||||
# 'pamt':contract_price,
|
||||
# 'mamt':volume*contract_price,
|
||||
# 'janqty':volume,
|
||||
# 'appamt':volume*contract_price,
|
||||
# 'dtsunik':0
|
||||
# }
|
||||
|
||||
#print('inserted to the balance: ',self.the_balance)
|
||||
|
||||
except Exception as e:
|
||||
#print('remove_from_the_balance err: ',e)
|
||||
pass
|
||||
|
||||
def remove_from_the_balance(self,stock_code):
|
||||
|
||||
try:
|
||||
|
||||
the_index=self.the_balance[stock_code]['the_index']
|
||||
|
||||
self.balance_window.remove_row_on_stocks_table(the_index)
|
||||
|
||||
|
||||
the_dict_from_master=tr_master.master_dict.get(stock_code,{})
|
||||
|
||||
if the_dict_from_master['gubun']=='1':
|
||||
self.xreal.remove_item(stock_code)
|
||||
elif the_dict_from_master['gubun']=='2':
|
||||
self.xreal_daq.remove_item(stock_code)
|
||||
|
||||
|
||||
del self.the_balance[stock_code]
|
||||
|
||||
|
||||
for i,key in enumerate( self.the_balance):
|
||||
self.the_balance[key]['the_index']=i
|
||||
|
||||
#print('removed the balance: ',self.the_balance)
|
||||
|
||||
return 1
|
||||
|
||||
except Exception as e:
|
||||
#print('remove_from_the_balance err: ',e)
|
||||
|
||||
return None
|
||||
|
||||
def init_get_account(self,balance_window):
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t0424.res"
|
||||
self.balance_window=balance_window
|
||||
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
self.pw=os.environ.get('PW')
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\t0424.res"
|
||||
|
||||
self.SetFieldData("t0424InBlock", "accno", 0, self.account)
|
||||
self.SetFieldData("t0424InBlock", "passwd", 0, self.pw)
|
||||
self.SetFieldData("t0424InBlock", "prcgb", 0, '1')
|
||||
self.SetFieldData("t0424InBlock", "chegb", 0, '2')
|
||||
self.SetFieldData("t0424InBlock", "dangb", 0, '0')
|
||||
self.SetFieldData("t0424InBlock", "charge", 0, '0')
|
||||
self.SetFieldData("t0424InBlock", "cts_expcode", 0, ' ')
|
||||
|
||||
#print('계좌 불러옴: ',self.account)
|
||||
|
||||
|
||||
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
|
||||
pass
|
||||
#print("error... {0}".format(err_code))
|
||||
|
||||
# def callback_from_balance_window(self,insert_row_on_stocks_table,set_value_on_stocks_table):
|
||||
# insert_row_on_stocks_table()
|
||||
# self.insert_row_on_stocks_table=insert_row_on_stocks_table
|
||||
# self.set_value_on_stocks_table=set_value_on_stocks_table
|
||||
|
||||
|
||||
def get_account(self):
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t0424.res"
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\t0424.res"
|
||||
|
||||
self.SetFieldData("t0424InBlock", "accno", 0, self.account)
|
||||
self.SetFieldData("t0424InBlock", "passwd", 0, self.pw)
|
||||
self.SetFieldData("t0424InBlock", "prcgb", 0, '1')
|
||||
self.SetFieldData("t0424InBlock", "chegb", 0, '2') #0 결제기준, 2 체결기준
|
||||
self.SetFieldData("t0424InBlock", "dangb", 0, '0')
|
||||
self.SetFieldData("t0424InBlock", "charge", 0, '0')
|
||||
self.SetFieldData("t0424InBlock", "cts_expcode", 0, ' ')
|
||||
|
||||
#print('계좌 불러옴')
|
||||
|
||||
|
||||
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
#print("error... {0}".format(err_code))
|
||||
|
||||
pass
|
||||
245
sample_python/tr/tr_1857.py
Normal file
245
sample_python/tr/tr_1857.py
Normal file
@@ -0,0 +1,245 @@
|
||||
#종목검색
|
||||
class Tr_1857:
|
||||
stock_index_dict={}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.AlertNum=''
|
||||
|
||||
def OnReceiveData(self, code):
|
||||
#print('종목검색 조회#####: ',code)
|
||||
result_count=self.GetBlockCount("t1857OutBlock")
|
||||
|
||||
if result_count is None:
|
||||
return
|
||||
|
||||
AlertNum=self.GetFieldData("t1857OutBlock",'AlertNum',0)
|
||||
if AlertNum is not None:
|
||||
self.AlertNum=AlertNum
|
||||
#print('실시간 키: ',AlertNum)
|
||||
#print('자기소개 Tr_1857: ',dir(self))
|
||||
|
||||
#조회 루프돔
|
||||
for i in range(0,1000):
|
||||
stock_code=self.GetFieldData("t1857OutBlock1", "shcode",i)
|
||||
stock_name=self.GetFieldData("t1857OutBlock1", "hname",i)
|
||||
#현재가
|
||||
price=self.GetFieldData("t1857OutBlock1", "price",i)
|
||||
#전일대비구분
|
||||
sign=self.GetFieldData("t1857OutBlock1", "sign",i)
|
||||
#전일대비
|
||||
change=self.GetFieldData("t1857OutBlock1", "change",i)
|
||||
#등락율
|
||||
diff=self.GetFieldData("t1857OutBlock1", "diff",i)
|
||||
#거래량
|
||||
volume=self.GetFieldData("t1857OutBlock1", "volume",i)
|
||||
|
||||
#N이 진입, R이 재진입, O가 이탈
|
||||
JobFlag=self.GetFieldData("t1857OutBlock1", "JobFlag",i)
|
||||
|
||||
# #print('stock_code: ',JobFlag)
|
||||
|
||||
if stock_code!="":
|
||||
|
||||
self.insert_row_on_stocks_table()
|
||||
self.stock_index_dict[stock_code]=i
|
||||
|
||||
self.set_value_on_table(0,i,stock_name)
|
||||
self.set_value_on_table(1,i,stock_code)
|
||||
self.set_value_on_table(2,i,price)
|
||||
self.set_value_on_table(3,i,change)
|
||||
self.set_value_on_table(4,i,diff)
|
||||
self.set_value_on_table(5,i,volume)
|
||||
|
||||
if JobFlag=='N':
|
||||
# #print('N은 진입이다')
|
||||
self.set_value_on_table(6,i,'진입')
|
||||
elif JobFlag=='R':
|
||||
# #print('R은 재진입이다')
|
||||
self.set_value_on_table(6,i,'재진입')
|
||||
elif JobFlag=='O':
|
||||
# #print('O는 아웃이다')
|
||||
self.set_value_on_table(6,i,'아웃')
|
||||
|
||||
|
||||
|
||||
# stock_name=self.the_master[stock_code]['hname']
|
||||
# gubun=self.the_master[stock_code]['gubun']
|
||||
# #print('stock_name: ',stock_name)
|
||||
# #print('gubun: ',gubun)
|
||||
# if gubun=='1':
|
||||
# xreal.start(stock_code)
|
||||
# elif gubun=='2':
|
||||
# xreal_daq.start(stock_code)
|
||||
# #print('index: ',i)
|
||||
if stock_code=="":
|
||||
break
|
||||
|
||||
|
||||
#print('result_count: ',result_count)
|
||||
# self.go_search('1')
|
||||
|
||||
|
||||
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
#print('nMessageCode: ',nMessageCode)
|
||||
#print('szMessage: ',szMessage)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def init_callbacks(self,set_value_on_table,insert_row_on_stocks_table):
|
||||
self.set_value_on_table=set_value_on_table
|
||||
self.insert_row_on_stocks_table=insert_row_on_stocks_table
|
||||
|
||||
|
||||
def OnReceiveSearchRealData(self, szTrCode):
|
||||
# print('종목검색 리얼@@@@: ',szTrCode)
|
||||
stock_code=self.GetFieldSearchRealData("t1857OutBlock1", "shcode")
|
||||
|
||||
stock_name=self.GetFieldSearchRealData("t1857OutBlock1", "hname")
|
||||
#현재가
|
||||
price=self.GetFieldSearchRealData("t1857OutBlock1", "price")
|
||||
#전일대비구분
|
||||
sign=self.GetFieldSearchRealData("t1857OutBlock1", "sign")
|
||||
#전일대비
|
||||
change=self.GetFieldSearchRealData("t1857OutBlock1", "change")
|
||||
#등락율
|
||||
diff=self.GetFieldSearchRealData("t1857OutBlock1", "diff")
|
||||
#거래량
|
||||
volume=self.GetFieldSearchRealData("t1857OutBlock1", "volume")
|
||||
|
||||
#N이 진입, R이 재진입, O가 이탈
|
||||
JobFlag=self.GetFieldSearchRealData("t1857OutBlock1", "JobFlag")
|
||||
|
||||
|
||||
|
||||
# if JobFlag=='N':
|
||||
# # #print('N은 진입이다')
|
||||
# table_cnt=self.insert_row_on_stocks_table()
|
||||
# self.stock_index_dict[stock_code]=table_cnt
|
||||
|
||||
# self.set_value_on_table(0,table_cnt,stock_name)
|
||||
# self.set_value_on_table(1,table_cnt,stock_code)
|
||||
# self.set_value_on_table(2,table_cnt,price)
|
||||
# self.set_value_on_table(3,table_cnt,change)
|
||||
# self.set_value_on_table(4,table_cnt,diff)
|
||||
# self.set_value_on_table(5,table_cnt,volume)
|
||||
# self.set_value_on_table(6,table_cnt,'진입')
|
||||
|
||||
|
||||
# elif JobFlag=='R':
|
||||
# # #print('R은 재진입이다')
|
||||
# # table_cnt=self.insert_row_on_stocks_table()
|
||||
# # self.stock_index_dict[stock_code]=table_cnt
|
||||
# the_index=self.stock_index_dict.get(stock_code,-1)
|
||||
|
||||
# self.set_value_on_table(0,the_index,''+stock_name)
|
||||
# self.set_value_on_table(1,the_index,stock_code)
|
||||
# self.set_value_on_table(2,the_index,price)
|
||||
# self.set_value_on_table(3,the_index,change)
|
||||
# self.set_value_on_table(4,the_index,diff)
|
||||
# self.set_value_on_table(5,the_index,volume)
|
||||
# self.set_value_on_table(6,the_index,'재진입')
|
||||
|
||||
|
||||
# elif JobFlag=='O':
|
||||
# # #print('O는 아웃이다')
|
||||
# the_index=self.stock_index_dict.get(stock_code,-1)
|
||||
# self.set_value_on_table(6,the_index,'이탈')
|
||||
|
||||
|
||||
#널 체크
|
||||
if (stock_code is not None and
|
||||
stock_name is not None and
|
||||
price is not None and
|
||||
sign is not None and
|
||||
change is not None and
|
||||
diff is not None and
|
||||
volume is not None and
|
||||
JobFlag is not None):
|
||||
|
||||
if JobFlag=='N':
|
||||
# #print('N은 진입이다')
|
||||
table_cnt=self.insert_row_on_stocks_table()
|
||||
self.stock_index_dict[stock_code]=table_cnt
|
||||
|
||||
self.set_value_on_table(0,table_cnt,stock_name)
|
||||
self.set_value_on_table(1,table_cnt,stock_code)
|
||||
self.set_value_on_table(2,table_cnt,price)
|
||||
self.set_value_on_table(3,table_cnt,change)
|
||||
self.set_value_on_table(4,table_cnt,diff)
|
||||
self.set_value_on_table(5,table_cnt,volume)
|
||||
self.set_value_on_table(6,table_cnt,'진입')
|
||||
|
||||
|
||||
elif JobFlag=='R':
|
||||
# #print('R은 재진입이다')
|
||||
# table_cnt=self.insert_row_on_stocks_table()
|
||||
# self.stock_index_dict[stock_code]=table_cnt
|
||||
the_index=self.stock_index_dict.get(stock_code,-1)
|
||||
|
||||
self.set_value_on_table(0,the_index,''+stock_name)
|
||||
self.set_value_on_table(1,the_index,stock_code)
|
||||
self.set_value_on_table(2,the_index,price)
|
||||
self.set_value_on_table(3,the_index,change)
|
||||
self.set_value_on_table(4,the_index,diff)
|
||||
self.set_value_on_table(5,the_index,volume)
|
||||
self.set_value_on_table(6,the_index,'재진입')
|
||||
|
||||
|
||||
elif JobFlag=='O':
|
||||
# #print('O는 아웃이다')
|
||||
the_index=self.stock_index_dict.get(stock_code,-1)
|
||||
self.set_value_on_table(6,the_index,'이탈')
|
||||
|
||||
# the_thing=master_dict.get(stock_code,None)
|
||||
# gubun=the_thing.get('gubun',None)
|
||||
|
||||
# #print('@@@@@master_dict: ',the_thing)
|
||||
|
||||
|
||||
|
||||
# def OnReceiveRealSearchData(self, szTrCode,result):
|
||||
# #print('szTrCode: ',szTrCode)
|
||||
# #print('szTrCode result: ',result)
|
||||
|
||||
def manually_stop(self):
|
||||
#print('manually_stop')
|
||||
if self.AlertNum !='':
|
||||
res=self.RemoveService('t1857',self.AlertNum)
|
||||
|
||||
if res is not None:
|
||||
pass
|
||||
|
||||
def go_search(self,the_path):
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t1857.res"
|
||||
#print('the_path: ',the_path)
|
||||
|
||||
# the_path='C:\\eBEST\\xingAPI\\ConditionToApi.ACF'
|
||||
# C:/eBEST/xingAPI/ConditionToApi.ACF
|
||||
|
||||
sRealFlag=self.SetFieldData("t1857InBlock", "sRealFlag", 0, 1)#맽 끝에 있는애가 0이면 조회 1이면 실시간
|
||||
sSearchFlag=self.SetFieldData("t1857InBlock", "sSearchFlag", 0, 'F')
|
||||
query_index=self.SetFieldData("t1857InBlock", "query_index", 0, the_path)
|
||||
# err_code = self.Request(False)
|
||||
|
||||
if self.AlertNum !='':
|
||||
res=self.RemoveService('t1857',self.AlertNum)
|
||||
if res is not None:
|
||||
pass
|
||||
|
||||
|
||||
# print('sRealFlag: ',sRealFlag)
|
||||
# print('sSearchFlag: ',sSearchFlag)
|
||||
# print('query_index: ',query_index)
|
||||
|
||||
#api 상으로 저 변수 세 개는 None이 나오는게 맞으므로 널 체크가 의미 없음
|
||||
|
||||
|
||||
err_code = self.RequestService('t1857',the_path)
|
||||
#print('GOGO: ',err_code)
|
||||
if err_code < 0:
|
||||
pass
|
||||
#print("error2... {0}".format(err_code))
|
||||
118
sample_python/tr/tr_cancel_order.py
Normal file
118
sample_python/tr/tr_cancel_order.py
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
load_dotenv()
|
||||
|
||||
class Tr_cancel_order:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
|
||||
def OnReceiveData(self, tr_code):
|
||||
#print('주문 에코: ',tr_code)
|
||||
# if tr_code=='CSPAT00600':
|
||||
|
||||
|
||||
# XAQueryEvents.query_state = True
|
||||
# block_count=self.GetBlockCount("t8430OutBlock")
|
||||
# #print('block_count: ',block_count)
|
||||
|
||||
|
||||
# for i in range(block_count):
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", i).strip()
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", i).strip()
|
||||
# gubun = self.GetFieldData("t8430OutBlock", "gubun", i).strip() #1은 코스피, 2는 코스닥
|
||||
|
||||
# master_dict[shcode]={
|
||||
# 'hname':hname,
|
||||
# 'gubun':gubun
|
||||
# }
|
||||
|
||||
# #print('master_dict: ',master_dict['005930'])
|
||||
# query_1857.set_master(master_dict)
|
||||
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
pass
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
# #print('OnReceiveMessage: ',szMessage)
|
||||
pass
|
||||
|
||||
|
||||
def shoot_order(self,stock_code,how_many,price,open,order_price,order_style,order_type,org_no):
|
||||
#order_style이 매수인지 매도인지 그거 말하는거임
|
||||
#order_type은 지정가인지 시장가인지 그거임
|
||||
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
is_market='00'
|
||||
|
||||
if order_type=='market':
|
||||
is_market=='03'
|
||||
|
||||
is_ask='1'
|
||||
|
||||
|
||||
if order_style=='bid':
|
||||
is_ask='2'
|
||||
|
||||
|
||||
order_dict={
|
||||
'account':self.account,
|
||||
'stock_code':stock_code,
|
||||
'how_many':how_many,
|
||||
'order_price':order_price,
|
||||
'is_ask':is_ask,
|
||||
'is_market':is_market,
|
||||
'org_no':org_no
|
||||
}
|
||||
|
||||
stock_code="A"+stock_code#모투라 이렇게 해놈
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\CSPAT00800.res"
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\CSPAT00800.res"
|
||||
self.SetFieldData("CSPAT00800InBlock1", "OrgOrdNo", 0, org_no)
|
||||
self.SetFieldData("CSPAT00800InBlock1", "AcntNo", 0, self.account)
|
||||
self.SetFieldData("CSPAT00800InBlock1", "InptPwd", 0, "0000") #모투는 0000임
|
||||
self.SetFieldData("CSPAT00800InBlock1", "IsuNo", 0, stock_code) #모투는 앞에 A 더하래
|
||||
self.SetFieldData("CSPAT00800InBlock1", "OrdQty", 0, how_many) #얘네 왜 스트링임?
|
||||
# self.SetFieldData("CSPAT00800InBlock1", "OrdPrc", 0, str(order_price))#얘네 왜 스트링임?
|
||||
# self.SetFieldData("CSPAT00700InBlock1", "BnsTpCode", 0, is_ask)#1이 매도 2가 매수
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
# 05@조건부지정가
|
||||
# 06@최유리지정가
|
||||
# 07@최우선지정가
|
||||
# 61@장개시전시간외종가
|
||||
# 81@시간외종가
|
||||
# 82@시간외단일가
|
||||
# self.SetFieldData("CSPAT00800InBlock1", "OrdprcPtnCode", 0, is_market)
|
||||
# 000:보통
|
||||
# 003:유통/자기융자신규
|
||||
# 005:유통대주신규
|
||||
# 007:자기대주신규
|
||||
# 101:유통융자상환
|
||||
# 103:자기융자상환
|
||||
# 105:유통대주상환
|
||||
# 107:자기대주상환
|
||||
# 180:예탁담보대출상환(신용)
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "MgntrnCode", 0, '000')
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "LoanDt", 0, '')#대출일이라는데 일단 비워둠
|
||||
# self.SetFieldData("CSPAT00800InBlock1", "OrdCndiTpCode", 0, '0') #0:없음,1:IOC,2:FOK 주문조건구분
|
||||
|
||||
#print('ORDER!!!!!')
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
|
||||
pass
|
||||
#print("error... {0}".format(err_code))
|
||||
72
sample_python/tr/tr_kh.py
Normal file
72
sample_python/tr/tr_kh.py
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
#XReal_S3_
|
||||
class XReal_KH_:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.count = 0
|
||||
# self.tr_0424=tr_0424
|
||||
|
||||
def OnReceiveRealData(self, tr_code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
shcode = self.GetFieldData("OutBlock", "shcode")
|
||||
price = self.GetFieldData("OutBlock", "price")
|
||||
tvol = self.GetFieldData("OutBlock", "tvol")
|
||||
tval = self.GetFieldData("OutBlock", "tval")
|
||||
|
||||
|
||||
# print('@@프로그램: ',shcode)
|
||||
# print('@@프로그램 price: ',price)
|
||||
# print('@@프로그램 순매수 수량: ',tvol)
|
||||
# print('@@프로그램 순매수 금액: ',tval)
|
||||
|
||||
if shcode is not None and price is not None:
|
||||
self.process_balance_change(shcode,price)
|
||||
|
||||
# chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
|
||||
# #print('chetime: ',chetime)
|
||||
# self.continue_draw_balance_table()
|
||||
|
||||
|
||||
|
||||
def initialize_continue_draw_balance_table(self,continue_draw_balance_table):
|
||||
#print('s3 initialize_continue_draw_balance_table @#@#@#@#@#@#@#')
|
||||
self.continue_draw_balance_table=continue_draw_balance_table
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('s3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,stock_code):
|
||||
print('프로그램 리얼 스타트: ',stock_code)
|
||||
# #print('왜 자꾸 콜하는겨')
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')+"\\Res\\KH_.res"
|
||||
# print('the_path: ',the_path)
|
||||
# the_path=os.environ.get('ROOT_FILE_PATH')+"\\Res\\S3_.res"
|
||||
self.ResFileName = the_path # RES 파일 등록
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\S3_.res" # RES 파일 등록
|
||||
|
||||
self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
67
sample_python/tr/tr_master.py
Normal file
67
sample_python/tr/tr_master.py
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
import os
|
||||
the_path=os.path.dirname(__file__)
|
||||
#XAQueryEvents
|
||||
class Tr_master:
|
||||
master_arr=[]
|
||||
master_dict={}
|
||||
query_state = False
|
||||
def OnReceiveData(self, tr_code):
|
||||
Tr_master.query_state = True
|
||||
block_count=self.GetBlockCount("t8430OutBlock")
|
||||
#print('block_count: ',block_count)
|
||||
|
||||
if block_count is not None:
|
||||
|
||||
|
||||
for i in range(block_count):
|
||||
hname = self.GetFieldData("t8430OutBlock", "hname", i).strip()
|
||||
shcode = self.GetFieldData("t8430OutBlock", "shcode", i).strip()
|
||||
gubun = self.GetFieldData("t8430OutBlock", "gubun", i).strip() #1은 코스피, 2는 코스닥
|
||||
self.master_dict[shcode]={
|
||||
'hname':hname,
|
||||
'shcode':shcode,
|
||||
'gubun':gubun
|
||||
}
|
||||
self.master_dict[hname]={
|
||||
'hname':hname,
|
||||
'shcode':shcode,
|
||||
'gubun':gubun
|
||||
}
|
||||
|
||||
# print('삼전: ',self.master_dict['005930'])
|
||||
#print('삼전2: ',self.master_dict['삼성전자'])
|
||||
|
||||
self.tr_0424.init_get_account(self.balance_window)#잔고
|
||||
self.tr_pending.get_pending(self.balance_window)#미체결
|
||||
|
||||
self.tr_0424.init_sc1()
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
# #print('OnReceiveMessage: ',szMessage)
|
||||
pass
|
||||
|
||||
def single_request(self,tr_0424,balance_window,tr_pending):
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t8430.res"
|
||||
self.tr_0424=tr_0424
|
||||
self.tr_pending=tr_pending
|
||||
self.balance_window=balance_window
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\t8430.res"
|
||||
#print('the_path2: ',the_path+"\\Res\\t8430.res")
|
||||
self.SetFieldData("t8430InBlock", "gubun", 0, 0)
|
||||
err_code = self.Request(False)
|
||||
|
||||
if err_code is not None:
|
||||
|
||||
if err_code < 0:
|
||||
#print("error... {0}".format(err_code))
|
||||
pass
|
||||
197
sample_python/tr/tr_order.py
Normal file
197
sample_python/tr/tr_order.py
Normal file
@@ -0,0 +1,197 @@
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from tr.tr_0424 import Tr_0424
|
||||
from PySide2 import QtTest
|
||||
from PySide2 import QtCore
|
||||
|
||||
# from order_window import Order_window
|
||||
|
||||
from balance_window import Balance_window
|
||||
import win32com.client #이베스트 관련
|
||||
import pythoncom #이베스트 관련
|
||||
load_dotenv()
|
||||
|
||||
|
||||
|
||||
class Tr_order:
|
||||
# class Worker(QtCore.QThread):
|
||||
# # def __init__(self,tr_0424):
|
||||
# # self.tr_0424=tr_0424
|
||||
|
||||
# def call(self,tr_0424):
|
||||
# self.tr_0424=tr_0424
|
||||
|
||||
# def run(self):
|
||||
# while True:
|
||||
# self.sleep(2)
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
# self.tr_0424=win32com.client.DispatchWithEvents("XA_DataSet.XAQuery",Tr_0424)#계좌티알
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
|
||||
# self.worker = self.Worker()
|
||||
# self.worker.call(self.tr_0424)
|
||||
# self.worker.start()
|
||||
|
||||
# self.order_window=Order_window()
|
||||
|
||||
self.the_pending={}#미체결
|
||||
self.the_pending_list=[]
|
||||
self.the_pending_temp={}#오더 에코 떨어지기 전에 메모리에 올려놓는 미체결
|
||||
|
||||
def init_set_text(self,func):
|
||||
self.set_status_label=func
|
||||
|
||||
|
||||
|
||||
def OnReceiveData(self, tr_code):
|
||||
# print('주문 에코: ',tr_code)
|
||||
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
|
||||
OrdQty = self.GetFieldData("CSPAT00600OutBlock1", "OrdQty",0).strip()
|
||||
|
||||
# print('AcntNo: ',OrdQty)
|
||||
|
||||
|
||||
|
||||
# if tr_code=='CSPAT00600':
|
||||
# df,df1=result
|
||||
|
||||
|
||||
# XAQueryEvents.query_state = True
|
||||
# block_count=self.GetBlockCount("t8430OutBlock")
|
||||
# #print('block_count: ',block_count)
|
||||
|
||||
|
||||
# for i in range(block_count):
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", i).strip()
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", i).strip()
|
||||
# gubun = self.GetFieldData("t8430OutBlock", "gubun", i).strip() #1은 코스피, 2는 코스닥
|
||||
|
||||
# master_dict[shcode]={
|
||||
# 'hname':hname,
|
||||
# 'gubun':gubun
|
||||
# }
|
||||
|
||||
# #print('master_dict: ',master_dict['005930'])
|
||||
# query_1857.set_master(master_dict)
|
||||
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
pass
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
# print('OnReceiveMessage nMessageCode: ',nMessageCode)
|
||||
# print('OnReceiveMessage szMessage: ',szMessage)
|
||||
|
||||
if nMessageCode=='00040':
|
||||
#미체결 obj 메모리에 올리는 부분
|
||||
# print('the_pending: ',self.the_pending)
|
||||
self.the_pending=self.the_pending_temp
|
||||
# print('the_pending2: ',self.the_pending)
|
||||
self.set_status_label(szMessage)
|
||||
pass
|
||||
|
||||
|
||||
def shoot_order(self,stock_code,how_many,price,open,order_price,order_style,order_type):
|
||||
#order_style이 매수인지 매도인지 그거 말하는거임
|
||||
#order_type은 지정가인지 시장가인지 그거임
|
||||
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
is_market='00'
|
||||
|
||||
if order_type=='market':
|
||||
is_market='03'
|
||||
order_price=0
|
||||
|
||||
is_ask='1'
|
||||
|
||||
|
||||
if order_style=='bid':
|
||||
is_ask='2'
|
||||
|
||||
|
||||
order_dict={
|
||||
'account':self.account,
|
||||
'stock_code':stock_code,
|
||||
'how_many':how_many,
|
||||
'order_price':order_price,
|
||||
'is_ask':is_ask,
|
||||
'is_market':is_market,
|
||||
'order_type':order_type
|
||||
}
|
||||
|
||||
#미체결에 넣는다 같은 스톡코드라도 리스트로 뿌려야되는거 아님?
|
||||
#걍 미체결 리얼에서 떨어지는거 찍어볼까
|
||||
# pending_stock=self.the_pending_temp.get(stock_code,None)
|
||||
|
||||
# self.the_pending_list.append({
|
||||
|
||||
# })
|
||||
|
||||
|
||||
# if pending_stock is None:
|
||||
|
||||
# self.the_pending_temp[stock_code]={
|
||||
# 'stock_code':stock_code,
|
||||
# 'how_many':how_many,
|
||||
# 'order_price':order_price,
|
||||
# }
|
||||
# else:
|
||||
# self.the_pending_temp[stock_code]['how_many']=how_many
|
||||
|
||||
#미체결에 넣는다 끝
|
||||
|
||||
|
||||
stock_code="A"+stock_code#모투라 이렇게 해놈
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\CSPAT00600.res"
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\CSPAT00600.res"
|
||||
self.SetFieldData("CSPAT00600InBlock1", "AcntNo", 0, self.account)
|
||||
self.SetFieldData("CSPAT00600InBlock1", "InptPwd", 0, "0000") #모투는 0000임
|
||||
self.SetFieldData("CSPAT00600InBlock1", "IsuNo", 0, stock_code) #모투는 앞에 A 더하래
|
||||
self.SetFieldData("CSPAT00600InBlock1", "OrdQty", 0, how_many) #얘네 왜 스트링임?
|
||||
self.SetFieldData("CSPAT00600InBlock1", "OrdPrc", 0, str(order_price))#얘네 왜 스트링임?
|
||||
self.SetFieldData("CSPAT00600InBlock1", "BnsTpCode", 0, is_ask)#1이 매도 2가 매수
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
# 05@조건부지정가
|
||||
# 06@최유리지정가
|
||||
# 07@최우선지정가
|
||||
# 61@장개시전시간외종가
|
||||
# 81@시간외종가
|
||||
# 82@시간외단일가
|
||||
self.SetFieldData("CSPAT00600InBlock1", "OrdprcPtnCode", 0, is_market)
|
||||
# 000:보통
|
||||
# 003:유통/자기융자신규
|
||||
# 005:유통대주신규
|
||||
# 007:자기대주신규
|
||||
# 101:유통융자상환
|
||||
# 103:자기융자상환
|
||||
# 105:유통대주상환
|
||||
# 107:자기대주상환
|
||||
# 180:예탁담보대출상환(신용)
|
||||
self.SetFieldData("CSPAT00600InBlock1", "MgntrnCode", 0, '000')
|
||||
self.SetFieldData("CSPAT00600InBlock1", "LoanDt", 0, '')#대출일이라는데 일단 비워둠
|
||||
self.SetFieldData("CSPAT00600InBlock1", "OrdCndiTpCode", 0, '0') #0:없음,1:IOC,2:FOK 주문조건구분
|
||||
|
||||
#print('ORDER!!!!!')
|
||||
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
pass
|
||||
#print("error... {0}".format(err_code))
|
||||
326
sample_python/tr/tr_pending.py
Normal file
326
sample_python/tr/tr_pending.py
Normal file
@@ -0,0 +1,326 @@
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from tr.tr_0424 import Tr_0424
|
||||
from PySide2 import QtTest
|
||||
from PySide2 import QtCore
|
||||
import json
|
||||
|
||||
# from order_window import Order_window
|
||||
|
||||
from balance_window import Balance_window
|
||||
import win32com.client #이베스트 관련
|
||||
import pythoncom #이베스트 관련
|
||||
load_dotenv()
|
||||
|
||||
from tr.tr_master import Tr_master
|
||||
tr_master=Tr_master()
|
||||
|
||||
|
||||
from tr.tr_sc0 import Tr_sc0
|
||||
|
||||
|
||||
class Tr_pending:
|
||||
# class Worker(QtCore.QThread):
|
||||
# # def __init__(self,tr_0424):
|
||||
# # self.tr_0424=tr_0424
|
||||
|
||||
# def call(self,tr_0424):
|
||||
# self.tr_0424=tr_0424
|
||||
|
||||
# def run(self):
|
||||
# while True:
|
||||
# self.sleep(2)
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
self.pw=os.environ.get('PW')
|
||||
# self.tr_0424=win32com.client.DispatchWithEvents("XA_DataSet.XAQuery",Tr_0424)#계좌티알
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
|
||||
# self.worker = self.Worker()
|
||||
# self.worker.call(self.tr_0424)
|
||||
# self.worker.start()
|
||||
|
||||
# self.order_window=Order_window()
|
||||
|
||||
# self.the_pending={}#미체결
|
||||
self.the_pending_list=[]
|
||||
# self.the_pending_temp={}#오더 에코 떨어지기 전에 메모리에 올려놓는 미체결
|
||||
|
||||
|
||||
# self.sc0_real = win32com.client.DispatchWithEvents("XA_DataSet.XAReal", Tr_sc0)
|
||||
# self.sc0_real.start(self.process_pending_change_echo)
|
||||
|
||||
def init_set_text(self,func):
|
||||
self.set_status_label=func
|
||||
|
||||
|
||||
# def process_pending_change_echo(self,ord_no, ord_qty, ord_price, stock_code, stock_name):
|
||||
# print('process_pending_change_echo: ',self.the_pending_list)
|
||||
|
||||
|
||||
def get_pending(self,balance_window):
|
||||
# print('펜딩부름')
|
||||
|
||||
self.balance_window=balance_window
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\t0424.res"
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\CSPAQ13700.res"
|
||||
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "RecCnt", 0, "00001")
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "AcntNo", 0, os.environ.get('ACCOUNT'))
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "InptPwd", 0, os.environ.get('PW'))
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "OrdMktCode", 0, '00')
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "BnsTpCode", 0, '0') #0 결제기준, 2 체결기준
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "IsuNo", 0, '')
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "ExecYn", 0, '3')
|
||||
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "OrdDt", 0, '')
|
||||
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "SrtOrdNo2", 0, '999999999')
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "BkseqTpCode", 0, '0')
|
||||
self.SetFieldData("CSPAQ13700InBlock1", "OrdPtnCode", 0, '00')
|
||||
|
||||
#print('계좌 불러옴')
|
||||
|
||||
|
||||
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
#print("error... {0}".format(err_code))
|
||||
|
||||
pass
|
||||
|
||||
def init_draw_pending_table(self):
|
||||
# self.balance_window.insert_row_on_pending_table()
|
||||
# self.balance_window.set_value_on_pending_table(0,0,'stock_name')
|
||||
# self.balance_window.set_value_on_pending_table(1,0,'stock_code')
|
||||
|
||||
|
||||
for i,obj in enumerate( self.the_pending_list):
|
||||
try:
|
||||
|
||||
self.balance_window.insert_row_on_pending_table()
|
||||
|
||||
self.balance_window.set_value_on_pending_table(0,i,obj['ord_no'] )
|
||||
self.balance_window.set_value_on_pending_table(1,i,obj['stock_name'] )
|
||||
self.balance_window.set_value_on_pending_table(2,i,obj['side'])
|
||||
self.balance_window.set_value_on_pending_table(3,i,obj['stock_code'])
|
||||
self.balance_window.set_value_on_pending_table(4,i,obj['ord_qty'])
|
||||
self.balance_window.set_value_on_pending_table(5,i,obj['ord_price'])
|
||||
self.balance_window.set_value_on_pending_table(6,i,obj['OrgOrdNo'])
|
||||
self.balance_window.set_value_on_pending_table(7,i,obj['OrdTrxPtnNm'])
|
||||
|
||||
|
||||
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
def OnReceiveData(self, tr_code):
|
||||
|
||||
# self.tr_0424.get_account(Balance_window)
|
||||
block_count=self.GetBlockCount("CSPAQ13700OutBlock3")
|
||||
self.the_pending_list=[]
|
||||
os.environ['the_pending_list_length']=str(len(self.the_pending_list))
|
||||
os.environ['the_pending_list']=json.dumps(self.the_pending_list)
|
||||
# if len(self.the_pending_list)>0:
|
||||
# self.the_pending_list=[]
|
||||
|
||||
|
||||
if block_count is not None:
|
||||
# print('미체결 block_count: ',block_count)
|
||||
|
||||
|
||||
for i in range(block_count):
|
||||
|
||||
OrgOrdNo = self.GetFieldData("CSPAQ13700OutBlock3", "OrgOrdNo",i).strip()
|
||||
ord_no = self.GetFieldData("CSPAQ13700OutBlock3", "OrdNo",i).strip()
|
||||
ord_qty = self.GetFieldData("CSPAQ13700OutBlock3", "OrdQty",i).strip()
|
||||
ExecQty = self.GetFieldData("CSPAQ13700OutBlock3", "ExecQty",i).strip()#체결수량
|
||||
ord_price = self.GetFieldData("CSPAQ13700OutBlock3", "OrdPrc",i).strip()
|
||||
stock_code = self.GetFieldData("CSPAQ13700OutBlock3", "shcode",i).strip()
|
||||
stock_name = self.GetFieldData("CSPAQ13700OutBlock3", "IsuNm",i).strip()
|
||||
BnsTpCode = self.GetFieldData("CSPAQ13700OutBlock3", "BnsTpCode",i).strip()#매매구분 1 매도 2 매수
|
||||
|
||||
BnsTpNm = self.GetFieldData("CSPAQ13700OutBlock3", "BnsTpNm",i).strip()
|
||||
OrdTrxPtnCode = self.GetFieldData("CSPAQ13700OutBlock3", "OrdTrxPtnCode",i).strip()
|
||||
OrdTrxPtnNm = self.GetFieldData("CSPAQ13700OutBlock3", "OrdTrxPtnNm",i).strip()
|
||||
# MrcTpCode = self.GetFieldData("CSPAQ13700OutBlock3", "MrcTpCode",i).strip()
|
||||
# MrcTpNm = self.GetFieldData("CSPAQ13700OutBlock3", "MrcTpNm",i).strip()
|
||||
|
||||
side=''
|
||||
|
||||
if BnsTpCode=='1':
|
||||
side='매도'
|
||||
else:
|
||||
side='매수'
|
||||
|
||||
actual_qty=int(ord_qty)-int(ExecQty)#미체결량 구하기
|
||||
|
||||
# print('미체결 MrcTpCode: ',MrcTpCode)
|
||||
# print('미체결 MrcTpNm: ',MrcTpNm)
|
||||
|
||||
the_dict_from_master=tr_master.master_dict.get(stock_name,{})
|
||||
|
||||
|
||||
stock_code_from_master=the_dict_from_master.get('shcode',"")
|
||||
|
||||
obj={
|
||||
"ord_no":ord_no,
|
||||
"ord_qty":actual_qty,
|
||||
"ord_price":int(float(ord_price)),
|
||||
"stock_code":stock_code_from_master,
|
||||
"stock_name":stock_name,
|
||||
'side':side,
|
||||
'OrgOrdNo':OrgOrdNo,
|
||||
'OrdTrxPtnNm':OrdTrxPtnNm
|
||||
}
|
||||
self.the_pending_list.append(obj)
|
||||
|
||||
os.environ['the_pending_list_length']=str(len(self.the_pending_list))
|
||||
os.environ['the_pending_list']=json.dumps(self.the_pending_list)
|
||||
|
||||
# print('tr_pending의 the_pending_list: ',json.loads(os.environ['the_pending_list']) )
|
||||
# print('tr_pending의 the_pending_list 길이: ',os.environ['the_pending_list_length'])
|
||||
self.init_draw_pending_table()
|
||||
|
||||
# if tr_code=='CSPAT00600':
|
||||
# df,df1=result
|
||||
|
||||
|
||||
# XAQueryEvents.query_state = True
|
||||
# block_count=self.GetBlockCount("t8430OutBlock")
|
||||
# #print('block_count: ',block_count)
|
||||
|
||||
|
||||
# for i in range(block_count):
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", i).strip()
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", i).strip()
|
||||
# gubun = self.GetFieldData("t8430OutBlock", "gubun", i).strip() #1은 코스피, 2는 코스닥
|
||||
|
||||
# master_dict[shcode]={
|
||||
# 'hname':hname,
|
||||
# 'gubun':gubun
|
||||
# }
|
||||
|
||||
# #print('master_dict: ',master_dict['005930'])
|
||||
# query_1857.set_master(master_dict)
|
||||
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
pass
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
|
||||
if nMessageCode=='00040':
|
||||
#미체결 obj 메모리에 올리는 부분
|
||||
self.the_pending=self.the_pending_temp
|
||||
# self.set_status_label(szMessage)
|
||||
|
||||
|
||||
|
||||
# def shoot_order(self,stock_code,how_many,price,open,order_price,order_style,order_type):
|
||||
# #order_style이 매수인지 매도인지 그거 말하는거임
|
||||
# #order_type은 지정가인지 시장가인지 그거임
|
||||
|
||||
# # 00@지정가
|
||||
# # 03@시장가
|
||||
# is_market='00'
|
||||
|
||||
# if order_type=='market':
|
||||
# is_market='03'
|
||||
# order_price=0
|
||||
|
||||
# is_ask='1'
|
||||
|
||||
|
||||
# if order_style=='bid':
|
||||
# is_ask='2'
|
||||
|
||||
|
||||
# order_dict={
|
||||
# 'account':self.account,
|
||||
# 'stock_code':stock_code,
|
||||
# 'how_many':how_many,
|
||||
# 'order_price':order_price,
|
||||
# 'is_ask':is_ask,
|
||||
# 'is_market':is_market,
|
||||
# 'order_type':order_type
|
||||
# }
|
||||
|
||||
# #미체결에 넣는다 같은 스톡코드라도 리스트로 뿌려야되는거 아님?
|
||||
# #걍 미체결 리얼에서 떨어지는거 찍어볼까
|
||||
# # pending_stock=self.the_pending_temp.get(stock_code,None)
|
||||
|
||||
# # self.the_pending_list.append({
|
||||
|
||||
# # })
|
||||
|
||||
|
||||
# # if pending_stock is None:
|
||||
|
||||
# # self.the_pending_temp[stock_code]={
|
||||
# # 'stock_code':stock_code,
|
||||
# # 'how_many':how_many,
|
||||
# # 'order_price':order_price,
|
||||
# # }
|
||||
# # else:
|
||||
# # self.the_pending_temp[stock_code]['how_many']=how_many
|
||||
|
||||
# #미체결에 넣는다 끝
|
||||
|
||||
|
||||
# stock_code="A"+stock_code#모투라 이렇게 해놈
|
||||
|
||||
# the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
# self.ResFileName = the_path+"\\Res\\CSPAT00600.res"
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\CSPAT00600.res"
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "AcntNo", 0, self.account)
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "InptPwd", 0, "0000") #모투는 0000임
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "IsuNo", 0, stock_code) #모투는 앞에 A 더하래
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "OrdQty", 0, how_many) #얘네 왜 스트링임?
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "OrdPrc", 0, str(order_price))#얘네 왜 스트링임?
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "BnsTpCode", 0, is_ask)#1이 매도 2가 매수
|
||||
# # 00@지정가
|
||||
# # 03@시장가
|
||||
# # 05@조건부지정가
|
||||
# # 06@최유리지정가
|
||||
# # 07@최우선지정가
|
||||
# # 61@장개시전시간외종가
|
||||
# # 81@시간외종가
|
||||
# # 82@시간외단일가
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "OrdprcPtnCode", 0, is_market)
|
||||
# # 000:보통
|
||||
# # 003:유통/자기융자신규
|
||||
# # 005:유통대주신규
|
||||
# # 007:자기대주신규
|
||||
# # 101:유통융자상환
|
||||
# # 103:자기융자상환
|
||||
# # 105:유통대주상환
|
||||
# # 107:자기대주상환
|
||||
# # 180:예탁담보대출상환(신용)
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "MgntrnCode", 0, '000')
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "LoanDt", 0, '')#대출일이라는데 일단 비워둠
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "OrdCndiTpCode", 0, '0') #0:없음,1:IOC,2:FOK 주문조건구분
|
||||
|
||||
# #print('ORDER!!!!!')
|
||||
|
||||
|
||||
# err_code = self.Request(False)
|
||||
# if err_code < 0:
|
||||
# pass
|
||||
# #print("error... {0}".format(err_code))
|
||||
115
sample_python/tr/tr_redo_order.py
Normal file
115
sample_python/tr/tr_redo_order.py
Normal file
@@ -0,0 +1,115 @@
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
load_dotenv()
|
||||
|
||||
class Tr_redo_order:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.account=os.environ.get('ACCOUNT')
|
||||
|
||||
def OnReceiveData(self, tr_code):
|
||||
#print('주문 에코: ',tr_code)
|
||||
|
||||
|
||||
# XAQueryEvents.query_state = True
|
||||
# block_count=self.GetBlockCount("t8430OutBlock")
|
||||
# #print('block_count: ',block_count)
|
||||
|
||||
|
||||
# for i in range(block_count):
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", i).strip()
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", i).strip()
|
||||
# gubun = self.GetFieldData("t8430OutBlock", "gubun", i).strip() #1은 코스피, 2는 코스닥
|
||||
|
||||
# master_dict[shcode]={
|
||||
# 'hname':hname,
|
||||
# 'gubun':gubun
|
||||
# }
|
||||
|
||||
# #print('master_dict: ',master_dict['005930'])
|
||||
# query_1857.set_master(master_dict)
|
||||
|
||||
|
||||
# hname = self.GetFieldData("t8430OutBlock", "hname", 0)
|
||||
# shcode = self.GetFieldData("t8430OutBlock", "shcode", 0)
|
||||
# #print('tr_code: ',tr_code)
|
||||
# #print('hname: ',hname)
|
||||
# #print('shcode: ',shcode)
|
||||
|
||||
# param['hname']=hname
|
||||
# param['shcode']=shcode
|
||||
pass
|
||||
def OnReceiveMessage(self, error, nMessageCode, szMessage):
|
||||
# #print('OnReceiveMessage: ',szMessage)
|
||||
pass
|
||||
|
||||
|
||||
def shoot_order(self,stock_code,how_many,price,open,order_price,order_style,order_type,org_no):
|
||||
#order_style이 매수인지 매도인지 그거 말하는거임
|
||||
#order_type은 지정가인지 시장가인지 그거임
|
||||
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
is_market='00'
|
||||
|
||||
if order_type=='market':
|
||||
is_market=='03'
|
||||
|
||||
is_ask='1'
|
||||
|
||||
|
||||
if order_style=='bid':
|
||||
is_ask='2'
|
||||
|
||||
|
||||
order_dict={
|
||||
'account':self.account,
|
||||
'stock_code':stock_code,
|
||||
'how_many':how_many,
|
||||
'order_price':order_price,
|
||||
'is_ask':is_ask,
|
||||
'is_market':is_market,
|
||||
'org_no':org_no
|
||||
}
|
||||
stock_code="A"+stock_code#모투라 이렇게 해놈
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\CSPAT00700.res"
|
||||
|
||||
# self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\CSPAT00700.res"
|
||||
self.SetFieldData("CSPAT00700InBlock1", "OrgOrdNo", 0, org_no)
|
||||
self.SetFieldData("CSPAT00700InBlock1", "AcntNo", 0, self.account)
|
||||
self.SetFieldData("CSPAT00700InBlock1", "InptPwd", 0, "0000") #모투는 0000임
|
||||
self.SetFieldData("CSPAT00700InBlock1", "IsuNo", 0, stock_code) #모투는 앞에 A 더하래
|
||||
self.SetFieldData("CSPAT00700InBlock1", "OrdQty", 0, how_many) #얘네 왜 스트링임?
|
||||
self.SetFieldData("CSPAT00700InBlock1", "OrdPrc", 0, str(order_price))#얘네 왜 스트링임?
|
||||
# self.SetFieldData("CSPAT00700InBlock1", "BnsTpCode", 0, is_ask)#1이 매도 2가 매수
|
||||
# 00@지정가
|
||||
# 03@시장가
|
||||
# 05@조건부지정가
|
||||
# 06@최유리지정가
|
||||
# 07@최우선지정가
|
||||
# 61@장개시전시간외종가
|
||||
# 81@시간외종가
|
||||
# 82@시간외단일가
|
||||
self.SetFieldData("CSPAT00700InBlock1", "OrdprcPtnCode", 0, is_market)
|
||||
# 000:보통
|
||||
# 003:유통/자기융자신규
|
||||
# 005:유통대주신규
|
||||
# 007:자기대주신규
|
||||
# 101:유통융자상환
|
||||
# 103:자기융자상환
|
||||
# 105:유통대주상환
|
||||
# 107:자기대주상환
|
||||
# 180:예탁담보대출상환(신용)
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "MgntrnCode", 0, '000')
|
||||
# self.SetFieldData("CSPAT00600InBlock1", "LoanDt", 0, '')#대출일이라는데 일단 비워둠
|
||||
self.SetFieldData("CSPAT00700InBlock1", "OrdCndiTpCode", 0, '0') #0:없음,1:IOC,2:FOK 주문조건구분
|
||||
|
||||
#print('ORDER!!!!!')
|
||||
|
||||
err_code = self.Request(False)
|
||||
if err_code < 0:
|
||||
pass
|
||||
#print("error... {0}".format(err_code))
|
||||
108
sample_python/tr/tr_sc0.py
Normal file
108
sample_python/tr/tr_sc0.py
Normal file
@@ -0,0 +1,108 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
|
||||
class Tr_sc0:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def OnReceiveRealData(self,code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
# self.count += 1
|
||||
#print('yeah')
|
||||
#print('자기소개2: ',dir(self))
|
||||
stock_code = self.GetFieldData("OutBlock", "expcode")
|
||||
stock_name = self.GetFieldData("OutBlock", "hname")
|
||||
ord_qty = self.GetFieldData("OutBlock", "ordqty")#주문수량
|
||||
ord_price = self.GetFieldData("OutBlock", "ordprice")#주문가격
|
||||
ord_no = self.GetFieldData("OutBlock", "ordno")#주문번호
|
||||
orgordno = self.GetFieldData("OutBlock", "orgordno")#원주문번호
|
||||
orgordundrqty = self.GetFieldData("OutBlock", "orgordundrqty")#원주문미체결수량
|
||||
bnstp = self.GetFieldData("OutBlock", "bnstp")#매매구분 1 매도 2 매수
|
||||
ordchegb = self.GetFieldData("OutBlock", "ordchegb") #01 주문 02 정정 03 취소 11체결
|
||||
|
||||
# OrdPtnCode = self.GetFieldData("OutBlock", "OrdPtnCode")
|
||||
# OrdPtnNm = self.GetFieldData("OutBlock", "OrdPtnNm")
|
||||
# OrdTrxPtnCode = self.GetFieldData("OutBlock", "OrdTrxPtnCode")
|
||||
OrdTrxPtnNm = ''
|
||||
|
||||
side=''
|
||||
|
||||
if bnstp=='1':
|
||||
side='매도'
|
||||
else:
|
||||
side='매수'
|
||||
|
||||
|
||||
if ordchegb=='02':
|
||||
OrdTrxPtnNm='정정확인'
|
||||
|
||||
|
||||
|
||||
if len(stock_code) > 10:
|
||||
stock_code=stock_code[3:-3]
|
||||
|
||||
if OrdTrxPtnNm=='':
|
||||
OrdTrxPtnNm='정상'
|
||||
|
||||
# price = int(self.GetFieldData("OutBlock", "price"))
|
||||
# if stock_code is not None and price is not None:
|
||||
# self.process_balance_change(stock_code,price)
|
||||
# open = int(self.GetFieldData("OutBlock", "open"))
|
||||
# drate = float(self.GetFieldData("OutBlock", "drate"))
|
||||
# #print('코스닥 코드: ',stock_code)
|
||||
# # #print('drate: ',drate)
|
||||
# # #print('chetime: ',chetime)
|
||||
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
# volume = int(self.GetFieldData("OutBlock", "cvolume"))#cvolume이 체결거래량이고 그냥 볼륨은 누적거래량임
|
||||
# accu_volume = int(self.GetFieldData("OutBlock", "volume"))#누적거래대금
|
||||
# value = int(self.GetFieldData("OutBlock", "value"))#누적거래대금
|
||||
# side = self.GetFieldData("OutBlock", "cgubun")
|
||||
|
||||
# self.process_pending_change_echo(ord_no, ord_qty, ord_price, stock_code, stock_name,side,orgordno,OrdTrxPtnNm)
|
||||
# print('##ordchegb222: ',ordchegb)
|
||||
if ordchegb != '03':
|
||||
# print('##ordchegb222: ',ordchegb)
|
||||
|
||||
self.process_pending_change_echo(ord_no, ord_qty, ord_price, stock_code, stock_name,side,orgordno,OrdTrxPtnNm)
|
||||
|
||||
|
||||
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,process_pending_change_echo):
|
||||
self.process_pending_change_echo=process_pending_change_echo
|
||||
# print('접수 리얼 스타트: ')
|
||||
#print('자기소개: ',dir(self))
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\SC0.res"
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\SC0.res" # RES 파일 등록
|
||||
# self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
# self.AdviseLinkFromHTS() # 실시간데이터 요청
|
||||
#print('접수 리얼 스타트 끝: ')
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
97
sample_python/tr/tr_sc1.py
Normal file
97
sample_python/tr/tr_sc1.py
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
|
||||
class Tr_sc1:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def OnReceiveRealData(self,code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
# self.count += 1
|
||||
# #print('yeah')
|
||||
# #print('자기소개2: ',dir(self))
|
||||
stock_code = self.GetFieldData("OutBlock", "Isuno")[3:-3]
|
||||
stock_name = self.GetFieldData("OutBlock", "Isunm")
|
||||
# chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
ordno = self.GetFieldData("OutBlock", "ordno")#주문번호
|
||||
volume = int(self.GetFieldData("OutBlock", "execqty"))
|
||||
#1 매도 2 매수
|
||||
side = int(self.GetFieldData("OutBlock", "bnstp"))
|
||||
contract_price = int(self.GetFieldData("OutBlock", "execprc"))
|
||||
|
||||
|
||||
|
||||
|
||||
if len(stock_code) > 10:
|
||||
stock_code=stock_code[3:-3]
|
||||
|
||||
|
||||
if (stock_code is not None and
|
||||
stock_name is not None and
|
||||
volume is not None and
|
||||
side is not None and
|
||||
contract_price is not None):
|
||||
|
||||
|
||||
self.process_balance_change_echo(stock_code,volume,side,contract_price,stock_name,ordno)
|
||||
|
||||
|
||||
# open = int(self.GetFieldData("OutBlock", "open"))
|
||||
# drate = float(self.GetFieldData("OutBlock", "drate"))
|
||||
# #print('코스닥 코드: ',stock_code)
|
||||
# # #print('drate: ',drate)
|
||||
# # #print('chetime: ',chetime)
|
||||
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
# volume = int(self.GetFieldData("OutBlock", "cvolume"))#cvolume이 체결거래량이고 그냥 볼륨은 누적거래량임
|
||||
# accu_volume = int(self.GetFieldData("OutBlock", "volume"))#누적거래대금
|
||||
# value = int(self.GetFieldData("OutBlock", "value"))#누적거래대금
|
||||
# side = self.GetFieldData("OutBlock", "cgubun")
|
||||
|
||||
#print('스톡코드: ',stock_code)
|
||||
#print('stock_name: ',stock_name)
|
||||
#print('volume: ',volume)
|
||||
#print('side: ',side)
|
||||
#print('contract_price: ',contract_price)
|
||||
|
||||
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,process_balance_change_echo):
|
||||
self.process_balance_change_echo=process_balance_change_echo
|
||||
#print('체결 리얼 스타트: ')
|
||||
#print('자기소개 체결: ',dir(self))
|
||||
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
# self.ResFileName = the_path+"\\Res\\SC1.res"
|
||||
# self.LoadFromResFile = the_path+"\\Res\\SC1.res"
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\SC1.res" # RES 파일 등록
|
||||
# self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
# self.AdviseLinkFromHTS() # 실시간데이터 요청
|
||||
#print('체결 리얼 스타트 끝: ')
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
82
sample_python/tr/tr_sc2.py
Normal file
82
sample_python/tr/tr_sc2.py
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
|
||||
class Tr_sc2:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def OnReceiveRealData(self,code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
# self.count += 1
|
||||
#print('yeah')
|
||||
#print('자기소개2: ',dir(self))
|
||||
|
||||
|
||||
# stock_code = self.GetFieldData("OutBlock", "Isuno")[3:-3]
|
||||
# stock_name = self.GetFieldData("OutBlock", "Isunm")
|
||||
ord_qty = self.GetFieldData("OutBlock", "ordqty")#주문수량
|
||||
ord_price = self.GetFieldData("OutBlock", "ordprc")#주문가격
|
||||
ord_no = self.GetFieldData("OutBlock", "ordno")#주문번호
|
||||
orgordno = self.GetFieldData("OutBlock", "orgordno")#원주문번호
|
||||
# bnstp = self.GetFieldData("OutBlock", "bnstp")#매매구분 1 매도 2 매수
|
||||
# side=''
|
||||
|
||||
# if bnstp=='1':
|
||||
# side='매도'
|
||||
# else:
|
||||
# side='매수'
|
||||
|
||||
|
||||
|
||||
|
||||
# print('##bnstp: ',bnstp)
|
||||
# print('##stock_code: ',stock_code)
|
||||
# print('##stock_name: ',stock_name)
|
||||
# print('##ord_qty: ',ord_qty)
|
||||
# print('##ord_price: ',ord_price)
|
||||
# print('##ord_no: ',ord_no)
|
||||
# print('##orgordno: ',orgordno)
|
||||
|
||||
# self.process_pending_fix_echo(orgordno,ord_qty,ord_price)
|
||||
|
||||
|
||||
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self):
|
||||
# self.process_pending_fix_echo=process_pending_fix_echo
|
||||
# print('정정 리얼 스타트: ')
|
||||
#print('자기소개: ',dir(self))
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\SC2.res"
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\SC2.res" # RES 파일 등록
|
||||
# self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
# self.AdviseLinkFromHTS() # 실시간데이터 요청
|
||||
#print('접수 리얼 스타트 끝: ')
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
88
sample_python/tr/tr_sc3.py
Normal file
88
sample_python/tr/tr_sc3.py
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
# from tr.tr_0424 import Tr_0424
|
||||
# tr_0424=Tr_0424()
|
||||
import os
|
||||
|
||||
class Tr_sc3:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def OnReceiveRealData(self,code): # event handler
|
||||
"""
|
||||
이베스트 서버에서 ReceiveRealData 이벤트 받으면 실행되는 event handler
|
||||
"""
|
||||
# self.count += 1
|
||||
#print('yeah')
|
||||
#print('자기소개2: ',dir(self))
|
||||
|
||||
|
||||
|
||||
|
||||
# stock_code = self.GetFieldData("OutBlock", "expcode")
|
||||
# stock_name = self.GetFieldData("OutBlock", "hname")
|
||||
ord_qty = self.GetFieldData("OutBlock", "ordqty")#주문수량
|
||||
# ord_price = self.GetFieldData("OutBlock", "ordprc")#주문가격
|
||||
ord_no = self.GetFieldData("OutBlock", "ordno")#주문번호
|
||||
orgordno = self.GetFieldData("OutBlock", "orgordno")#원주문번호
|
||||
# bnstp = self.GetFieldData("OutBlock", "bnstp")#매매구분 1 매도 2 매수
|
||||
# side=''
|
||||
|
||||
# if bnstp=='1':
|
||||
# side='매도'
|
||||
# else:
|
||||
# side='매수'
|
||||
|
||||
|
||||
# price = int(self.GetFieldData("OutBlock", "price"))
|
||||
# if stock_code is not None and price is not None:
|
||||
# self.process_balance_change(stock_code,price)
|
||||
# open = int(self.GetFieldData("OutBlock", "open"))
|
||||
# drate = float(self.GetFieldData("OutBlock", "drate"))
|
||||
# #print('코스닥 코드: ',stock_code)
|
||||
# # #print('drate: ',drate)
|
||||
# # #print('chetime: ',chetime)
|
||||
# # chetime = self.GetFieldData("OutBlock", "chetime")
|
||||
# volume = int(self.GetFieldData("OutBlock", "cvolume"))#cvolume이 체결거래량이고 그냥 볼륨은 누적거래량임
|
||||
# accu_volume = int(self.GetFieldData("OutBlock", "volume"))#누적거래대금
|
||||
# value = int(self.GetFieldData("OutBlock", "value"))#누적거래대금
|
||||
# side = self.GetFieldData("OutBlock", "cgubun")
|
||||
|
||||
self.process_pending_cancel_echo(orgordno,ord_qty)
|
||||
|
||||
|
||||
|
||||
|
||||
def initialize_process_balance_change(self,process_balance_change):
|
||||
#print('k3 initialize_process_balance_change @#@#@#@#@#@#@#')
|
||||
self.process_balance_change=process_balance_change
|
||||
|
||||
def start(self,process_pending_cancel_echo):
|
||||
self.process_pending_cancel_echo=process_pending_cancel_echo
|
||||
# print('취소 리얼 스타트: ')
|
||||
#print('자기소개: ',dir(self))
|
||||
"""
|
||||
이베스트 서버에 실시간 data 요청함.
|
||||
"""
|
||||
|
||||
|
||||
the_path=os.environ.get('ROOT_FILE_PATH')
|
||||
self.ResFileName = the_path+"\\Res\\SC3.res"
|
||||
|
||||
self.ResFileName = "C:\\eBEST\\xingAPI\\Res\\SC3.res" # RES 파일 등록
|
||||
# self.SetFieldData("InBlock", "shcode", stock_code)
|
||||
self.AdviseRealData() # 실시간데이터 요청
|
||||
# self.AdviseLinkFromHTS() # 실시간데이터 요청
|
||||
#print('접수 리얼 스타트 끝: ')
|
||||
|
||||
def add_item(self, stockcode):
|
||||
# 실시간데이터 요청 종목 추가
|
||||
self.SetFieldData("InBlock", "shcode", stockcode)
|
||||
|
||||
self.AdviseRealData()
|
||||
|
||||
def remove_item(self, stockcode):
|
||||
# stockcode 종목만 실시간데이터 요청 취소
|
||||
self.UnadviseRealDataWithKey(stockcode)
|
||||
|
||||
def end(self):
|
||||
self.UnadviseRealData() # 실시간데이터 요청 모두 취소
|
||||
Reference in New Issue
Block a user