kimtaewoo90 / CoinGo

0 stars 0 forks source link

#TODO.04 Make a new Strategy called RSI Strategy #6

Open kimtaewoo90 opened 2 years ago

kimtaewoo90 commented 2 years ago

Strategy3. RSI Strategy

  1. RSI value 30 아래로 내려갔다가 다시 30 위로 올라올 때 매수
  2. RSI value 70이상으로 올라갔다가 다시 70이하로 내려올때 매도
  3. 30아래로 내려갔다가 다시 30위로 올라갔는데 다시 30이하로 내려가면 매도
kimtaewoo90 commented 2 years ago

def rsi_upbit(itv, symbol="KRW-BTC"): url = "https://api.upbit.com/v1/candles/minutes/"+str(itv) querystring = {"market" : symbol, "count" : "200"} response = requests.request("GET", url, params=querystring) data = response.json() df =pd.DataFrame(data) df=df.reindex(index=df.index[::-1]).reset_index() nrsi=rsi_calc(df, 14).iloc[-1] print("현재" + str(itv) +"분 rsi :" +str(nrsi))

return nrsi

def rsi_calc(ohlc: pd.DataFrame, period: int = 14): ohlc["trade_price"] = ohlc["trade_price"] delta = ohlc["trade_price"].diff() gains, declines = delta.copy(), delta.copy() gains[gains < 0] = 0 declines[declines > 0] = 0

_gain = gains.ewm(com=(period-1), min_periods=period).mean()
_loss = declines.abs().ewm(com=(period-1), min_periods=period).mean()

RS = _gain / _loss
return pd.Series(100-(100/(1+RS)), name="RSI")    
kimtaewoo90 commented 2 years ago

Q) 각 전략이 Thread로 독립적으로 움직여야 할까?