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

Commit

Permalink
internal checker intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
fou3fou3 committed Dec 29, 2023
1 parent 3377ff9 commit b1b0d86
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def authorize_server(encoded):

return decoded

def algorithm_output(algorithm, prices, backtest=False):
module = import_module(f'algorithms.{algorithm}').Algorithm()
def algorithm_output(algorithm_name, prices, backtest=False):
module = import_module(f'algorithms.{algorithm_name}').Algorithm()
signal, strength = module.signal(prices, module.algorithm(prices))
if backtest:
return signal, strength

return algorithm, (signal, strength)
return algorithm_name, (signal, strength)

def svg_plot():
svg_buffer = io.StringIO()
Expand Down
3 changes: 1 addition & 2 deletions views/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
mpl.use('Agg')

def backtest_view(algorithm_name):
default_interval = get_default_interval()
interval = int(request.args.get('interval') or default_interval)
interval = int(request.args.get('interval') or get_default_interval())
plot_bool = bool(request.args.get('plot') or False)

if algorithm_name not in [*get_algorithms()]:
Expand Down
14 changes: 12 additions & 2 deletions views/internal_checker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from flask import request
from redis import from_url
from price import get_prices
from price import get_prices, get_default_interval, is_supported_interval, get_cached_prices, is_supported_interval, is_cached_interval
from ipaddress import ip_address
from utils import authorize_server, get_algorithms, algorithm_output

Expand All @@ -18,7 +18,17 @@ def internal_checker():
except Exception:
return 'Unauthorized', 401

prices, _, last_complete_point = get_prices()
interval = int(request.args.get('interval') or get_default_interval())

if interval and is_cached_interval(interval):
prices, _, last_complete_point = get_cached_prices(interval=interval)
elif interval and is_supported_interval(interval):
prices, _, last_complete_point = get_prices(interval=interval)
elif not interval:
prices, _, last_complete_point = get_cached_prices()
else:
return 'Unsupported Interval', 400

new_datapoint = last_complete_point > last_checked_point
if new_datapoint:
last_checked_point = last_complete_point
Expand Down
5 changes: 2 additions & 3 deletions views/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
figure_size[0] = figure_size[0] * 1.5

def plot(algorithm_name):
default_interval = get_default_interval()
interval = int(request.args.get('interval') or default_interval)
interval = int(request.args.get('interval') or get_default_interval())
interactive = bool(request.args.get('interactive') or False)

if algorithm_name not in ['price', *get_algorithms()]:
Expand All @@ -32,7 +31,7 @@ def plot(algorithm_name):

# Even out timestamps so plotting algos works
timestamps = timestamps.astype('datetime64[s]')
interval_timedelta = np.timedelta64(default_interval, 'm')
interval_timedelta = np.timedelta64(interval, 'm')
timestamps = np.arange(timestamps[-1] - interval_timedelta * timestamps.shape[0], timestamps[-1], interval_timedelta)

figure = plt.figure()
Expand Down

0 comments on commit b1b0d86

Please sign in to comment.