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

Commit

Permalink
Revert "utils logging"
Browse files Browse the repository at this point in the history
This reverts commit e532164.
  • Loading branch information
CelestialCrafter committed Feb 9, 2024
1 parent b41d3bb commit 00340a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
18 changes: 2 additions & 16 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
load_dotenv()

client = MongoClient(os.environ['DB_URI'], server_api=ServerApi('1'))
algorithms_collection = client['database']['algorithms']
algorithms = client['database']['algorithms']

def get_algorithms() -> list[str]:
logger = setup_logger()
algorithms = [algorithm['name'] for algorithm in algorithms_collection.find({'owner': {'$not': {'$type': 'object'}}})]
logger.info(f'Fetching algorithms', extra={'number_of_algorithms': len(algorithms)})

return algorithms
return [algorithm['name'] for algorithm in algorithms.find({'owner': {'$not': {'$type': 'object'}}})]

def authorize(encoded: str) -> str:
if encoded.startswith('Bearer'):
Expand All @@ -24,29 +20,19 @@ def authorize(encoded: str) -> str:
return jwt.decode(encoded, os.environ['JWT_SECRET'], algorithms=['HS256'])

def algorithm_output(algorithm_name: str, prices: list[float], backtest=False) -> tuple[str, tuple[str, float]]:
logger = setup_logger()
module = import_module(f'algorithms.{algorithm_name}').Algorithm()
signal, strength = module.signal(prices, module.algorithm(prices))
if backtest:
return signal, strength

logger.info('Algorithm Output',
extra={
'algorithm': algorithm_name,
'backtest': backtest,
'signal': signal,
'strength': strength
})
return algorithm_name, (signal, strength)

def svg_plot() -> str:
logger = setup_logger()
svg_buffer = io.StringIO()
plt.savefig(svg_buffer, format='svg', transparent=True)
plot_data = svg_buffer.getvalue()
plt.close()
svg_buffer.close()
logger.info('SVG plot')

return plot_data

Expand Down
6 changes: 3 additions & 3 deletions src/views/signals.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, default_interval, default_coin
from price import get_prices
from ipaddress import ip_address
from utils import get_algorithms, algorithm_output

Expand All @@ -14,8 +14,8 @@ def signals():
return 'Forbidden', 403

# require explicit interval and coin instead of using get_using_x()
interval = int(request.args.get('interval', type=int) or default_interval)
coin = str(request.args.get('coin', type=str) or default_coin)
interval = request.args.get('interval', type=int)
coin = request.args.get('coin', type=str)

try:
prices, _ = get_prices(interval=interval, pair=coin)
Expand Down

0 comments on commit 00340a1

Please sign in to comment.