init
This commit is contained in:
@@ -432,14 +432,6 @@ class Bithumb_minute(HTS):
|
||||
|
||||
return
|
||||
|
||||
def getBalance(self, ticker):
|
||||
tmp = self.bithumb.get_balance(ticker)
|
||||
return tmp[2]
|
||||
|
||||
def getCount(self, ticker):
|
||||
tmp = self.bithumb.get_balance(ticker)
|
||||
return tmp[0]
|
||||
|
||||
def exist_buy(self, ticker, log_filename):
|
||||
if os.path.exists(log_filename):
|
||||
log_file = open(log_filename, 'r', )
|
||||
@@ -656,6 +648,31 @@ class Bithumb_minute(HTS):
|
||||
df.set_index('datetime', inplace=True)
|
||||
return df
|
||||
|
||||
def cancel_order(self, log_filename, min=10):
|
||||
tmp_transactions = []
|
||||
if os.path.exists(log_filename):
|
||||
with open(log_filename, 'r', encoding='utf-8') as log_file:
|
||||
rd = csv.reader(log_file)
|
||||
for line in rd:
|
||||
tmp_transactions.append(line)
|
||||
|
||||
transactions = []
|
||||
for tmp_transaction in tmp_transactions:
|
||||
if tmp_transaction[0] == 'buy':
|
||||
diff = datetime.now() - datetime.strptime(tmp_transaction[1], '%Y-%m-%d %H:%M:%S')
|
||||
if 60*min < diff.seconds:
|
||||
order = (tmp_transaction[2], tmp_transaction[3], tmp_transaction[4], tmp_transaction[5])
|
||||
cancel = self.bithumb.cancel_order(order)
|
||||
continue
|
||||
transactions.append(tmp_transaction)
|
||||
|
||||
with open(log_filename, 'w', newline='', encoding='utf-8') as log_file:
|
||||
wr = csv.writer(log_file)
|
||||
for transaction in transactions:
|
||||
wr.writerow(transaction)
|
||||
|
||||
return
|
||||
|
||||
def buyRealTime(self, ticker, isRealTime=False):
|
||||
|
||||
stock = {"CODE": ticker, "NAME": ticker, "PRICE": []}
|
||||
@@ -695,24 +712,29 @@ class Bithumb_minute(HTS):
|
||||
# 그래프를 그린다.
|
||||
if len(data.index) > 10:
|
||||
today = datetime.today().strftime('%Y%m%d')
|
||||
log_filename = os.path.join(RESOURCE_PATH, 'analysis', 'bithumb', today + '.log')
|
||||
log_filename = os.path.join(RESOURCE_PATH, 'order', "bithumb"+"_"+today + '.log')
|
||||
|
||||
# 10분이 지난 미체결은 취소한다.
|
||||
self.cancel_order(log_filename, 10)
|
||||
if isRealTime:
|
||||
if not self.exist_buy(ticker, log_filename):
|
||||
if max(bsLine['buy'][len(bsLine['buy']) - 2:]) > 100:
|
||||
balance = self.getBalance(ticker)
|
||||
tmp = self.bithumb.get_balance(ticker)
|
||||
balance = tmp[2]
|
||||
count = round((balance * (bsLine['buy_weight'][len(bsLine['buy_weight']) - 1] / 100)) / bsLine['buy'][len(bsLine['buy']) - 1], 2)
|
||||
order = self.bithumb.buy_limit_order(ticker, bsLine['buy'][len(bsLine['buy']) - 1], count)
|
||||
# order: ('bid', 'BTC', 'C0101000000322993432', 'KRW')
|
||||
|
||||
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]])
|
||||
wr.writerow(["buy", datetime.now().strftime('%Y-%m-%d %H:%M:%S'), order[0], order[1], order[2], order[3]])
|
||||
|
||||
dirName = os.path.join(RESOURCE_PATH, 'analysis', 'bithumb')
|
||||
self.writeFile(dirName, ticker, data, bsLine, datetime.now().strftime('%Y%m%d %H%M%S'), 'buy')
|
||||
|
||||
if max(bsLine['sell'][len(bsLine['sell']) - 2:]) > 100:
|
||||
count = self.getCount(ticker)
|
||||
tmp = self.bithumb.get_balance(ticker)
|
||||
count = tmp[0]
|
||||
order = self.bithumb.sell_limit_order(ticker, bsLine['sell'][len(bsLine['sell'])-1], count)
|
||||
|
||||
dirName = os.path.join(RESOURCE_PATH, 'analysis', 'bithumb')
|
||||
@@ -738,7 +760,7 @@ if __name__ == "__main__":
|
||||
bithumb = Bithumb_minute(RESOURCE_PATH)
|
||||
|
||||
tickers = ['XRP']
|
||||
isRealTime = True
|
||||
isRealTime = False
|
||||
if isRealTime:
|
||||
while True:
|
||||
for ticker in tickers:
|
||||
|
||||
Reference in New Issue
Block a user