optimizing trade db handling to lower monthly cost

This commit is contained in:
Gert Wohlgemuth
2018-06-02 14:44:09 -07:00
parent cd462db993
commit 13b533820f
6 changed files with 161 additions and 90 deletions

37
freqtrade/aws/trade.py Normal file
View File

@@ -0,0 +1,37 @@
import boto3
import simplejson as json
import os
from freqtrade.aws.tables import get_trade_table
def store(event, context):
"""
stores the received data in the internal database
:param data:
:return:
"""
if 'Records' in event:
for x in event['Records']:
if 'Sns' in x and 'Message' in x['Sns']:
data = json.loads(x['Sns']['Message'], use_decimal=True)
get_trade_table().put_item(Item=data)
def submit(event, context):
"""
submits a new trade to be registered in the internal queue system
:param event:
:param context:
:return:
"""
data = json.loads(event['body'])
client = boto3.client('sns')
topic_arn = client.create_topic(Name=os.environ['tradeTopic'])['TopicArn']
result = client.publish(
TopicArn=topic_arn,
Message=json.dumps({'default': data}),
Subject="persist data",
MessageStructure='json'
)