diff --git a/Bithumb.py b/Bithumb.py index 1dd0a61..cd4f47f 100644 --- a/Bithumb.py +++ b/Bithumb.py @@ -18,7 +18,6 @@ class Bithumb(HTS): RESOURCE_PATH = None buySellChecker = None analyzerSqlite = None - log_filename = None def __init__(self, RESOURCE_PATH): super().__init__(RESOURCE_PATH) @@ -33,8 +32,6 @@ class Bithumb(HTS): self.buySellChecker = BuySellChecker() self.analyzerSqlite = AnalyzerSqlite() - self.log_filename = os.path.join(RESOURCE_PATH, 'analysis', 'bithumb', 'transaction.json') - return def bull_market(self, df, ticker): @@ -413,6 +410,17 @@ class Bithumb(HTS): def getBalance(self, ticker): tmp = self.bithumb.get_balance(ticker) return tmp[2] + + def exist_buy(self, ticker, log_filename): + log_file = open('data.csv', 'r', ) + reader = csv.reader(log_file) + for line in reader: + if line[2] == ticker: + log_file.close() + return True + log_file.close() + return False + def buyRealTime(self, ticker, isRealTime=False): stock = {"CODE": ticker, "NAME": ticker, "PRICE": []} @@ -436,14 +444,16 @@ class Bithumb(HTS): # 그래프를 그린다. if len(data.index) > 10: - if not isRealTime: + today = datetime.today().strftime('%Y%m%d') + log_filename = os.path.join(RESOURCE_PATH, 'analysis', 'bithumb', today + '.log') + if not isRealTime and self.exist_buy(ticker, log_filename): if max(bsLine['buy'][len(bsLine['buy']) - 2:]) > 100: balance = self.getBalance(ticker) count = int(balance * (bsLine['buy_weight'][len(bsLine['buy_weight'])-1]/100)) order = self.bithumb.buy_limit_order(ticker, bsLine['buy'][len(bsLine['buy'])-1], count) # order: ('bid', 'BTC', 'C0101000000322993432', 'KRW') - with open(self.log_filename, 'a', newline='') as log_file: + with open(log_filename, 'a', newline='', encoding='utf-8') as log_file: wr = csv.writer(log_file) wr.writerow([datetime.now().strftime('%Y-%m-%d %H:%M:%S'), order[0], order[1], order[2], order[3]]) else: diff --git a/resources/order/122630_20220708.csv b/resources/order/122630_20220708.csv deleted file mode 100644 index 1bbc594..0000000 --- a/resources/order/122630_20220708.csv +++ /dev/null @@ -1,7 +0,0 @@ -,stock_code,type,orderNum,count,price,datetime -0,122630,2,2,20,14555,2022-07-08 12:07:04.174773 -1,122630,2,2,20,14585,2022-07-08 13:01:04.328865 -2,122630,2,2,20,14570,2022-07-08 13:24:03.429791 -3,122630,2,2,20,14625,2022-07-08 14:27:03.920891 -4,122630,2,2,20,14615,2022-07-08 14:33:03.578675 -5,122630,2,2,20,14585,2022-07-08 14:47:04.028914 diff --git a/resources/order/252670_20220422.csv b/resources/order/252670_20220422.csv deleted file mode 100644 index 3584e61..0000000 --- a/resources/order/252670_20220422.csv +++ /dev/null @@ -1,2 +0,0 @@ -,stock_code,type,orderNum,count,price,datetime -0,252670,2,2,40,2570,2022-04-22 13:51:03.587620 diff --git a/resources/order/252670_20220526.csv b/resources/order/252670_20220526.csv deleted file mode 100644 index fe452f2..0000000 --- a/resources/order/252670_20220526.csv +++ /dev/null @@ -1,4 +0,0 @@ -,stock_code,type,orderNum,count,price,datetime -0,252670,2,2,300,2665,2022-05-26 11:38:06.850113 -1,252670,2,2,300,2665,2022-05-26 11:39:03.672531 -2,252670,2,2,300,2680,2022-05-26 13:09:03.891335 diff --git a/resources/order/252670_20220527.csv b/resources/order/252670_20220527.csv deleted file mode 100644 index 7502f10..0000000 --- a/resources/order/252670_20220527.csv +++ /dev/null @@ -1,2 +0,0 @@ -,stock_code,type,orderNum,count,price,datetime -0,252670,2,2,500,2640,2022-05-27 10:55:04.113265