커밋 1 — 실매 가격 TTL 구멍 (본체)

왜: 체결이 없어도 마지막가는 유지인데, TTL로 None 만들고 매도/EOD를 건너뛰어 8/5 돌파·금요일 leftover가 남음. 호가필터 TTL 구멍과 같은 병.

넣을 파일

신규: kis_trader/engine/live_sell_price.py
kis_trader/strategies/base.py (_ws_last_quote, _resolve_sell_price)
전략: momentum.py scalping.py tail_catch.py breakout.py range_break.py dart_strategy.py updow_strategy.py updown_feed.py us_momentum.py
WS: ws_manager.py kis_ws.py kiwoom_ws.py ls_ws.py kis_ws_overseas.py
kis_trader/web/live_config_schema.py (WS_PRICE_MAX_AGE_SEC 기본 0)
database.py (키 주석 + legacy/ sys.path)
kis_trader/execution/order_manager.py (잔고 있는데 40240000 ghost_purge 금지 — 같은 EOD 사고)
EOD가 min_hold에 안 막히게 손본 momentum_hts_logic.py / scalping_engine.py / tail_engine.py (이 대화에서 손본 부분만 확인 후)
문서: docs/like_mcp.md/db_erd.md code_architecture.md (가격 TTL 문구)
메시지 초안

fix: 매수·매도 현재가를 TTL로 버리지 않음 (마지막 RAM)
횡보·체결 공백을 죽은 캐시로 오인해 None 처리하면 손절·EOD가 스킵된다.
호가필터와 같이 나이는 무시하고 마지막 체결가를 유지한다. EOD는 매수가 폴백.
영향: 실매 O / 백테·옵투나 봉 경로 거의 무관 (엔진 식 변경 아님)

커밋 2 — 루트 정리 (remove/ vs legacy/)
왜: 루트 단독봇·테스트는 지울 보관함으로. 웹·알람이 아직 쓰는 모듈은 remove에 두면 나중에 폴더째 삭제 때 깨짐.

넣을 파일

이동: 미사용 → remove/legacy_root/ (래퍼, ETF/키움 옛봇, 테스트, kiwoom_rest_api 등)
이동: 사용 중 → legacy/ (holding_bot kis_holding_ver1 news_analyzer kis_long_ver1/2)
신규: kis_trader/utils/legacy_root.py legacy/README.md remove/README.md
import 경로: backtest_web.py mm_butler.py mm_remote.py updow_holding_cfg.py dbband_stock_cfg.py param_search_updow*.py dbband_param_search.py param_search_apply_snapshot.py verify_three_paths.py
docs/like_mcp.md/code_architecture.md 수동 노트
메시지 초안

chore: 미사용 루트는 remove/, 웹·알람 구모듈은 legacy/
remove는 나중에 통째 삭제 예정. holding_bot·news_analyzer·kis_long은
ensure_legacy_root로 legacy/만 본다.
빼기: scratch/set_ws_price_max_age_zero.py (일회성)
This commit is contained in:
Your Name
2026-08-18 00:13:17 +09:00
parent 36a3e2b4a1
commit 6d2a706a48
1416 changed files with 0 additions and 0 deletions

View 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