当前位置: 首页>>代码示例>>Python>>正文


Python EPosixClientSocket.reqContractDetails方法代码示例

本文整理汇总了Python中swigibpy.EPosixClientSocket.reqContractDetails方法的典型用法代码示例。如果您正苦于以下问题:Python EPosixClientSocket.reqContractDetails方法的具体用法?Python EPosixClientSocket.reqContractDetails怎么用?Python EPosixClientSocket.reqContractDetails使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swigibpy.EPosixClientSocket的用法示例。


在下文中一共展示了EPosixClientSocket.reqContractDetails方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Contract

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqContractDetails [as 别名]
# Connect to tws running on localhost
tws.eConnect("", 7496, 42)

# Simple contract for GOOG
contract = Contract()
contract.exchange = "SMART"
contract.symbol = "GOOG"
contract.secType = "STK"
contract.currency = "USD"
today = datetime.today()

print("Requesting contract details...")

# Perform the request
tws.reqContractDetails(
        42,                                         # reqId,
        contract,                                   # contract,
    )

print("\n=====================================================================")
print(" Contract details requested, waiting for TWS responses")
print("=====================================================================\n")


print("******************* Press ENTER to quit when done *******************\n")
input()

print("\nDisconnecting...")
tws.eDisconnect()
开发者ID:3kwa,项目名称:swigibpy,代码行数:31,代码来源:contractdetails.py

示例2: SwigIBClientForInstrument

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqContractDetails [as 别名]
class SwigIBClientForInstrument(EWrapper):
    '''Callback object passed to TWS, these functions will be called directly
    by TWS.
    '''

    def __init__(self, port=4001, client_id=12):
        super(SwigIBClientForInstrument, self).__init__()

        self.tws = EPosixClientSocket(self)
        self.port = port
        self.client_id = client_id

        self.got_history = Event()
        self.got_contract = Event()
        self.got_err = Event()
        self.order_filled = Event()
        self.order_ids = Queue()

    def execDetails(self, id, contract, execution):
        pass

    def managedAccounts(self, openOrderEnd):
        pass

    ### Order
    def nextValidId(self, validOrderId):
        '''Capture the next order id'''
        self.order_ids.put(validOrderId)


    def request_contract_details(self, contract):
        today = datetime.today()

        print("Requesting contract details...")

        # Perform the request
        self.tws.reqContractDetails(
            43,  # reqId,
            contract,  # contract,
        )

        print("\n====================================================================")
        print(" Contract details requested, waiting %ds for TWS responses" % WAIT_TIME)
        print("====================================================================\n")

        try:
            self.got_contract.wait(timeout=WAIT_TIME)
        except KeyboardInterrupt:
            pass
        finally:
            if not self.got_contract.is_set():
                print('Failed to get contract within %d seconds' % WAIT_TIME)

    def contractDetails(self, reqId, contractDetails):
        print("Contract details received (request id %i):" % reqId)
        print("callable: %s" % contractDetails.callable)
        print("category: %s" % contractDetails.category)
        print("contractMonth: %s" % contractDetails.contractMonth)
        print("convertible: %s" % contractDetails.convertible)
        print("coupon: %s" % contractDetails.coupon)
        print("industry: %s" % contractDetails.industry)
        print("liquidHours: %s" % contractDetails.liquidHours)
        print("longName: %s" % contractDetails.longName)
        print("marketName: %s" % contractDetails.marketName)
        print("minTick: %s" % contractDetails.minTick)
        print("nextOptionPartial: %s" % contractDetails.nextOptionPartial)
        print("orderTypes: %s" % contractDetails.orderTypes)
        print("priceMagnifier: %s" % contractDetails.priceMagnifier)
        print("putable: %s" % contractDetails.putable)
        if contractDetails.secIdList is not None:
            for secId in contractDetails.secIdList:
                print("secIdList: %s" % secId)
        else:
            print("secIdList: None")

        print("subcategory: %s" % contractDetails.subcategory)
        print("tradingHours: %s" % contractDetails.tradingHours)
        print("timeZoneId: %s" % contractDetails.timeZoneId)
        print("underConId: %s" % contractDetails.underConId)
        print("evRule: %s" % contractDetails.evRule)
        print("evMultiplier: %s" % contractDetails.evMultiplier)

        contract = contractDetails.summary

        print("\nContract Summary:")
        print("exchange: %s" % contract.exchange)
        print("symbol: %s" % contract.symbol)
        print("secType: %s" % contract.secType)
        print("currency: %s" % contract.currency)
        print("tradingClass: %s" % contract.tradingClass)
        if contract.comboLegs is not None:
            for comboLeg in contract.comboLegs:
                print("comboLegs: %s - %s" %
                      (comboLeg.action, comboLeg.exchange))
        else:
            print("comboLegs: None")

        # inst_id = seq_mgr.get_next_sequence("instruments")
        print("\nBond Values:")
        print("bondType: %s" % contractDetails.bondType)
