For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Issue with positions when live trading



  • I use custom broker for bitfinex.
    I have an update positions function.
    It creates positions on start if there any.
    Or it fixes positions if position is wrong for some reason.

    I have a problem during live trading.
    If position is already open, and I start live trading.
    When strategy closes position.
    I get notify_trade that trade.justopened instead of trade.isclosed.

    Please tell me what I'm doing wrong here?

        def positions_update(self):
            positions = self.store.get_positions()
    
            for position in positions:
                symbol = position['symbol']
                amount = position['amount']
                base = position['base']
    
                if symbol in self.positions:
                    self.positions[symbol].fix(amount, base)
                else:
                    self.positions[symbol] = Position(amount, base)
    


  • But when strategy has no open positions on start.
    And It opens and closes position, without restarts.
    Everything works as expected.


  • administrators

    Your custom broker should retrieve any open position and notify that (like if the position had been just opened) to let the trade accounting know when a position is actually being opened.

    Simple logic. That mechanism will also include any position which you may have chosen to manually open, so take it into account.



  • It should simulate trades?
    I saw simulated orders code in oanda broker.
    But I don't get how to access data from broker to create simulated orders.
    Is it possible to assign order time to be executed in the past, when position was opened?



  • Up. Still need help.


  • administrators

    Sorry, I don't know how I can help. Let me quote from above

    @CooleRnax said in Issue with positions when live trading:

    I use custom broker for bitfinex

    That's the key. Your custom broker has to let the engine know there are open trades. Because trades start with an opening order, you need to create fake orders that will trigger the start of a trade if you want to restart with an open position.



  • @backtrader my main problem is that i don't get how to access data inside broker to create fake orders.



  • @backtrader I know dataname of the data that should be linked position.



  • Solved. It actually was not that hard.


Log in to reply
 

});