{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Contract details\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<IB connected to 127.0.0.1:7497 clientId=11>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from ib_insync import *\n",
    "util.startLoop()\n",
    "\n",
    "import logging\n",
    "# util.logToConsole(logging.DEBUG)\n",
    "\n",
    "ib = IB()\n",
    "ib.connect('127.0.0.1', 7497, clientId=11)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Suppose we want to find the contract details for AMD stock.\n",
    "Let's create a stock object and request the details for it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "35"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amd = Stock('AMD')\n",
    "\n",
    "cds = ib.reqContractDetails(amd)\n",
    "\n",
    "len(cds)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We get a long list of contract details. Lets print the first one:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ContractDetails(contract=Contract(secType='STK', conId=4391, symbol='AMD', exchange='SMART', primaryExchange='NASDAQ', currency='USD', localSymbol='AMD', tradingClass='NMS', comboLegs=[]), marketName='NMS', minTick=0.01, orderTypes='ACTIVETIM,ADJUST,ALERT,ALGO,ALLOC,AON,AVGCOST,BASKET,BENCHPX,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,POSTONLY,PREOPGRTH,REL,RPI,RTH,SCALE,SCALEODD,SCALERST,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF', validExchanges='SMART,AMEX,NYSE,CBOE,PHLX,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,EDGX,FOXRIVER,NYSENAT,PSX', priceMagnifier=1, underConId=0, longName='ADVANCED MICRO DEVICES', contractMonth='', industry='Technology', category='Semiconductors', subcategory='Electronic Compo-Semicon', timeZoneId='EST (Eastern Standard Time)', tradingHours='20191231:0400-20191231:2000;20200101:CLOSED;20200102:0400-20200102:2000;20200103:0400-20200103:2000;20200104:CLOSED;20200105:CLOSED;20200106:0400-20200106:2000;20200107:0400-20200107:2000;20200108:0400-20200108:2000;20200109:0400-20200109:2000;20200110:0400-20200110:2000;20200111:CLOSED;20200112:CLOSED;20200113:0400-20200113:2000;20200114:0400-20200114:2000;20200115:0400-20200115:2000;20200116:0400-20200116:2000;20200117:0400-20200117:2000;20200118:CLOSED;20200119:CLOSED;20200120:0400-20200120:2000;20200121:0400-20200121:2000;20200122:0400-20200122:2000;20200123:0400-20200123:2000;20200124:0400-20200124:2000;20200125:CLOSED;20200126:CLOSED;20200127:0400-20200127:2000;20200128:0400-20200128:2000;20200129:0400-20200129:2000;20200130:0400-20200130:2000;20200131:0400-20200131:2000;20200201:CLOSED;20200202:CLOSED;20200203:0400-20200203:2000', liquidHours='20191231:0930-20191231:1600;20200101:CLOSED;20200102:0930-20200102:1600;20200103:0930-20200103:1600;20200104:CLOSED;20200105:CLOSED;20200106:0930-20200106:1600;20200107:0930-20200107:1600;20200108:0930-20200108:1600;20200109:0930-20200109:1600;20200110:0930-20200110:1600;20200111:CLOSED;20200112:CLOSED;20200113:0930-20200113:1600;20200114:0930-20200114:1600;20200115:0930-20200115:1600;20200116:0930-20200116:1600;20200117:0930-20200117:1600;20200118:CLOSED;20200119:CLOSED;20200120:0930-20200120:1600;20200121:0930-20200121:1600;20200122:0930-20200122:1600;20200123:0930-20200123:1600;20200124:0930-20200124:1600;20200125:CLOSED;20200126:CLOSED;20200127:0930-20200127:1600;20200128:0930-20200128:1600;20200129:0930-20200129:1600;20200130:0930-20200130:1600;20200131:0930-20200131:1600;20200201:CLOSED;20200202:CLOSED;20200203:0930-20200203:1600', evRule='', evMultiplier=0, mdSizeMultiplier=100, aggGroup=1, underSymbol='', underSecType='', marketRuleIds='26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26', secIdList=[], realExpirationDate='', lastTradeTime='', stockType='COMMON', cusip='', ratings='', descAppend='', bondType='', couponType='', callable=False, putable=False, coupon=0, convertible=False, maturity='', issueDate='', nextOptionDate='', nextOptionType='', nextOptionPartial=False, notes='')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cds[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The contract itself is in the 'contract' property of the contract details. Lets make a list of contracts and look at the first:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Contract(secType='STK', conId=4391, symbol='AMD', exchange='SMART', primaryExchange='NASDAQ', currency='USD', localSymbol='AMD', tradingClass='NMS', comboLegs=[])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "contracts = [cd.contract for cd in cds]\n",
    "\n",
    "contracts[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To better spot the difference between all the contracts it's handy to convert to a DataFrame. There is a utility function to do that:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>secType</th>\n",
       "      <th>conId</th>\n",
       "      <th>symbol</th>\n",
       "      <th>lastTradeDateOrContractMonth</th>\n",
       "      <th>strike</th>\n",
       "      <th>right</th>\n",
       "      <th>multiplier</th>\n",
       "      <th>exchange</th>\n",
       "      <th>primaryExchange</th>\n",
       "      <th>currency</th>\n",
       "      <th>localSymbol</th>\n",
       "      <th>tradingClass</th>\n",
       "      <th>includeExpired</th>\n",
       "      <th>secIdType</th>\n",
       "      <th>secId</th>\n",
       "      <th>comboLegsDescrip</th>\n",
       "      <th>comboLegs</th>\n",
       "      <th>deltaNeutralContract</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>SMART</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>SMART</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>XETRA</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>STK</td>\n",
       "      <td>172603743</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>SMART</td>\n",
       "      <td>EBS</td>\n",
       "      <td>CHF</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>STK</td>\n",
       "      <td>298633607</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>SMART</td>\n",
       "      <td>ASX</td>\n",
       "      <td>AUD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>AMEX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>NYSE</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>CBOE</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>PHLX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>ISE</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>CHX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>ARCA</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>ISLAND</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>DRCTEDGE</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>BEX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>BATS</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>EDGEA</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>CSFBALGO</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>JEFFALGO</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>BYX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>IEX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>EDGX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>FOXRIVER</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>NYSENAT</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>STK</td>\n",
       "      <td>4391</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>PSX</td>\n",
       "      <td>NASDAQ</td>\n",
       "      <td>USD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>NMS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>FWB</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>USSTARS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>IBIS</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>XETRA</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>BVME</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>VSE</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>SWB</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>XETRA</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>TGATE</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>STK</td>\n",
       "      <td>32596680</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>GETTEX</td>\n",
       "      <td>IBIS</td>\n",
       "      <td>EUR</td>\n",
       "      <td>AMD</td>\n",
       "      <td>USSTARS</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>STK</td>\n",
       "      <td>48818298</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>MEXI</td>\n",
       "      <td>MEXI</td>\n",
       "      <td>MXN</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>STK</td>\n",
       "      <td>172603743</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>EBS</td>\n",
       "      <td>EBS</td>\n",
       "      <td>CHF</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>STK</td>\n",
       "      <td>298633607</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>ASX</td>\n",
       "      <td>ASX</td>\n",
       "      <td>AUD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>STK</td>\n",
       "      <td>298633607</td>\n",
       "      <td>AMD</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>ASXCEN</td>\n",
       "      <td>ASX</td>\n",
       "      <td>AUD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>AMD</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>[]</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   secType      conId symbol lastTradeDateOrContractMonth  strike right  \\\n",
       "0      STK       4391    AMD                                  0.0         \n",
       "1      STK   32596680    AMD                                  0.0         \n",
       "2      STK  172603743    AMD                                  0.0         \n",
       "3      STK  298633607    AMD                                  0.0         \n",
       "4      STK       4391    AMD                                  0.0         \n",
       "5      STK       4391    AMD                                  0.0         \n",
       "6      STK       4391    AMD                                  0.0         \n",
       "7      STK       4391    AMD                                  0.0         \n",
       "8      STK       4391    AMD                                  0.0         \n",
       "9      STK       4391    AMD                                  0.0         \n",
       "10     STK       4391    AMD                                  0.0         \n",
       "11     STK       4391    AMD                                  0.0         \n",
       "12     STK       4391    AMD                                  0.0         \n",
       "13     STK       4391    AMD                                  0.0         \n",
       "14     STK       4391    AMD                                  0.0         \n",
       "15     STK       4391    AMD                                  0.0         \n",
       "16     STK       4391    AMD                                  0.0         \n",
       "17     STK       4391    AMD                                  0.0         \n",
       "18     STK       4391    AMD                                  0.0         \n",
       "19     STK       4391    AMD                                  0.0         \n",
       "20     STK       4391    AMD                                  0.0         \n",
       "21     STK       4391    AMD                                  0.0         \n",
       "22     STK       4391    AMD                                  0.0         \n",
       "23     STK       4391    AMD                                  0.0         \n",
       "24     STK   32596680    AMD                                  0.0         \n",
       "25     STK   32596680    AMD                                  0.0         \n",
       "26     STK   32596680    AMD                                  0.0         \n",
       "27     STK   32596680    AMD                                  0.0         \n",
       "28     STK   32596680    AMD                                  0.0         \n",
       "29     STK   32596680    AMD                                  0.0         \n",
       "30     STK   32596680    AMD                                  0.0         \n",
       "31     STK   48818298    AMD                                  0.0         \n",
       "32     STK  172603743    AMD                                  0.0         \n",
       "33     STK  298633607    AMD                                  0.0         \n",
       "34     STK  298633607    AMD                                  0.0         \n",
       "\n",
       "   multiplier  exchange primaryExchange currency localSymbol tradingClass  \\\n",
       "0                 SMART          NASDAQ      USD         AMD          NMS   \n",
       "1                 SMART            IBIS      EUR         AMD        XETRA   \n",
       "2                 SMART             EBS      CHF         AMD          AMD   \n",
       "3                 SMART             ASX      AUD         AMD          AMD   \n",
       "4                  AMEX          NASDAQ      USD         AMD          NMS   \n",
       "5                  NYSE          NASDAQ      USD         AMD          NMS   \n",
       "6                  CBOE          NASDAQ      USD         AMD          NMS   \n",
       "7                  PHLX          NASDAQ      USD         AMD          NMS   \n",
       "8                   ISE          NASDAQ      USD         AMD          NMS   \n",
       "9                   CHX          NASDAQ      USD         AMD          NMS   \n",
       "10                 ARCA          NASDAQ      USD         AMD          NMS   \n",
       "11               ISLAND          NASDAQ      USD         AMD          NMS   \n",
       "12             DRCTEDGE          NASDAQ      USD         AMD          NMS   \n",
       "13                  BEX          NASDAQ      USD         AMD          NMS   \n",
       "14                 BATS          NASDAQ      USD         AMD          NMS   \n",
       "15                EDGEA          NASDAQ      USD         AMD          NMS   \n",
       "16             CSFBALGO          NASDAQ      USD         AMD          NMS   \n",
       "17             JEFFALGO          NASDAQ      USD         AMD          NMS   \n",
       "18                  BYX          NASDAQ      USD         AMD          NMS   \n",
       "19                  IEX          NASDAQ      USD         AMD          NMS   \n",
       "20                 EDGX          NASDAQ      USD         AMD          NMS   \n",
       "21             FOXRIVER          NASDAQ      USD         AMD          NMS   \n",
       "22              NYSENAT          NASDAQ      USD         AMD          NMS   \n",
       "23                  PSX          NASDAQ      USD         AMD          NMS   \n",
       "24                  FWB            IBIS      EUR         AMD      USSTARS   \n",
       "25                 IBIS            IBIS      EUR         AMD        XETRA   \n",
       "26                 BVME            IBIS      EUR         AMD          AMD   \n",
       "27                  VSE            IBIS      EUR         AMD          AMD   \n",
       "28                  SWB            IBIS      EUR         AMD        XETRA   \n",
       "29                TGATE            IBIS      EUR         AMD          AMD   \n",
       "30               GETTEX            IBIS      EUR         AMD      USSTARS   \n",
       "31                 MEXI            MEXI      MXN         AMD          AMD   \n",
       "32                  EBS             EBS      CHF         AMD          AMD   \n",
       "33                  ASX             ASX      AUD         AMD          AMD   \n",
       "34               ASXCEN             ASX      AUD         AMD          AMD   \n",
       "\n",
       "    includeExpired secIdType secId comboLegsDescrip comboLegs  \\\n",
       "0            False                                         []   \n",
       "1            False                                         []   \n",
       "2            False                                         []   \n",
       "3            False                                         []   \n",
       "4            False                                         []   \n",
       "5            False                                         []   \n",
       "6            False                                         []   \n",
       "7            False                                         []   \n",
       "8            False                                         []   \n",
       "9            False                                         []   \n",
       "10           False                                         []   \n",
       "11           False                                         []   \n",
       "12           False                                         []   \n",
       "13           False                                         []   \n",
       "14           False                                         []   \n",
       "15           False                                         []   \n",
       "16           False                                         []   \n",
       "17           False                                         []   \n",
       "18           False                                         []   \n",
       "19           False                                         []   \n",
       "20           False                                         []   \n",
       "21           False                                         []   \n",
       "22           False                                         []   \n",
       "23           False                                         []   \n",
       "24           False                                         []   \n",
       "25           False                                         []   \n",
       "26           False                                         []   \n",
       "27           False                                         []   \n",
       "28           False                                         []   \n",
       "29           False                                         []   \n",
       "30           False                                         []   \n",
       "31           False                                         []   \n",
       "32           False                                         []   \n",
       "33           False                                         []   \n",
       "34           False                                         []   \n",
       "\n",
       "   deltaNeutralContract  \n",
       "0                  None  \n",
       "1                  None  \n",
       "2                  None  \n",
       "3                  None  \n",
       "4                  None  \n",
       "5                  None  \n",
       "6                  None  \n",
       "7                  None  \n",
       "8                  None  \n",
       "9                  None  \n",
       "10                 None  \n",
       "11                 None  \n",
       "12                 None  \n",
       "13                 None  \n",
       "14                 None  \n",
       "15                 None  \n",
       "16                 None  \n",
       "17                 None  \n",
       "18                 None  \n",
       "19                 None  \n",
       "20                 None  \n",
       "21                 None  \n",
       "22                 None  \n",
       "23                 None  \n",
       "24                 None  \n",
       "25                 None  \n",
       "26                 None  \n",
       "27                 None  \n",
       "28                 None  \n",
       "29                 None  \n",
       "30                 None  \n",
       "31                 None  \n",
       "32                 None  \n",
       "33                 None  \n",
       "34                 None  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "util.df(contracts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see from this that AMD trades in different currencies on different exchanges.\n",
    "Suppose we want the one in USD on the SMART exchange. The AMD contract is adjusted to\n",
    "reflect that and becomes unique:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "amd = Stock('AMD', 'SMART', 'USD')\n",
    "\n",
    "assert len(ib.reqContractDetails(amd)) == 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets try the same for Intel:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "intc = Stock('INTC', 'SMART', 'USD')\n",
    "\n",
    "assert len(ib.reqContractDetails(intc)) == 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try a non-existing contract:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error 200, reqId 6: No security definition has been found for the request, contract: Stock(symbol='XXX', exchange='SMART', currency='USD', comboLegs=[])\n"
     ]
    }
   ],
   "source": [
    "xxx = Stock('XXX', 'SMART', 'USD')\n",
    "\n",
    "assert len(ib.reqContractDetails(xxx)) == 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or a Forex contract"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "eurusd = Forex('EURUSD')\n",
    "\n",
    "assert len(ib.reqContractDetails(eurusd)) == 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the ``qualifyContracts`` method the extra information that is send back\n",
    "from the contract details request is used to fill in the original contracts.\n",
    "\n",
    "Lets do that with ``amd`` and compare before and aftwards:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Stock(symbol='AMD', exchange='SMART', currency='USD', comboLegs=[])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Stock(conId=4391, symbol='AMD', exchange='SMART', primaryExchange='NASDAQ', currency='USD', localSymbol='AMD', tradingClass='NMS', comboLegs=[])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ib.qualifyContracts(amd)\n",
    "amd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TIP:** When printing a contract, the output can be copy-pasted and it will be valid Python code.\n",
    "\n",
    "The ``conId`` that is returned can by itself be used to uniquely specify a contract:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "contract_4391 = Contract(conId=4391)\n",
    "\n",
    "ib.qualifyContracts(contract_4391)\n",
    "\n",
    "assert contract_4391 == amd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A whole bunch of contracts can be qualified at the same time. A list of all the successfull ones is returned:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Error 200, reqId 12: No security definition has been found for the request, contract: Stock(symbol='XXX', exchange='SMART', currency='USD', comboLegs=[])\n",
      "Unknown contract: Stock(symbol='XXX', exchange='SMART', currency='USD', comboLegs=[])\n"
     ]
    }
   ],
   "source": [
    "qualContracts = ib.qualifyContracts(amd, intc, xxx, eurusd)\n",
    "\n",
    "assert intc in qualContracts\n",
    "assert xxx not in qualContracts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is also an API function to request stocks (only stocks) that match a pattern:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[ContractDescription(contract=Contract(secType='STK', conId=38709539, symbol='INTC', primaryExchange='MEXI', currency='MXN', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=270639, symbol='INTC', primaryExchange='NASDAQ.NMS', currency='USD', comboLegs=[]), derivativeSecTypes=['CFD', 'OPT', 'IOPT', 'WAR', 'FUT']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=12178234, symbol='INTC', primaryExchange='EBS', currency='CHF', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=11463493, symbol='INTCUSD', primaryExchange='EBS', currency='USD', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=130861844, symbol='S', primaryExchange='MEXI', currency='MXN', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=130861851, symbol='2S7', primaryExchange='FWB', currency='EUR', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=130651996, symbol='S', primaryExchange='NYSE', currency='USD', comboLegs=[]), derivativeSecTypes=['CFD', 'OPT', 'FUT']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=14015710, symbol='4613', primaryExchange='TSEJ', currency='JPY', comboLegs=[]), derivativeSecTypes=['CFD']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=257765562, symbol='603737', primaryExchange='SEHKNTL', currency='CNH', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=257310905, symbol='002436', primaryExchange='SEHKSZSE', currency='CNH', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=234809383, symbol='FING.B', primaryExchange='SFB', currency='SEK', comboLegs=[]), derivativeSecTypes=['CFD', 'OPT', 'IOPT']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=234809384, symbol='FPQ1', primaryExchange='FWB2', currency='EUR', comboLegs=[]), derivativeSecTypes=['IOPT']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=83364054, symbol='FRP', primaryExchange='VALUE', currency='USD', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=169544707, symbol='ECC', primaryExchange='NYSE', currency='USD', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=96816938, symbol='E16', primaryExchange='SGX', currency='USD', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=90691307, symbol='1151', primaryExchange='SEHK', currency='HKD', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=173148149, symbol='JYNT', primaryExchange='NASDAQ.SCM', currency='USD', comboLegs=[]), derivativeSecTypes=['OPT']),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=392988575, symbol='1JO', primaryExchange='FWB2', currency='EUR', comboLegs=[]), derivativeSecTypes=[]),\n",
       " ContractDescription(contract=Contract(secType='STK', conId=131085231, symbol='4621', primaryExchange='TSEJ', currency='JPY', comboLegs=[]), derivativeSecTypes=[])]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matches = ib.reqMatchingSymbols('intc')\n",
    "matchContracts = [m.contract for m in matches]\n",
    "\n",
    "matches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "assert intc in matchContracts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "ib.disconnect()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
