Open JDJoe opened 4 years ago
in actions.py, you change the order line to:
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']), { 'leverage': data["leverage"] })
This is how I used it in "Tradingview alert message:
{"type": "stop-loss", "side": "sell", "amount": "100", "symbol": "BCH/EUR", "price": "321", "leverage": "2", "key": "yourkeyhere"}
Interesting. BTW, I can barely read code (I am not a programmer) but do I understand it correctly, you have moved the stop loss calculation to the bot side?
Not sure, if this is a good idea because this information should come from the strategy running on TradingView and it can be different for trading pairs. For example, I use volatility to calculate the possible SL and it's not a % percentage from last price.
I personally hope this bot remains as dumb as possible - only facilitate outside commands.
Maybe, in the future, it should be able to check did your limit order get filled and if not, do something about it.
@JDJoe At the time I wrote it PineScript was still very limited in what info it can pass on (variables). If you look closely you'll see a file called talib.py which I never got around to. Had some personal issues to deal with the past 3 months. Ideally you'd want to calculate stop losses server-side, as even a few seconds can make a huge difference. The hard part is getting a constant stream of reliable data without any downtime, which TV is particularly good at. There's many ways to approach this I guess
Most of the requests here can be done within the bot's "send order" action (as it was intended) BUT I am working on a branch that will allow for "blueprints" of sorts. It's been awhile since I worked with this bot, so I might get it wrong but for the following:
Stop Loss & Take Profit:
Should be possible by setting it to "StopLimit" or "StopMarket". Take profit can be done with a limit order, set to POST only, or "ParticipateDoNotInitiate" in the custom parameters. It should be possible, something like this:
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']), params={'execInst': 'ParticipateDoNotInitiate'})
The bot is basically a ccxt trigger that runs when it gets a TV alert.
I could add the ability to cancel orders made by the bot, I would say this might not be totally efficient though, as it would have to grab the order ID from the exchange, then there would also have to be a way for the alert to know which order you're trying to cancel. It could be "last order" or "3rd from last" etc. Beyond that though would be a bit difficult.
You could do multiple orders even, if you want. Getting price:
exchange.fetch_ticker('XBTUSD')) for example. Then just run your stop/profit formula, and copy the "order = exchange..." to create 3 orders, essentially a bracket order.
Let me know how it works out!
You can do this right now if you use limit order. This will give you a little kickback on fees too. So, When going short, place limit buy order at what ever level below the current market and opposite for the long position - limit sell at something above the market.
To keep it simple: When entering a new order:
What is really important is to execute all this in one single TradingView message so it can be processed in correct order. Because the "key" is really long, TV wont be able to handle 3 x key + orders in one message.
Ah, I see. I'm currently working on a new version that allows for placing a take profit and stop with one alert, it might only work with market orders to start though.
In the mean time, try seeing if this works:
order1 = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
order2 = exchange.create_order(data['symbol'], 'stopLoss', ('sell' if data['side'] == 'buy' else 'buy'), data['amount'], data['takeProfitPrice']))
order3 = exchange.create_order(data['symbol'], 'takeProfit', ('sell' if data['side'] == 'buy' else 'buy'), data['amount'], data['stopLossPrice']))
Off the top of my head, so it might not work.
Just add the "takeProfitPrice": "{{something}}"
In the tradingview alert to get that data to the bot.
I'm currently working on a new version that allows for placing a take profit and stop with one alert
Sounds good. I'll be waiting. I'll be more than happy to help you test it. Stop and take profit already works but there is no way to submit multiple orders at once.
How's the new version looking? :)
Any news about the new version?