This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3125d92
commit 8b811d2
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import jwt, os, utils | ||
from flask import json, request | ||
from bson.objectid import ObjectId | ||
from backtesting import optimize_algorithm | ||
|
||
algorithms = utils.client['database']['algorithms'] | ||
|
||
def optimize(): | ||
jwt_encoded = request.headers.get('Authorization') | ||
if not jwt_encoded: | ||
return 'Bad Request', 400 | ||
|
||
if 'algorithms' not in request.json or type(request.json['algorithms']) is not list: | ||
return 'Bad Request', 400 | ||
|
||
try: | ||
jwt_decoded = jwt.decode(jwt_encoded, os.environ['JWT_SECRET'], algorithms=['HS256']) | ||
except Exception: | ||
return 'Unauthorized', 401 | ||
|
||
return json( | ||
optimize_algorithm({ | ||
algorithm['name']: algorithm['params'] for algorithm in | ||
algorithms.find({'$or': [{ | ||
'owner': ObjectId(jwt_decoded['_id']) | ||
}, { | ||
'owner': { | ||
'$exists': False | ||
} | ||
}]}) | ||
})) |