def on_order_status_changed(self, t: Target, data): complete_trade = False if t.is_completed(): if t.is_entry_target(): # validate balance and activate trade only if there are trading targets if self.strategy_exit: AccountBalances().update_balances( self.fx.get_all_balances_dict()) self.trade.cap = self.get_balance_for_side().avail self.trade.set_active() self.trigger_target_updated() else: complete_trade = True elif t.is_exit_target(): if self.trade.exit and self.trade.exit.is_completed(): # if all targets are completed, set trade as completed complete_trade = True elif t.is_stoploss_target(): complete_trade = True if complete_trade: self.set_trade_completed() [s.on_order_status_changed(t, data) for s in self.all_strategies()]
def on_order_status_changed(self, t: Target, data): if not t.is_stoploss_target(): return if t.is_completed(): self.set_trade_completed() else: self.logInfo('Order status updated: {}'.format(t.status))
def on_order_status_changed(self, t: Target, data): if not t.is_exit_target(): return if t.is_completed(): self.logInfo('Target {} completed'.format(t)) else: self.logInfo('Order status updated: {}'.format(t.status))
def _update_trade_target_status_change(self, t: Target, status: str) -> bool: if status == FXConnector.ORDER_STATUS_FILLED: t.set_completed() return True if status in [ FXConnector.ORDER_STATUS_CANCELED, FXConnector.ORDER_STATUS_REJECTED, FXConnector.ORDER_STATUS_EXPIRED ]: t.set_canceled() return True return False
def generate_targets(start_price, iter=4, increment=4, smart=True, sl_interval=3): targets = [] prices = [] for i in range(0, iter): prices.append(start_price) vol = round(100 / (iter - i), 2) target = Target(price=start_price, vol='{}%'.format(vol), smart=smart) if sl_interval != 0 and len(prices) >= sl_interval: target.sl = prices[-sl_interval] targets.append(target) start_price = round(start_price * (1 + increment / 100), 8) print(ConfigLoader.get_json_str(targets))