테스트
This commit is contained in:
@@ -23,8 +23,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="api_test.py" />
|
<Compile Include="api_test.py" />
|
||||||
|
<Compile Include="data_checker.py">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="data_manager.py" />
|
<Compile Include="data_manager.py" />
|
||||||
<Compile Include="main.py" />
|
<Compile Include="main.py" />
|
||||||
|
<Compile Include="transaction.py">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="xcoin_api_client.py" />
|
<Compile Include="xcoin_api_client.py" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
|
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
|
||||||
|
|||||||
59
data_checker.py
Normal file
59
data_checker.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import transaction
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
LIST_SIZE=20
|
||||||
|
INITIAL_LIMIT=5
|
||||||
|
FAST_SD=0.75
|
||||||
|
FAST_UP=0.05
|
||||||
|
FAST_DOWN=0.05
|
||||||
|
SLOW_SD=0.2
|
||||||
|
SLOW_UP=0.4
|
||||||
|
SLOW_DOWN=0.4
|
||||||
|
TIME_LIMIT=6
|
||||||
|
TIME_DOWN=0.02
|
||||||
|
IGNORE_PRICE=50000
|
||||||
|
|
||||||
|
|
||||||
|
class DataChecker:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.tr_list = []
|
||||||
|
self.condition_limit = Config.INITIAL_LIMIT
|
||||||
|
self.condition_cnt = 0
|
||||||
|
self.type = 'bid'
|
||||||
|
|
||||||
|
def add(self, tr: transaction.Transaction):
|
||||||
|
if len(self.tr_list) >= Config.LIST_SIZE:
|
||||||
|
self.tr_list = self.tr_list[1:]
|
||||||
|
self.tr_list.append(tr)
|
||||||
|
|
||||||
|
avg = sum(tr.price for tr in self.tr_list) / len(self.tr_list)
|
||||||
|
variance = sum((tr.price-avg)**2 for tr in self.tr_list) / len(self.tr_list)
|
||||||
|
sd = variance**0.5
|
||||||
|
|
||||||
|
if sd >= Config.FAST_SD:
|
||||||
|
if tr.price >= avg:
|
||||||
|
self.condition_limit += Config.FAST_UP
|
||||||
|
else:
|
||||||
|
self.condition_limit -= Config.FAST_DOWN
|
||||||
|
else:
|
||||||
|
if tr.price >= avg:
|
||||||
|
self.condition_limit += Config.SLOW_UP
|
||||||
|
else:
|
||||||
|
self.condition_limit -= Config.SLOW_DOWN
|
||||||
|
|
||||||
|
if self.type == tr.type:
|
||||||
|
self.condition_cnt += 1
|
||||||
|
else:
|
||||||
|
self.condition_cnt = 0
|
||||||
|
|
||||||
|
buy_or_sell = False
|
||||||
|
if self.condition_cnt >= self.condition_limit:
|
||||||
|
buy_or_sell = True
|
||||||
|
self.type = 'ask' if self.type == 'bid' else 'ask'
|
||||||
|
self.condition_cnt = 0
|
||||||
|
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 ''))
|
||||||
|
|
||||||
|
|
||||||
@@ -1,31 +1,19 @@
|
|||||||
|
import transaction
|
||||||
class Transaction:
|
import data_checker
|
||||||
def __init__(self):
|
|
||||||
self.time = None
|
|
||||||
self.price = None
|
|
||||||
self.unit = 0
|
|
||||||
self.type = None
|
|
||||||
|
|
||||||
def __init__(self, item):
|
|
||||||
self.time = item['transaction_date']
|
|
||||||
self.price = int(item['price'])
|
|
||||||
self.unit = float(item['units_traded'])
|
|
||||||
self.type = item['type']
|
|
||||||
|
|
||||||
def __str__(self, **kwargs):
|
|
||||||
return '[{}] {} {}'.format(self.time, self.type, self.price)
|
|
||||||
|
|
||||||
|
|
||||||
class DataMgr:
|
class DataMgr:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.transactions = {}
|
self.transactions = {}
|
||||||
|
self.data_checker = data_checker.DataChecker()
|
||||||
|
|
||||||
def insert(self, item):
|
def insert(self, item):
|
||||||
transactions_new = {}
|
transactions_new = {}
|
||||||
tr = Transaction(item)
|
tr = transaction.Transaction(item)
|
||||||
if tr.time in self.transactions:
|
if tr.time in self.transactions:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.data_checker.add(tr)
|
||||||
self.transactions[tr.time] = tr
|
self.transactions[tr.time] = tr
|
||||||
print(tr)
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
17
transaction.py
Normal file
17
transaction.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class Transaction:
|
||||||
|
def __init__(self):
|
||||||
|
self.time = None
|
||||||
|
self.price = None
|
||||||
|
self.unit = 0
|
||||||
|
self.type = None
|
||||||
|
|
||||||
|
def __init__(self, item):
|
||||||
|
self.time = item['transaction_date']
|
||||||
|
self.price = int(item['price'])
|
||||||
|
self.unit = float(item['units_traded'])
|
||||||
|
self.type = item['type']
|
||||||
|
|
||||||
|
def __str__(self, **kwargs):
|
||||||
|
return '[{}] {} {}'.format(self.time, self.type, self.price)
|
||||||
Reference in New Issue
Block a user