minor adjustements

This commit is contained in:
Gert Wohlgemuth 2018-06-04 13:40:06 -07:00
parent 41d5a566a2
commit 7b101f17b6
3 changed files with 34 additions and 26 deletions

View File

@ -1,7 +1,7 @@
FROM python:3.6.5-slim-stretch FROM python:3.6.5-slim-stretch
# Install TA-lib # Install TA-lib
RUN apt-get update && apt-get -y install curl build-essential && apt-get clean RUN apt-get update && apt-get -y install curl build-essential git && apt-get clean
RUN curl -L http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz | \ RUN curl -L http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz | \
tar xzvf - && \ tar xzvf - && \
cd ta-lib && \ cd ta-lib && \

View File

@ -2,6 +2,7 @@ import datetime
import logging import logging
import os import os
import tempfile import tempfile
from base64 import urlsafe_b64encode
import boto3 import boto3
import simplejson as json import simplejson as json
@ -68,30 +69,18 @@ def backtest(event, context):
try: try:
if "Items" in response and len(response['Items']) > 0: if "Items" in response and len(response['Items']) > 0:
print("backtesting from {} till {} for {} with {} vs {}".format(fromDate, till, name, print("schedule backtesting from {} till {} for {} with {} vs {}".format(fromDate, till, name,
event['body'][ event['body'][
'stake_currency'], 'stake_currency'],
event['body']['assets'])) event['body'][
'assets']))
configuration = _generate_configuration(event, fromDate, name, response, till) configuration = _generate_configuration(event, fromDate, name, response, till)
backtesting = Backtesting(configuration) print("configuration: \n{}\n".format(
result = backtesting.start() urlsafe_b64encode(json.dumps(configuration).encode('utf-8')).decode('utf-8')))
for index, row in result.iterrows():
data = {
"id": "{}.{}:{}:test".format(user, name, row['currency'].upper()),
"trade": "{} to {}".format(row['entry'].strftime('%Y-%m-%d %H:%M:%S'),
row['exit'].strftime('%Y-%m-%d %H:%M:%S')),
"pair": row['currency'],
"duration": row['duration'],
"profit_percent": row['profit_percent'],
"profit_stake": row['profit_BTC'],
"entry_date": row['entry'].strftime('%Y-%m-%d %H:%M:%S'),
"exit_date": row['exit'].strftime('%Y-%m-%d %H:%M:%S')
}
_submit_result_to_backend(data) # fire AWS fargate instance now
run_backtest(configuration, name, user)
# fire request message to aggregate this strategy now
return { return {
"statusCode": 200 "statusCode": 200
@ -113,6 +102,25 @@ def backtest(event, context):
raise Exception("not a valid event: {}".format(event)) raise Exception("not a valid event: {}".format(event))
def run_backtest(configuration, name, user):
backtesting = Backtesting(configuration)
result = backtesting.start()
for index, row in result.iterrows():
data = {
"id": "{}.{}:{}:test".format(user, name, row['currency'].upper()),
"trade": "{} to {}".format(row['entry'].strftime('%Y-%m-%d %H:%M:%S'),
row['exit'].strftime('%Y-%m-%d %H:%M:%S')),
"pair": row['currency'],
"duration": row['duration'],
"profit_percent": row['profit_percent'],
"profit_stake": row['profit_BTC'],
"entry_date": row['entry'].strftime('%Y-%m-%d %H:%M:%S'),
"exit_date": row['exit'].strftime('%Y-%m-%d %H:%M:%S')
}
_submit_result_to_backend(data)
def _submit_result_to_backend(data): def _submit_result_to_backend(data):
""" """
submits the given result to the backend system for further processing and analysis submits the given result to the backend system for further processing and analysis
@ -163,7 +171,7 @@ def _generate_configuration(event, fromDate, name, response, till):
"chat_id": "0" "chat_id": "0"
}, },
"initial_state": "running", "initial_state": "running",
"datadir": tempfile.gettempdir(), "datadir": os.environ("FREQ_DATA_DIR", tempfile.gettempdir()),
"experimental": { "experimental": {
"use_sell_signal": response['Items'][0]['use_sell'], "use_sell_signal": response['Items'][0]['use_sell'],
"sell_profit_only": True "sell_profit_only": True
@ -172,7 +180,7 @@ def _generate_configuration(event, fromDate, name, response, till):
"process_throttle_secs": 5 "process_throttle_secs": 5
}, },
'realistic_simulation': True, 'realistic_simulation': True,
"loglevel": logging.DEBUG, "loglevel": logging.INFO,
"strategy": "{}:{}".format(name, content), "strategy": "{}:{}".format(name, content),
"timerange": "{}-{}".format(fromDate.strftime('%Y%m%d'), till.strftime('%Y%m%d')), "timerange": "{}-{}".format(fromDate.strftime('%Y%m%d'), till.strftime('%Y%m%d')),
"refresh_pairs": True "refresh_pairs": True

View File

@ -64,14 +64,14 @@ class TestStrategy(IStrategy):
} }
# db should be empty # db should be empty
assert (len(json.loads(aws.names({}, {})['body'])) == 0) assert (len(json.loads(aws.names({}, {})['body']['result'])) == 0)
# now we add an entry # now we add an entry
aws.submit({ aws.submit({
"body": json.dumps(request) "body": json.dumps(request)
}, {}) }, {})
# now we should have items # now we should have items
assert (len(json.loads(aws.names({}, {})['body'])) == 1) assert (len(json.loads(aws.names({}, {})['body']['result'])) == 1)
# able to add a second strategy with the sample name, but different user # able to add a second strategy with the sample name, but different user