This commit is contained in:
dsyoon
2023-10-13 22:23:19 +09:00
parent c0f2a3e025
commit 0f02e5b5de
2 changed files with 9 additions and 10 deletions

View File

@@ -156,7 +156,7 @@ class HTS_etf(HTS):
if buy_count > 0:
# 매수를 주문한다.
orderNum = self.requestOrder(OrderType.buy, stock_code, buy_count, bs_buy_price, self.slackBot)
orderNum = self.requestOrder(OrderType.buy, stock_code, buy_count, bs_buy_price)
self.orderChecker.buy(today, "A" + stock_code, buy_count, bs_buy_price, orderNum)
# 로그 출력

View File

@@ -8,6 +8,7 @@ import time
import sqlite3
from datetime import datetime, timedelta
from hts.OrderItem import OrderItem
from stock.util.SlackBot import SlackBot
class HTS:
@@ -20,7 +21,7 @@ class HTS:
def __init__(self, RESOURCE_PATH):
self.RESOURCE_PATH = RESOURCE_PATH
#self.connect()
self.slackBot = SlackBot()
self.connect2DB(os.path.join( RESOURCE_PATH, "hts.db"))
return
@@ -156,21 +157,21 @@ class HTS:
return result
# 주식 현금 매수주문
def requestOrder(self, type, stock_code, count, price, slackBot=None):
def requestOrder(self, type, stock_code, count, price):
# type = 2: buy, type=1: sell
# 주문 초기화
# 연결 여부 체크
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
bConnect = objCpCybos.IsConnect
if (bConnect == 0):
slackBot.sendMsg("PLUS가 정상적으로 연결되지 않음. ")
self.slackBot.sendMsg("PLUS가 정상적으로 연결되지 않음. ")
print("PLUS가 정상적으로 연결되지 않음. ")
exit()
objTrade = win32com.client.Dispatch("CpTrade.CpTdUtil")
initCheck = objTrade.TradeInit(0)
if (initCheck != 0):
slackBot.sendMsg("주문 초기화 실패")
self.slackBot.sendMsg("주문 초기화 실패")
print("주문 초기화 실패")
exit()
@@ -202,18 +203,16 @@ class HTS:
rqRet = objStockOrder.GetDibMsg1()
print("통신상태", rqStatus, rqRet)
if rqStatus != 0:
slackBot.sendMsg("통신상태: "+ str(rqStatus)+' ('+str(rqRet)+')')
self.slackBot.sendMsg("통신상태: "+ str(rqStatus)+" ("+str(rqRet)+")")
return None
orderNum = objStockOrder.GetHeaderValue(0)
if (type == "1"):
if slackBot is not None:
slackBot.post_to_slack(stock_code, stock_code, "SELL", price, count)
self.slackBot.post_to_slack(stock_code, stock_code, "SELL", price, count)
print ("(SELL", count, price, ")")
else:
if slackBot is not None:
slackBot.post_to_slack(stock_code, stock_code, "BUY", price, count)
self.slackBot.post_to_slack(stock_code, stock_code, "BUY", price, count)
print ("(BUY", count, price, ")")
return orderNum