hoffe bin hier richtig

Folgende Situation - an sich bin ich eher Trader als Entwickler. Mit einfachen Aufgaben komme ich jedoch ganz gut klar (z.B. C# API Integration zu Binance). Nun wollte ich mich an das Thema serverless application rantasten und merke nun, dass mein Basiswissen nicht mehr ausreicht...
Folgende Aufgabe möchte ich umsetzen:
- Alerts/Webhooks via Tradingview --> Check
- Einrichtung einer AWS REST API (Python) mit POST/GET Funktion via Lambda --> Check
- Empfangen der Webhooks von Tradingview und auswerten des übermittelten Jsons --> Check
- Broker gefunden, der an Tradingview angebunden ist und eine API bereitstellt (FXOpen) --> Check
Nun die stelle wo ich nicht weiter komme.
Theoretisch konnte ich einen HTTP Post zum Broker absetzen - dank Google und ChatGPT. Bekomme aber die Fehlermeldung "Invalid signature!" zurück. Ich gehe stark davon aus, dass es an der HMAC Verschlüsselung liegt. Leider ist auf der Doku Seite des Broker nichts Nützlichen (für mich) zu finden (https://demo.forex.game/webapi).
Folgende Lambda bringt mir diese Meldung wenn ich über Postman den POST auf AWS absetze:
Code: Alles auswählen
import requests, json
import hmac
import hashlib
import time
from chalice import Chalice
app = Chalice(app_name='tradingview-webhook-alerts')
@app.route('/')
def index():
return {'hello': 'world'}
@app.route('/', methods=['POST'])
def buy_sell():
buy_webhook = app.current_request.json_body
side = buy_webhook['Side']
type = buy_webhook['Type']
symbol = buy_webhook['Symbol']
amount = 10000
api_id = "xxxx";
api_key = "xxxx"
api_secret = "xxxx"
timestamp = int(time.time()) # replace with the current timestamp in seconds
message = f"{api_key}:{timestamp}"
signature = hmac.new(api_secret.encode(), message.encode(), hashlib.sha256).hexdigest()
url = 'https://marginalttdemowebapi.fxopen.net:8443/api/v2/trade'
payload = {
'Type': 'Market',
'Side': 'Buy',
'Symbol': 'EURUSD',
'Amount': 10000
}
auth = 'HMAC ' + api_id + ':' + api_key + ':' + str(timestamp) + ':' + signature
headers = {
'Content-Type': 'application/json',
'Accept': 'text/plain',
'Authorization': auth
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
return {
'message': response.text
}
Die .py für TTWebClient eingebunden und wie auf der Startseite dieses Examples die Haupt .py wie folgt bescrhreiben:
Code: Alles auswählen
@app.route('/', methods=['POST'])
def buy_sell():
buy_webhook = app.current_request.json_body
side = buy_webhook['Side']
type = buy_webhook['Type']
symbol = buy_webhook['Symbol']
amount = 10000
web_api_address = "https://marginalttdemowebapi.fxopen.net:8443";
web_api_id = "xxx";
web_api_key = "xxx";
web_api_secret = "xxx";
# Create instance of the TickTrader Web API client
client = TickTraderWebClient(web_api_address, web_api_id, web_api_key, web_api_secret)
account = client.get_account()
if (account['AccountingType'] == 'Gross') or (account['AccountingType'] == 'Net'):
# Create limit order
limit = client.create_trade(
{
'Type': 'Limit',
'Side': 'Buy',
'Symbol': 'EURUSD' if (account['AccountingType'] == 'Gross') else 'EUR/USD',
'Amount': 10000,
'Price': 1.0,
'Comment': 'Buy limit from Web API sample'
})
{
"Code": "InternalServerError",
"Message": "An internal server error occurred."
}
Zusätzlich gibt massiv Einträge in CloudWatch.
Nun die Frage - hat jemand eine Idee wo ich gute Tutorials finde oder besser noch, kann jemand direkt dem Noob helfen?
Vielen Dank und noch einen schönen Abend!
Marcus