add WMA algorithm with bitbank bot

This commit is contained in:
2022-07-12 23:03:32 +09:00
parent 37840311e0
commit ecb9ad08e1
8 changed files with 304 additions and 0 deletions

2
algorithm/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
from algorithm.wma import WMA
from algorithm.status import Status

4
algorithm/status.py Normal file
View File

@@ -0,0 +1,4 @@
class Status:
def __init__(self):
self.price = 0
self.candles = {"1m": [], "1h": []}

22
algorithm/wma.py Normal file
View File

@@ -0,0 +1,22 @@
class WMA:
def __init__(self, unit, period, width):
self._unit = unit
self._period = period
self._width = width
def judge(self, status):
cands = status.candles[self._unit]
sum = 0
den = 0
for i in range(min(self._period-1, len(cands)-1)):
sum += cands[i+1][3] * (i+1)
den += i+1
avg = sum / den
price = cands[0][3]
width = price * self._width
diff = price - avg
if diff < 0:
return max(-1, diff/width) # sell
else:
return min(1, diff/width) # buy