Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def onOrderUpdated(self, broker_, order):
if self.__plotBuySell and order.isFilled() and order.getInstrument() == self.__instrument:
action = order.getAction()
execInfo = order.getExecutionInfo()
if action in [broker.Order.Action.BUY, broker.Order.Action.BUY_TO_COVER]:
self.getSeries("Buy", BuyMarker).addValue(execInfo.getDateTime(), execInfo.getPrice())
elif action in [broker.Order.Action.SELL, broker.Order.Action.SELL_SHORT]:
self.getSeries("Sell", SellMarker).addValue(execInfo.getDateTime(), execInfo.getPrice())
def __init__(self, strategy, instrument, limitPrice, stopPrice, quantity, goodTillCanceled):
if limitPrice == None and stopPrice == None:
entryOrder = strategy.getBroker().createMarketOrder(broker.Order.Action.SELL_SHORT, instrument, quantity, False)
elif limitPrice != None and stopPrice == None:
entryOrder = strategy.getBroker().createLimitOrder(broker.Order.Action.SELL_SHORT, instrument, limitPrice, quantity)
elif limitPrice == None and stopPrice != None:
entryOrder = strategy.getBroker().createStopOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, quantity)
elif limitPrice != None and stopPrice != None:
entryOrder = strategy.getBroker().createStopLimitOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, limitPrice, quantity)
else:
assert(False)
Position.__init__(self, strategy, entryOrder, goodTillCanceled)
strategy.getBroker().placeOrder(entryOrder)
def onOrderEvent(self, broker_, orderEvent):
order = orderEvent.getOrder()
if self.__plotBuySell and orderEvent.getEventType() in (broker.OrderEvent.Type.PARTIALLY_FILLED, broker.OrderEvent.Type.FILLED) and order.getInstrument() == self.__instrument:
action = order.getAction()
execInfo = orderEvent.getEventInfo()
if action in [broker.Order.Action.BUY, broker.Order.Action.BUY_TO_COVER]:
self.getSeries("Buy", BuyMarker).addValue(execInfo.getDateTime(), execInfo.getPrice())
elif action in [broker.Order.Action.SELL, broker.Order.Action.SELL_SHORT]:
self.getSeries("Sell", SellMarker).addValue(execInfo.getDateTime(), execInfo.getPrice())
def __init__(self, strategy, instrument, limitPrice, stopPrice, quantity, goodTillCanceled):
if limitPrice == None and stopPrice == None:
entryOrder = strategy.getBroker().createMarketOrder(broker.Order.Action.SELL_SHORT, instrument, quantity, False)
elif limitPrice != None and stopPrice == None:
entryOrder = strategy.getBroker().createLimitOrder(broker.Order.Action.SELL_SHORT, instrument, limitPrice, quantity)
elif limitPrice == None and stopPrice != None:
entryOrder = strategy.getBroker().createStopOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, quantity)
elif limitPrice != None and stopPrice != None:
entryOrder = strategy.getBroker().createStopLimitOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, limitPrice, quantity)
else:
assert(False)
Position.__init__(self, strategy, entryOrder, goodTillCanceled)
strategy.getBroker().placeOrder(entryOrder)
def __init__(self, strategy, instrument, limitPrice, stopPrice, quantity, goodTillCanceled):
if limitPrice == None and stopPrice == None:
entryOrder = strategy.getBroker().createMarketOrder(broker.Order.Action.SELL_SHORT, instrument, quantity, False)
elif limitPrice != None and stopPrice == None:
entryOrder = strategy.getBroker().createLimitOrder(broker.Order.Action.SELL_SHORT, instrument, limitPrice, quantity)
elif limitPrice == None and stopPrice != None:
entryOrder = strategy.getBroker().createStopOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, quantity)
elif limitPrice != None and stopPrice != None:
entryOrder = strategy.getBroker().createStopLimitOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, limitPrice, quantity)
else:
assert(False)
Position.__init__(self, strategy, entryOrder, goodTillCanceled)
strategy.getBroker().placeOrder(entryOrder)
def __init__(self, strategy, instrument, limitPrice, stopPrice, quantity, goodTillCanceled):
if limitPrice == None and stopPrice == None:
entryOrder = strategy.getBroker().createMarketOrder(broker.Order.Action.SELL_SHORT, instrument, quantity, False)
elif limitPrice != None and stopPrice == None:
entryOrder = strategy.getBroker().createLimitOrder(broker.Order.Action.SELL_SHORT, instrument, limitPrice, quantity)
elif limitPrice == None and stopPrice != None:
entryOrder = strategy.getBroker().createStopOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, quantity)
elif limitPrice != None and stopPrice != None:
entryOrder = strategy.getBroker().createStopLimitOrder(broker.Order.Action.SELL_SHORT, instrument, stopPrice, limitPrice, quantity)
else:
assert(False)
Position.__init__(self, strategy, entryOrder, goodTillCanceled)
strategy.getBroker().placeOrder(entryOrder)