#.........这里部分代码省略.........
开发者ID:alexcwyu,项目名称:python-trading,代码行数:103,代码来源:vix_inst_importer.py

示例3:

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqContractDetails [as 别名]
    # generate clientid based on time of day so that we won't likely get duplicate clientids
    timenow = datetime.utcnow().time()
    clientid = timenow.hour * 60 * 60 + timenow.minute * 60 + timenow.second

    tws.eConnect("", 7496, clientid)

    api_started.wait(10)

    if tws.exited:
        sys.exit(2)

    logging.info("API functional, getting started...")

    logging.info("Requesting contract details...")
    tws.reqContractDetails(0, contract)
    contract_details_received.wait(5)
    if not prev_session_end and not next_session_end:
        logging.info("Failed to retrieve contract details. Aborting...")
        sys.exit(ExitCode.error_can_continue)
    logging.info("Contract details received.")

    # historical data is requested and received in local timezone

    now = datetime.now()
    local_tz = tzlocal.get_localzone()
    now = local_tz.localize(now)

    if args.e == "now":
        if not next_session_start:
            if args.rth:
开发者ID:azyr,项目名称:jtsdownloader,代码行数:32,代码来源:jtsdownloader.py

示例4: EPosixClientSocket

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqContractDetails [as 别名]
# Instantiate a socket object, allowing us to call TWS directly. Pass our
# callback object so TWS can respond.
tws = EPosixClientSocket(callback)

# Connect to tws running on localhost
tws.eConnect("", 7496, 42)

# Simple contract for GOOG
contract = Contract()
contract.exchange = "SMART"
contract.symbol = "GOOG"
contract.secType = "STK"
contract.currency = "USD"
today = datetime.today()

print "Requesting historical data for %s" % contract.symbol

# Perform the request
tws.reqContractDetails(42, contract)  # reqId,  # contract,

print "\n====================================================================="
print " Contract details requested, waiting for TWS responses"
print "=====================================================================\n"


print "******************* Press ENTER to quit when done *******************\n"
raw_input()

print "\nDisconnecting..."
tws.eDisconnect()
开发者ID:olafsep01,项目名称:swigibpy,代码行数:32,代码来源:contractdetails.py

示例5: SwigIBClient

# 需要导入模块: from swigibpy import EPosixClientSocket [as 别名]
# 或者: from swigibpy.EPosixClientSocket import reqContractDetails [as 别名]

#.........这里部分代码省略.........
        self.got_err.set()

    def winError(self, msg, lastError):
        print("TWS reports API error: %s" % msg)
        self.got_err.set()

    def pyError(self, type, val, tb):
        sys.print_exception(type, val, tb)

    ###
    def connect(self):
        if not self.tws.eConnect("", self.port, self.client_id):
            raise RuntimeError('Failed to connect to TWS')

    def disconnect(self):
        print("\nDisconnecting...")
        self.tws.eDisconnect()

    def create_contract(self):
        # Simple contract for GOOG
        contract = Contract()
        contract.exchange = "SMART"
        contract.symbol = "GOOG"
        contract.secType = "STK"
        contract.currency = "USD"
        return contract

    def request_contract_details(self, contract):
        today = datetime.today()

        print("Requesting contract details...")

        # Perform the request
        self.tws.reqContractDetails(
            42,  # reqId,
            contract,  # contract,
        )

        print("\n====================================================================")
        print(" Contract details requested, waiting %ds for TWS responses" % WAIT_TIME)
        print("====================================================================\n")

        try:
            self.got_contract.wait(timeout=WAIT_TIME)
        except KeyboardInterrupt:
            pass
        finally:
            if not self.got_contract.is_set():
                print('Failed to get contract within %d seconds' % WAIT_TIME)

    def request_hist_data(self, contract):
        today = datetime.today()

        print("Requesting historical data for %s" % contract.symbol)

        # Request some historical data.
        self.tws.reqHistoricalData(
            2,  # tickerId,
            contract,  # contract,
            today.strftime("%Y%m%d %H:%M:%S %Z"),  # endDateTime,
            "1 W",  # durationStr,
            "1 day",  # barSizeSetting,
            "TRADES",  # whatToShow,
            0,  # useRTH,
            1  # formatDate
        )
开发者ID:alexcwyu,项目名称:python-trading,代码行数:70,代码来源:ib_demo.py


注:本文中的swigibpy.EPosixClientSocket.reqContractDetails方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。