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

How to pair trade in python using IBpy with forex like "USD/JPY"?



  • In TWS only USD/JPY not paired with EUR/JPY. Output error: Error: 56 320 Error reading request:Message id 56. Missing parent order: server: 0 order: 0 parent: 55 hedge:[P]

    def start(self):
    	dpzStock = USStock("USD")
    	dpzOrder = LimitOrder("BUY", 1, 110)
    	dpzOrder.transmit = False
    	dpzOrderId = self.nextOrderId()
    	self.placeOrder(dpzOrderId, dpzStock, dpzOrder)
    	time.sleep(0.2)
    
    	pzzaStock = USStock("GBP")
    	pzzaOrder = LimitOrder("SELL", 1, 100)
    	pzzaOrder.parentId = dpzOrderId
    	pzzaOrder.hedgeType = "P"
    	pzzaOrder.hedgeParam = "5"
    
    	self.placeOrder(self.nextOrderId(), pzzaStock, pzzaOrder)
    
       def LimitOrder(action: str, quantity: float, limitPrice: float):
        
        	# ! [limitorder]
        
        	order = Order()
        
        	order.action = action
        
        	order.orderType = "LMT"
        
        	order.totalQuantity = quantity
        
        	order.lmtPrice = limitPrice
        
        	# ! [limitorder]
        
        	return order 
        
        
        def USStock(ticker: str):
        
        	contract = Contract()
        
        	contract.symbol = ticker
        
        	contract.secType = "CASH"
        
        	contract.exchange = "IDEALPRO"
        
        	contract.currency = "JPY"
        
        	# contract.primaryExchange = "NYSE"
        
        	return contract

Log in to reply
 

});