From 2da14fc554ba9cdd7e82bb6076d7671a56e6b9e1 Mon Sep 17 00:00:00 2001 From: Gert Wohlgemuth Date: Sat, 19 May 2018 15:59:36 -0700 Subject: [PATCH] wokring on persistence scan api --- freqtrade/aws/service/Persistence.py | 26 ++++++++++++++++++++++++++ freqtrade/aws/strategy.py | 20 ++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/freqtrade/aws/service/Persistence.py b/freqtrade/aws/service/Persistence.py index d19ae7005..3587657f1 100644 --- a/freqtrade/aws/service/Persistence.py +++ b/freqtrade/aws/service/Persistence.py @@ -1,5 +1,15 @@ import boto3 import simplejson as json +import decimal + +class DecimalEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, decimal.Decimal): + if o % 1 > 0: + return float(o) + else: + return int(o) + return super(DecimalEncoder, self).default(o) class Persistence: @@ -16,6 +26,22 @@ class Persistence: self.table = table self.db = boto3.resource('dynamodb') + def list(self): + table = self.db.Table(self.table) + + response = table.scan() + result = [] + + while 'LastEvaluatedKey' in response: + response = table.scan( + ExclusiveStartKey=response['LastEvaluatedKey'] + ) + + for i in response['Items']: + result.append(i) + + return result + def load(self, sample): """ loads a given object from the database storage diff --git a/freqtrade/aws/strategy.py b/freqtrade/aws/strategy.py index 4260b3a2f..f242db977 100644 --- a/freqtrade/aws/strategy.py +++ b/freqtrade/aws/strategy.py @@ -1,5 +1,5 @@ from freqtrade.strategy.resolver import StrategyResolver - +import boto3 import os import simplejson as json import uuid @@ -17,8 +17,12 @@ def names(event, context): :param context: :return: """ - pass + table = Persistence(os.environ['strategyTable']) + return { + "statusCode": 200, + "body": json.dumps(table.list()) + } def performance(event, context): """ @@ -51,19 +55,19 @@ def submit(event, context): # get data data = json.loads(event['body']) - print("received data") - print(data) + # print("received data") + # print(data) # validate against schema result = validate(data, __SUBMIT_STRATEGY_SCHEMA__) - print("data are validated"); - print(result) + # print("data are validated"); + # print(result) strategy = urlsafe_b64decode(data['content']).decode('utf-8') - print("loaded strategy") - print(strategy) + # print("loaded strategy") + # print(strategy) # try to load the strategy StrategyResolver().compile(data['name'], strategy)