Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialCrafter committed Nov 16, 2023
2 parents e7553f0 + 8f65d5b commit cdc6954
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 56 deletions.
2 changes: 1 addition & 1 deletion algorithms/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def algorithm(prices, window_size=14):
def signal(prices, data, high=70, low=30):
rsi = data
if rsi[-1] > high:
strength = ( rsi[-1] - high ) * ( 1 / low )
strength = (rsi[-1] - high) * (1 / low)
return 'sell', strength
elif rsi[-1] < low:
strength = 1 - rsi[-1] * (1 / low)
Expand Down
4 changes: 1 addition & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"pair": "ETH/USD"
}
{}
60 changes: 11 additions & 49 deletions plot.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,23 @@
import json
import numpy as np
import matplotlib.pyplot as plt
from price import get_prices
from algorithms.bollinger_bands import algorithm as boillinger_bands
from algorithms.rsi import algorithm as rsi
from algorithms.macd import algorithm as macd
from plots.bollinger_bands import plot as boillinger_bands
from plots.rsi import plot as rsi

# @TODO split plotting off into another algorithm function. def plot(subplot, prices, data)
config = json.load(open('config.json', 'r'))
prices = get_prices(address=config['address'] if 'address' in config else None)

prices = get_prices('ETH/USD', interval=1440)

upper_band, lower_band, middle_band = boillinger_bands(prices)
rsi_data = rsi(prices)
macd, signal = macd(prices)

bb_indicies = np.arange(0, upper_band.shape[0])
rsi_indicies = np.arange(0, rsi_data.shape[0])
macd_indicies = np.arange(0, macd.shape[0])

## Boillinger Bands
# RSI
plt.subplot(221)
rsi(prices)

bb_sliced_prices = prices[:upper_band.shape[0]]
plt.fill_between(bb_indicies, upper_band, lower_band, color='grey', alpha=0.3)

# Price/SMA
plt.plot(bb_indicies, bb_sliced_prices, color='plum')
plt.plot(bb_indicies, middle_band, color='mediumpurple')

# Buy/Sell Signals
bb_upper_condition = bb_sliced_prices >= upper_band
bb_lower_condition = bb_sliced_prices <= lower_band

plt.scatter(bb_indicies[bb_upper_condition], bb_sliced_prices[bb_upper_condition], color='lightcoral')
plt.scatter(bb_indicies[bb_lower_condition], bb_sliced_prices[bb_lower_condition], color='darkturquoise')

## RSI
# Boillinger Bands
plt.subplot(222)
plt.plot(rsi_indicies, rsi_data, color='plum')

# Thresholds
rsi_upper = np.full(rsi_data.shape, 70)
rsi_lower = np.full(rsi_data.shape, 30)

plt.fill_between(rsi_indicies, rsi_upper, rsi_lower, color='grey', alpha=0.3)
plt.plot(rsi_indicies, rsi_upper, linestyle='dashed', color='lightcoral')
plt.plot(rsi_indicies, rsi_lower, linestyle='dashed', color='darkturquoise')
boillinger_bands(prices)

## MACD
# Prices
plt.subplot(223)

macd_upper_condition = macd > signal
macd_lower_condition = macd < signal

plt.scatter(macd_indicies[macd_upper_condition], signal[macd_upper_condition], color='darkturquoise')
plt.scatter(macd_indicies[macd_lower_condition], signal[macd_lower_condition], color='lightcoral')

plt.plot(signal, color='plum')
plt.plot(macd, color='mediumpurple')
plt.plot(np.arange(0, prices.shape[0]), prices)

plt.show()
2 changes: 1 addition & 1 deletion price.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def get_prices(pair, interval=15):
current = float(list(ticker['result'].values())[0]['c'][0])
prices = [float(point[4]) for point in list(ohlc['result'].values())[0]]

return np.array([current, *prices])
return np.array([*prices, current])
5 changes: 3 additions & 2 deletions views/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import io
import io, json
import matplotlib
import matplotlib.pyplot as plt
import plots.colors as colors
Expand All @@ -10,7 +10,8 @@
matplotlib.use('Agg')

def plot(algorithm):
prices = get_prices('ETH/USD', interval=1440)
config = json.load(open('config.json', 'r'))
prices = get_prices(config['pair'], interval=1440)

if algorithm not in get_algorithms():
return 'Invalid Algorithm', 404
Expand Down

0 comments on commit cdc6954

Please sign in to comment.