Closed monsterlady closed 1 year ago
I don't know what the output of the webhook is, but here is a simple logic as an example.
import ejtraderCT
from flask import Flask, request
import logging
import time
from ejtraderCT import Ctrader
logging.getLogger().setLevel(logging.INFO)
SERVER = "IP" # Host name
BROKER = "demo.icmarkets"
LOGIN = "11111"
PASSWORD = "1111"
CURRENCY = "EUR"
volume = 10 # position size
api = Ctrader(server=SERVER, broker=BROKER, login=LOGIN, password=PASSWORD, currency=CURRENCY)
app = Flask(__name__)
@app.route('/alert', methods=['POST'])
def handle_alert():
data = request.get_json()
# faça algo com os dados do alerta recebido
return 'alert received!'
def handle_alert():
data = request.get_json()
symbol = data["SYMBOL"]
type = data['TYPE']
if type == 'buy':
api.buy(symbol=symbol, volume= volume, stoploss=None, takeprofit=None)
elif data['type'] == 'sell':
api.sell(symbol=symbol, volume= volume, stoploss=None, takeprofit=None)
return 'Action Done!'
Remember that this is just a simple example and in practice, you will likely want to add more trading logic and risk management to your code. Additionally, you will need to ensure that your broker credentials are properly configured and that your trading strategy is tested on a demo account before running it on a real trading account.
ejtraderCT is really easy to use, is there any possibility to use it in REST API? For instance, TradingView's alert triggers the webhook, and we have a Python Flask application(RESTFUL API) to receive this call, and then use ejtraderCT to open/close the position.
RestAPI add check the examples folder
ejtraderCT is really easy to use, is there any possibility to use it in REST API? For instance, TradingView's alert triggers the webhook, and we have a Python Flask application(RESTFUL API) to receive this call, and then use ejtraderCT to open/close the position.