update
This commit is contained in:
		| @@ -37,28 +37,20 @@ class WMA: | |||||||
|  |  | ||||||
|  |  | ||||||
| class MA_Cross: | class MA_Cross: | ||||||
|   def __init__(self, ma, unit, width): |   def __init__(self, ma, unit): | ||||||
|     self._ma    = ma |     self._ma    = ma | ||||||
|     self._unit  = unit |     self._unit  = unit | ||||||
|     self._width = width |  | ||||||
|  |  | ||||||
|     self._period_short = 5 |     self._period_short = 21 | ||||||
|     self._period_mid   = 21 |     self._period_mid   = 55 | ||||||
|     self._period_long  = 55 |  | ||||||
|  |  | ||||||
|     self._posi_amp = 0.1 |  | ||||||
|  |  | ||||||
|   def judge(self, status): |   def judge(self, status): | ||||||
|     cands = status.candles[self._unit] |     cands = status.candles[self._unit] | ||||||
|     short = self._ma.calc(cands, self._period_short) |     short = self._ma.calc(cands, self._period_short) | ||||||
|     mid   = self._ma.calc(cands, self._period_mid) |     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 |     diff  = short - mid | ||||||
|     if diff < 0: |     if diff < 0: | ||||||
|       return max(-1, diff/width+posi)  # sell |       return -1  # sell | ||||||
|     else: |     else: | ||||||
|       return min(1, diff/width+posi)  # buy |       return 1  # buy | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								bitbank.py
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								bitbank.py
									
									
									
									
									
								
							| @@ -23,26 +23,8 @@ def init(): | |||||||
|     return [] |     return [] | ||||||
|  |  | ||||||
|   procs = [] |   procs = [] | ||||||
|   procs.append(Fetcher(pub, "qtum_jpy", 5*60)) |   procs.append(Fetcher(pub, "btc_jpy", 30)) | ||||||
|   procs.append(Proc(pri, "qtum_jpy",   2000, algo.MA_Cross(algo.EMA(), "1h", 0.01), 5*60)) |   procs.append(Proc(pri, "btc_jpy", 2000, algo.MA_Cross(algo.SMA(), "1m"), 30)) | ||||||
|  |  | ||||||
|   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)) |  | ||||||
|   return procs |   return procs | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -60,17 +42,17 @@ class Fetcher: | |||||||
|     now = time.time() |     now = time.time() | ||||||
|     if now-self._last_update < self._interval: |     if now-self._last_update < self._interval: | ||||||
|       return |       return | ||||||
|  |     self._last_update = now | ||||||
|     try: |     try: | ||||||
|       st = algo.Status() |       st = algo.Status() | ||||||
|  |  | ||||||
|       st.candles["1h"] = self._get_candle("1hour", 60) |       st.candles["1m"] = self._get_candle("1min", 60) | ||||||
|       st.price = st.candles["1h"][0][3] |       st.price = st.candles["1m"][0][3] | ||||||
|  |  | ||||||
|       global status |       global status | ||||||
|       status[self._pair] = st |       status[self._pair] = st | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|       print("fetce error:", e) |       print("fetce error:", e) | ||||||
|     self._last_update = now |  | ||||||
|  |  | ||||||
|   def _get_candle(self, unit, n, t = datetime.datetime.now(tz=datetime.timezone.utc)): |   def _get_candle(self, unit, n, t = datetime.datetime.now(tz=datetime.timezone.utc)): | ||||||
|     data = self._pub.get_candlestick( |     data = self._pub.get_candlestick( | ||||||
| @@ -111,8 +93,8 @@ class Proc: | |||||||
|   def tick(self): |   def tick(self): | ||||||
|     self._now = time.time() |     self._now = time.time() | ||||||
|     if self._now-self._last_update > self._interval: |     if self._now-self._last_update > self._interval: | ||||||
|       self._update() |  | ||||||
|       self._last_update = self._now |       self._last_update = self._now | ||||||
|  |       self._update() | ||||||
|  |  | ||||||
|   def _update(self): |   def _update(self): | ||||||
|     global status |     global status | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user