This commit is contained in:
falsycat 2022-07-14 06:14:50 +09:00
parent fecec43e33
commit 3cd6db5831
2 changed files with 11 additions and 37 deletions

View File

@ -37,28 +37,20 @@ class WMA:
class MA_Cross:
def __init__(self, ma, unit, width):
def __init__(self, ma, unit):
self._ma = ma
self._unit = unit
self._width = width
self._period_short = 5
self._period_mid = 21
self._period_long = 55
self._posi_amp = 0.1
self._period_short = 21
self._period_mid = 55
def judge(self, status):
cands = status.candles[self._unit]
short = self._ma.calc(cands, self._period_short)
mid = self._ma.calc(cands, self._period_mid)
long = self._ma.calc(cands, self._period_long)
width = mid * self._width
posi = max(-1, min((short-long)/(2.5*width), 1)) * self._posi_amp
diff = short - mid
if diff < 0:
return max(-1, diff/width+posi) # sell
return -1 # sell
else:
return min(1, diff/width+posi) # buy
return 1 # buy

View File

@ -23,26 +23,8 @@ def init():
return []
procs = []
procs.append(Fetcher(pub, "qtum_jpy", 5*60))
procs.append(Proc(pri, "qtum_jpy", 2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "xrp_jpy", 5*60))
procs.append(Proc(pri, "xrp_jpy", 2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "xlm_jpy", 5*60))
procs.append(Proc(pri, "xlm_jpy", 2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "bat_jpy", 5*60))
procs.append(Proc(pri, "bat_jpy", 2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "xym_jpy", 5*60))
procs.append(Proc(pri, "xym_jpy", 2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "btc_jpy", 5*60))
procs.append(Proc(pri, "btc_jpy", 5000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "eth_jpy", 5*60))
procs.append(Proc(pri, "eth_jpy", 5000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60))
procs.append(Fetcher(pub, "btc_jpy", 30))
procs.append(Proc(pri, "btc_jpy", 2000, algo.MA_Cross(algo.SMA(), "1m"), 30))
return procs
@ -60,17 +42,17 @@ class Fetcher:
now = time.time()
if now-self._last_update < self._interval:
return
self._last_update = now
try:
st = algo.Status()
st.candles["1h"] = self._get_candle("1hour", 60)
st.price = st.candles["1h"][0][3]
st.candles["1m"] = self._get_candle("1min", 60)
st.price = st.candles["1m"][0][3]
global status
status[self._pair] = st
except Exception as e:
print("fetce error:", e)
self._last_update = now
def _get_candle(self, unit, n, t = datetime.datetime.now(tz=datetime.timezone.utc)):
data = self._pub.get_candlestick(
@ -111,8 +93,8 @@ class Proc:
def tick(self):
self._now = time.time()
if self._now-self._last_update > self._interval:
self._update()
self._last_update = self._now
self._update()
def _update(self):
global status