예제 #1
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')
예제 #2
0
파일: placeorder.py 프로젝트: 3kwa/swigibpy
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, orderId))

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

print("\n=====================================================================")
print(" Order placed, waiting for TWS responses")
예제 #3
0
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, orderId))

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

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