Esempio n. 1
0
contract = Contract()
contract.symbol = "IBM"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"

if orderId is None:
    print('Waiting for valid order id')
    sleep(1)
    while orderId is None:
        print('Still waiting for valid order id...')
        sleep(1)

# Order details
algoParams = TagValueList()
algoParams.append(TagValue("componentSize", "3"))
algoParams.append(TagValue("timeBetweenOrders", "60"))
algoParams.append(TagValue("randomizeTime20", "1"))
algoParams.append(TagValue("randomizeSize55", "1"))
algoParams.append(TagValue("giveUp", "1"))
algoParams.append(TagValue("catchUp", "1"))
algoParams.append(TagValue("waitForFill", "1"))
algoParams.append(TagValue("startTime", "20110302-14:30:00 GMT"))
algoParams.append(TagValue("endTime", "20110302-21:00:00 GMT"))

order = Order()
order.action = 'BUY'
order.lmtPrice = 140
order.orderType = 'LMT'
order.totalQuantity = 10
order.algoStrategy = "AD"
Esempio n. 2
0
contract = Contract()
contract.symbol = "IBM"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"

if orderId is None:
    print('Waiting for valid order id')
    sleep(1)
    while orderId is None:
        print('Still waiting for valid order id...')
        sleep(1)

# Order details
algoParams = TagValueList()
algoParams.append(TagValue("componentSize","3"))
algoParams.append(TagValue("timeBetweenOrders","60"))
algoParams.append(TagValue("randomizeTime20","1"))
algoParams.append(TagValue("randomizeSize55","1"))
algoParams.append(TagValue("giveUp","1"))
algoParams.append(TagValue("catchUp","1"))
algoParams.append(TagValue("waitForFill","1"))
algoParams.append(TagValue("startTime","20110302-14:30:00 GMT"))
algoParams.append(TagValue("endTime","20110302-21:00:00 GMT"))

order = Order()
order.action = 'BUY'
order.lmtPrice = 140
order.orderType = 'LMT'
order.totalQuantity = 10
order.algoStrategy = "AD"
Esempio n. 3
0
    def place_order(self, contract):
        print('Waiting for valid order id')
        order_id = self.order_ids.get(timeout=WAIT_TIME)
        if not order_id:
            raise RuntimeError('Failed to receive order id after %ds' % WAIT_TIME)

        # Order details
        algoParams = TagValueList()
        algoParams.append(TagValue("componentSize", "3"))
        algoParams.append(TagValue("timeBetweenOrders", "60"))
        algoParams.append(TagValue("randomizeTime20", "1"))
        algoParams.append(TagValue("randomizeSize55", "1"))
        algoParams.append(TagValue("giveUp", "1"))
        algoParams.append(TagValue("catchUp", "1"))
        algoParams.append(TagValue("waitForFill", "1"))
        algoParams.append(TagValue("startTime", "20110302-14:30:00 GMT"))
        algoParams.append(TagValue("endTime", "20110302-21:00:00 GMT"))

        order = Order()
        order.action = 'BUY'
        order.lmtPrice = 140
        order.orderType = 'LMT'
        order.totalQuantity = 10
        order.algoStrategy = "AD"
        order.tif = 'DAT'
        order.algoParams = algoParams
        # order.transmit = False


        print("Placing order for %d %s's (id: %d)" % (order.totalQuantity,
                                                      contract.symbol, order_id))

        # Place the order
        self.tws.placeOrder(
            order_id,  # orderId,
            contract,  # contract,
            order  # order
        )

        print("\n====================================================================")
        print(" Order placed, waiting %ds for TWS responses" % WAIT_TIME)
        print("====================================================================\n")

        print("Waiting for order to be filled..")

        try:
            self.order_filled.wait(WAIT_TIME)
        except KeyboardInterrupt:
            pass
        finally:
            if not self.order_filled.is_set():
                print('Failed to fill order')