This commit is contained in:
dosangyoon
2021-10-16 19:40:55 +09:00
parent b464987eba
commit 476e828226
3 changed files with 65 additions and 43 deletions

View File

@@ -18,28 +18,29 @@ class OrderChecker:
if os.path.isfile(fileName):
self.order_df = pd.read_csv(fileName)
else:
self.order_df = None
self.order_df = pd.DataFrame(columns=["type", "orderNum", "count", "price", "datetime"])
self.order_df = self.order_df.astype({"type": str, "orderNum": int, "count": int, "price": int})
self.order_df['datetime'] = pd.to_datetime(self.order_df['datetime'])
return
def add(self, type, orderNum, count, price, orderList):
orderListToCancel = []
if self.order_df is None:
self.order_df = pd.DataFrame()
else:
# 두 시간 전
before_two_hour = datetime.now() - timedelta(hours=2)
# 두 시간 전
before_two_hour = datetime.now() - timedelta(hours=2)
# 두 시간 전 주문을 찾는다.
if 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]
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]
# 두 시간 전 주문을 찾는다.
if 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]
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 = self.order_df.append({"type": type.value, "orderNum": orderNum, "count": count, "price": price, "datetime": datetime.now()}, ignore_index=True)
self.order_df.to_csv(self.saveFileName)
@@ -47,13 +48,19 @@ class OrderChecker:
return orderListToCancel
if __name__ == "__main__":
orderChecker = OrderChecker()
a = pd.DataFrame(columns=["type", "orderNum", "count", "price", "datetime"])
a = a.astype({"type": str, "orderNum": int, "count": int, "price": int})
a['datetime'] = pd.to_datetime(a['datetime'])
a = pd.DataFrame(columns=["a", "b", "c", "d", "e"])
a = a.append({"a": 0, "b": 1, "c": 3, "d": 7, "e": 8}, ignore_index=True)
a = a.append({"a": 1, "b": 3, "c": 0, "d": 6, "e": 6}, ignore_index=True)
a = a.append({"a": 2, "b": 3, "c": 0, "d": 3, "e": 9}, ignore_index=True)
a = a.append({"a": 3, "b": 9, "c": 9, "d": 8, "e": 4}, ignore_index=True)
this_time = datetime.now()
a = a.append({"type": "0", "orderNum": 1, "count": 3, "price": 7, "datetime": this_time}, ignore_index=True)
a = a.append({"type": "1", "orderNum": 3, "count": 0, "price": 6, "datetime": this_time - timedelta(hours=2)}, ignore_index=True)
a = a.append({"type": "2", "orderNum": 3, "count": 0, "price": 3, "datetime": this_time + timedelta(hours=1)}, ignore_index=True)
a = a.append({"type": "1", "orderNum": 9, "count": 9, "price": 8, "datetime": this_time}, ignore_index=True)
a = a.loc[a["b"] != 3]
print(a.tail())
b = a.loc[a["orderNum"] != 3]
print(b.tail())
print()
b = a.loc[a["datetime"] < this_time]
print(b.tail())