init
This commit is contained in:
23
hts/HTS.py
23
hts/HTS.py
@@ -548,6 +548,7 @@ class HTS:
|
||||
def buyRealTime(self, stock_code, GIVEN_DAY):
|
||||
orderChecker = OrderChecker()
|
||||
BASE_COUNT = 100
|
||||
ORDER_LIST = None
|
||||
|
||||
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
||||
timecheck = {GIVEN_DAY + " " + str(second).zfill(6):False for second, check in timecheckList}
|
||||
@@ -578,31 +579,37 @@ class HTS:
|
||||
data_size = len(data["Close"])
|
||||
final_price = data["Close"][data_size-1]
|
||||
|
||||
if bs_buy_price > 0 or bs_sell_price > 0:
|
||||
# 미체결 기록을 가져온다.
|
||||
ORDER_LIST = self.requestOrderList()
|
||||
|
||||
if bs_buy_price > 0:
|
||||
# 기본 100 주에 가중치를 추가해서 매수한다.
|
||||
BUY_COUNT = int(BASE_COUNT * bs_weight)
|
||||
|
||||
# 매수를 주문한다.
|
||||
# 매수를 요청한다.
|
||||
orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price)
|
||||
# 미체결 기록을 가져온다.
|
||||
orderList = self.requestOrderList()
|
||||
# 매수 주문을 기록한다.
|
||||
orderListToCancel = orderChecker.add(OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, orderList)
|
||||
# 두 시간 이전 미체결을 취소한다.
|
||||
orderListToCancel = orderChecker.add(OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST)
|
||||
# 두 시간 이전 미체결을 모두 취소한다.
|
||||
self.cancelOrderList(orderListToCancel)
|
||||
# 로그 출력
|
||||
print("BUY", THIS_TIME, BUY_COUNT, bs_buy_price)
|
||||
|
||||
if bs_sell_price > 0:
|
||||
# 매도 주문을 기록한다.
|
||||
orderListToCancel = orderChecker.remove(OrderType.sell, ORDER_LIST)
|
||||
# 매도 미체결을 모두 취소한다.
|
||||
self.cancelOrderList(orderListToCancel)
|
||||
|
||||
# 매도 가격을 가져온다.
|
||||
selling_count, selling_price = self.getSellingPrice(final_price)
|
||||
# 분석되 가격으로 매도 요청한다.
|
||||
if selling_count != 0 and selling_price != 0:
|
||||
# 매도를 요청한다.
|
||||
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
|
||||
# 미체결 기록을 가져온다.
|
||||
orderList = self.requestOrderList()
|
||||
# 매도 주문을 기록한다.
|
||||
orderListToCancel = orderChecker.add(OrderType.sell, orderNum, selling_count, selling_price, orderList)
|
||||
orderListToCancel = orderChecker.add(OrderType.sell, orderNum, selling_count, selling_price, ORDER_LIST)
|
||||
# 두 시간 이전 미체결을 취소한다.
|
||||
self.cancelOrderList(orderListToCancel)
|
||||
# 로그 출력
|
||||
|
||||
@@ -31,7 +31,7 @@ class OrderChecker:
|
||||
before_two_hour = datetime.now() - timedelta(hours=2)
|
||||
|
||||
# 두 시간 전 주문을 찾는다.
|
||||
if len(orderList) > 0:
|
||||
if orderList is not None and len(orderList) > 0:
|
||||
# 만약 두시간 전 주문을 찾는다.
|
||||
orderNum_df = self.order_df.loc[self.order_df["datetime"] <= before_two_hour]
|
||||
orderNum_df = orderNum_df.loc[orderNum_df["type"] == OrderType.buy.value]
|
||||
@@ -47,6 +47,21 @@ class OrderChecker:
|
||||
|
||||
return orderListToCancel
|
||||
|
||||
def remove(self, type, orderList):
|
||||
orderListToCancel = []
|
||||
|
||||
if orderList is not None and len(orderList) > 0:
|
||||
orderNum_df = self.order_df.loc[self.order_df["type"] == type.value]
|
||||
orderNumSet = set(list(orderNum_df["orderNum"]))
|
||||
for item in orderList:
|
||||
if item.orderNum in orderNumSet:
|
||||
orderListToCancel.append(item)
|
||||
# 해당 orderNum 제외하기
|
||||
self.order_df = self.order_df.loc[self.order_df["orderNum"] != item.orderNum]
|
||||
self.order_df.to_csv(self.saveFileName)
|
||||
|
||||
return orderListToCancel
|
||||
|
||||
if __name__ == "__main__":
|
||||
a = pd.DataFrame(columns=["type", "orderNum", "count", "price", "datetime"])
|
||||
a = a.astype({"type": str, "orderNum": int, "count": int, "price": int})
|
||||
|
||||
Reference in New Issue
Block a user