Merge branch 'aws' of https://github.com/berlinguyinca/freqtrade into aws
This commit is contained in:
commit
90629e2b49
@ -194,7 +194,7 @@ class Arguments(object):
|
|||||||
Builds and attaches all subcommands
|
Builds and attaches all subcommands
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
from freqtrade.optimize import backtesting, hyperopt
|
from freqtrade.optimize import backtesting
|
||||||
|
|
||||||
subparsers = self.parser.add_subparsers(dest='subparser')
|
subparsers = self.parser.add_subparsers(dest='subparser')
|
||||||
|
|
||||||
@ -205,10 +205,14 @@ class Arguments(object):
|
|||||||
self.backtesting_options(backtesting_cmd)
|
self.backtesting_options(backtesting_cmd)
|
||||||
|
|
||||||
# Add hyperopt subcommand
|
# Add hyperopt subcommand
|
||||||
|
try:
|
||||||
|
from freqtrade.optimize import hyperopt
|
||||||
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
|
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
|
||||||
hyperopt_cmd.set_defaults(func=hyperopt.start)
|
hyperopt_cmd.set_defaults(func=hyperopt.start)
|
||||||
self.optimizer_shared_options(hyperopt_cmd)
|
self.optimizer_shared_options(hyperopt_cmd)
|
||||||
self.hyperopt_options(hyperopt_cmd)
|
self.hyperopt_options(hyperopt_cmd)
|
||||||
|
except ImportError as e:
|
||||||
|
logging.warn("no hyper opt found - skipping support for it")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_timerange(text: str) -> Optional[Tuple[List, int, int]]:
|
def parse_timerange(text: str) -> Optional[Tuple[List, int, int]]:
|
||||||
|
@ -114,6 +114,7 @@ def backtest(event, context):
|
|||||||
print("persist data in dynamo")
|
print("persist data in dynamo")
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
result_data = []
|
||||||
for index, row in result.iterrows():
|
for index, row in result.iterrows():
|
||||||
data = {
|
data = {
|
||||||
"id": "{}.{}:{}".format(user, name, row['currency']),
|
"id": "{}.{}:{}".format(user, name, row['currency']),
|
||||||
@ -129,9 +130,15 @@ def backtest(event, context):
|
|||||||
|
|
||||||
data = json.dumps(data, use_decimal=True)
|
data = json.dumps(data, use_decimal=True)
|
||||||
data = json.loads(data, use_decimal=True)
|
data = json.loads(data, use_decimal=True)
|
||||||
print(data)
|
|
||||||
# persist data
|
# persist data
|
||||||
trade_table.put_item(Item=data)
|
trade_table.put_item(Item=data)
|
||||||
|
result_data.append(data)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"statusCode": 200,
|
||||||
|
"body": json.dumps(result_data)
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"sorry we did not find any matching strategy for user {} and name {}".format(user, name))
|
"sorry we did not find any matching strategy for user {} and name {}".format(user, name))
|
||||||
|
@ -8,7 +8,7 @@ from boto3.dynamodb.conditions import Key, Attr
|
|||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
|
|
||||||
from freqtrade.aws.schemas import __SUBMIT_STRATEGY_SCHEMA__
|
from freqtrade.aws.schemas import __SUBMIT_STRATEGY_SCHEMA__
|
||||||
from freqtrade.aws.tables import get_strategy_table
|
from freqtrade.aws.tables import get_strategy_table, get_trade_table
|
||||||
from freqtrade.strategy.resolver import StrategyResolver
|
from freqtrade.strategy.resolver import StrategyResolver
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ def submit(event, context):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print(event)
|
# print(event)
|
||||||
# get data
|
# get data
|
||||||
data = json.loads(event['body'])
|
data = json.loads(event['body'])
|
||||||
|
|
||||||
@ -253,3 +253,44 @@ def submit_github(event, context):
|
|||||||
print("imported/updated: {} strategies".format(strategies))
|
print("imported/updated: {} strategies".format(strategies))
|
||||||
else:
|
else:
|
||||||
print("invalid response received \n{}\n".format(result))
|
print("invalid response received \n{}\n".format(result))
|
||||||
|
|
||||||
|
|
||||||
|
def get_trades(event, context):
|
||||||
|
"""
|
||||||
|
this function retuns all the knowns trades for a user, strategy and pair
|
||||||
|
:param event:
|
||||||
|
:param context:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert 'pathParameters' in event
|
||||||
|
assert 'user' in event['pathParameters']
|
||||||
|
assert 'name' in event['pathParameters']
|
||||||
|
assert 'stake' in event['pathParameters']
|
||||||
|
assert 'asset' in event['pathParameters']
|
||||||
|
|
||||||
|
table = get_trade_table()
|
||||||
|
|
||||||
|
response = table.query(
|
||||||
|
KeyConditionExpression=Key('id').eq(
|
||||||
|
"{}.{}:{}/{}".format(
|
||||||
|
event['pathParameters']['user'],
|
||||||
|
event['pathParameters']['name'],
|
||||||
|
event['pathParameters']['asset'],
|
||||||
|
event['pathParameters']['stake']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if "Items" in response and len(response['Items']) > 0:
|
||||||
|
|
||||||
|
return {
|
||||||
|
"statusCode": response['ResponseMetadata']['HTTPStatusCode'],
|
||||||
|
"body": json.dumps(response['Items'])
|
||||||
|
}
|
||||||
|
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"statusCode": response['ResponseMetadata']['HTTPStatusCode'],
|
||||||
|
"body": json.dumps(response)
|
||||||
|
}
|
||||||
|
@ -5,7 +5,7 @@ import boto3
|
|||||||
import pytest
|
import pytest
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from freqtrade.aws.backtesting_lambda import backtest, cron
|
from freqtrade.aws.backtesting_lambda import backtest, cron
|
||||||
from freqtrade.aws.strategy import submit
|
from freqtrade.aws.strategy import submit, get_trades
|
||||||
|
|
||||||
|
|
||||||
def test_backtest(lambda_context):
|
def test_backtest(lambda_context):
|
||||||
@ -72,7 +72,7 @@ class MyFancyTestStrategy(IStrategy):
|
|||||||
"name": "MyFancyTestStrategy"
|
"name": "MyFancyTestStrategy"
|
||||||
}
|
}
|
||||||
|
|
||||||
backtest({
|
data = json.loads(backtest({
|
||||||
"Records": [
|
"Records": [
|
||||||
{
|
{
|
||||||
"Sns": {
|
"Sns": {
|
||||||
@ -80,7 +80,23 @@ class MyFancyTestStrategy(IStrategy):
|
|||||||
"Message": json.dumps(request)
|
"Message": json.dumps(request)
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}, {})
|
}, {})['body'])
|
||||||
|
|
||||||
|
# evaluate that we now have trades in the database
|
||||||
|
# sadly not always a given at this tage
|
||||||
|
# due to the dynamic nature. Should pick a strategy for testing
|
||||||
|
# which generates a lot of trades
|
||||||
|
if len(data) > 0:
|
||||||
|
data = get_trades({
|
||||||
|
'pathParameters': {
|
||||||
|
'user': "GCU4LW2XXZW3A3FM2XZJTEJHNWHTWDKY2DIJLCZJ5ULVZ4K7LZ7D23TG",
|
||||||
|
"name": "MyFancyTestStrategy",
|
||||||
|
'stake': "USDT",
|
||||||
|
'asset': "{}".format(data[0]['pair'].split("/")[0])
|
||||||
|
}
|
||||||
|
}, {})['body']
|
||||||
|
print(data)
|
||||||
|
assert len(json.loads(data)) > 0
|
||||||
|
|
||||||
|
|
||||||
def test_cron(lambda_context):
|
def test_cron(lambda_context):
|
||||||
@ -146,4 +162,4 @@ class MyFancyTestStrategy(IStrategy):
|
|||||||
|
|
||||||
cron({}, {})
|
cron({}, {})
|
||||||
|
|
||||||
#TODO test receiving of message some how
|
# TODO test receiving of message some how
|
||||||
|
@ -158,6 +158,28 @@ functions:
|
|||||||
environment:
|
environment:
|
||||||
strategyTable: ${self:custom.strategyTable}
|
strategyTable: ${self:custom.strategyTable}
|
||||||
|
|
||||||
|
# loads all trades for a strategy and it's associated pairs
|
||||||
|
trades:
|
||||||
|
memorySize: 128
|
||||||
|
handler: freqtrade/aws/strategy.get_trades
|
||||||
|
events:
|
||||||
|
- http:
|
||||||
|
path: strategies/{user}/{name}/{stake}/{asset}
|
||||||
|
method: get
|
||||||
|
cors: true
|
||||||
|
request:
|
||||||
|
parameter:
|
||||||
|
paths:
|
||||||
|
user: true
|
||||||
|
name: true
|
||||||
|
stake: true
|
||||||
|
asset: true
|
||||||
|
|
||||||
|
environment:
|
||||||
|
strategyTable: ${self:custom.strategyTable}
|
||||||
|
tradeTable: ${self:custom.tradeTable}
|
||||||
|
|
||||||
|
|
||||||
#submits a new strategy to the system
|
#submits a new strategy to the system
|
||||||
submit:
|
submit:
|
||||||
memorySize: 128
|
memorySize: 128
|
||||||
|
Loading…
Reference in New Issue
Block a user