버그 수정
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
|
log/
|
||||||
|
.vs/
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import datetime
|
||||||
import transaction
|
import transaction
|
||||||
|
|
||||||
|
|
||||||
@@ -50,10 +51,14 @@ class DataChecker:
|
|||||||
buy_or_sell = False
|
buy_or_sell = False
|
||||||
if self.condition_cnt >= self.condition_limit:
|
if self.condition_cnt >= self.condition_limit:
|
||||||
buy_or_sell = True
|
buy_or_sell = True
|
||||||
self.type = 'ask' if self.type == 'bid' else 'ask'
|
self.type = 'ask' if self.type == 'bid' else 'bid'
|
||||||
self.condition_cnt = 0
|
self.condition_cnt = 0
|
||||||
self.condition_limit = Config.INITIAL_LIMIT
|
self.condition_limit = Config.INITIAL_LIMIT
|
||||||
|
|
||||||
print('{} {:.2f} {:.2f} {:.2f} {} ({}) {}'.format(tr, avg, sd, self.condition_limit, self.condition_cnt, self.type, 'action!' if buy_or_sell else ''))
|
today = datetime.datetime.now().strftime('%Y-%m-%d')
|
||||||
|
with open('log/trade-{}.txt'.format(today), 'a') as the_file:
|
||||||
|
the_file.write('{} {:.2f} {:.2f} {:.2f} {} ({}) {}\n'.format(tr, avg, sd, self.condition_limit, self.condition_cnt, self.type, 'action!' if buy_or_sell else ''))
|
||||||
|
|
||||||
|
print('{} {} {:.2f} {:.2f} {:.2f} {} ({}) {}'.format(tr.key, tr, avg, sd, self.condition_limit, self.condition_cnt, self.type, 'action!' if buy_or_sell else ''))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,36 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
import transaction
|
import transaction
|
||||||
import data_checker
|
import data_checker
|
||||||
|
|
||||||
|
|
||||||
class DataMgr:
|
class DataMgr:
|
||||||
|
|
||||||
|
TR_MAX_CNT = 500
|
||||||
|
TR_MAINTAIN_CNT = 100
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.transactions = {}
|
self.transactions = []
|
||||||
self.data_checker = data_checker.DataChecker()
|
self.data_checker = data_checker.DataChecker()
|
||||||
|
|
||||||
|
def contains(self, tr: transaction.Transaction):
|
||||||
|
next_item = next((i for i, x in enumerate(self.transactions) if x.key == tr.key), None)
|
||||||
|
return (next_item is not None)
|
||||||
|
|
||||||
def insert(self, item):
|
def insert(self, item):
|
||||||
transactions_new = {}
|
|
||||||
tr = transaction.Transaction(item)
|
tr = transaction.Transaction(item)
|
||||||
if tr.time in self.transactions:
|
if self.contains(tr):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.data_checker.add(tr)
|
self.data_checker.add(tr)
|
||||||
self.transactions[tr.time] = tr
|
self.transactions.append(tr)
|
||||||
|
|
||||||
|
if len(self.transactions) >= DataMgr.TR_MAX_CNT:
|
||||||
|
today = datetime.datetime.now().strftime('%Y-%m-%d')
|
||||||
|
with open('log/log-{}.txt'.format(today), 'a') as log_file:
|
||||||
|
for key in self.transactions[:-DataMgr.TR_MAINTAIN_CNT]:
|
||||||
|
log_file.write('{}\n'.format(self.transactions[key]))
|
||||||
|
|
||||||
|
self.transactions = self.transactions[-DataMgr.TR_MAINTAIN_CNT:]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
11
main.py
11
main.py
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from xcoin_api_client import *
|
from xcoin_api_client import *
|
||||||
import sched
|
import sched
|
||||||
import time
|
import time
|
||||||
@@ -32,6 +34,9 @@ rgParams = {
|
|||||||
scheduler = sched.scheduler(time.time, time.sleep)
|
scheduler = sched.scheduler(time.time, time.sleep)
|
||||||
timer_delay = 0.1
|
timer_delay = 0.1
|
||||||
|
|
||||||
|
if not os.path.exists('log'):
|
||||||
|
os.makedirs('log')
|
||||||
|
|
||||||
def printTicker(result):
|
def printTicker(result):
|
||||||
print("["+time.strftime("%H:%M:%S")+"]" + " status: " + result["status"] + " last: " + result["data"]["closing_price"])
|
print("["+time.strftime("%H:%M:%S")+"]" + " status: " + result["status"] + " last: " + result["data"]["closing_price"])
|
||||||
|
|
||||||
@@ -40,6 +45,8 @@ def printTransaction(result):
|
|||||||
for item in result['data']:
|
for item in result['data']:
|
||||||
print('\t[' + item['transaction_date']+']' + item['type'] + ' ' + item['price']);
|
print('\t[' + item['transaction_date']+']' + item['type'] + ' ' + item['price']);
|
||||||
|
|
||||||
|
def printTransactionItem(item):
|
||||||
|
print('{}'.format(item))
|
||||||
|
|
||||||
datamgr = data_manager.DataMgr()
|
datamgr = data_manager.DataMgr()
|
||||||
def main(arg):
|
def main(arg):
|
||||||
@@ -49,6 +56,10 @@ def main(arg):
|
|||||||
|
|
||||||
result = api.xcoinApiCall("/public/recent_transactions/" + rgParams["order_currency"], rgParams)
|
result = api.xcoinApiCall("/public/recent_transactions/" + rgParams["order_currency"], rgParams)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
|
#for item in reversed(result['data']):
|
||||||
|
# printTransactionItem(item)
|
||||||
|
#print('--------------')
|
||||||
|
|
||||||
for item in reversed(result['data']):
|
for item in reversed(result['data']):
|
||||||
datamgr.insert(item)
|
datamgr.insert(item)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
class Transaction:
|
class Transaction:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.key = None
|
||||||
self.time = None
|
self.time = None
|
||||||
self.price = None
|
self.price = None
|
||||||
self.unit = 0
|
self.unit = 0
|
||||||
@@ -13,5 +14,7 @@ class Transaction:
|
|||||||
self.unit = float(item['units_traded'])
|
self.unit = float(item['units_traded'])
|
||||||
self.type = item['type']
|
self.type = item['type']
|
||||||
|
|
||||||
|
self.key = self.time + '_' + str(self.unit)
|
||||||
|
|
||||||
def __str__(self, **kwargs):
|
def __str__(self, **kwargs):
|
||||||
return '[{}] {} {}'.format(self.time, self.type, self.price)
|
return '[{}] {} {}'.format(self.time, self.type, self.price)
|
||||||
|
|||||||
Reference in New Issue
Block a user