Files
kis_trader/remove/legacy_root/sample_python/tr/tr_1857.py
Your Name 6d2a706a48 커밋 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 (일회성)
2026-08-18 00:13:17 +09:00

246 lines
9.1 KiB
Python

#종목검색
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))