09-10-2018, 08:43 PM
(09-06-2018, 11:13 PM)mark.sch Wrote:Quote:Could you explain how to use the onTrade handle to be notified of a stoploss sell?
You need only to add a couple of lines into your strategy to get notified when the gekko event system is firing a trade completed event. It is the same way like you add the init or check function to your strategy:
strat.onTrade = function (trade) {
//catch all trades. Whether from manual buy/sell (telegram bot), a stoploss trigger or from a strategy advice
if (trade.action == 'sell') {
// do something here
}
}
From console.log(trade) output you see all properties the trade object is containing:
{ id: 'trade-7',
adviceId: 'advice-4',
action: 'buy',
cost: 1.4524059748649476,
amount: 0.07355882,
price: 13143.47,
portfolio: { asset: 0.07355882, currency: 0 },
balance: 966.8181439053999,
date: moment("2018-01-16T01:45:00.000"),
effectivePrice: 13123.754795,
feePercent: 0.15,
status: 'tradeCompleted',
trigger: { origin: 'trailingStop', trailPercentage: 2 } }
Thanks a lot!