Esempio n. 1
0
def create_contract(symbol, secType, exchange, currency='USD'):
    contract = Contract()
    contract.symbol = symbol
    contract.secType = secType
    contract.exchange = exchange
    if currency:
        contract.currency = currency
    return contract
Esempio n. 2
0
 def req_mkt_data(self, symbol):
     contract = Contract();
     contract.symbol = "TSLA";
     contract.secType = "STK";
     contract.exchange = "SMART";
     contract.currency = "USD";
 
     self.reqMktData(1001, contract, "220", False, False, [])
    def create_contract(self, symbol, sec_type, exch, curr):
        contract = Contract()
        contract.symbol = symbol
        contract.secType = sec_type
        contract.exchange = exch
        contract.currency = curr

        return contract
Esempio n. 4
0
def create_nasdaq_contract(ticker):
    contract = Contract()
    contract.symbol = row['ticker']
    contract.secType = "STK"
    contract.exchange = "SMART"
    contract.currency = "USD"
    contract.primaryExchange = "NASDAQ"
    return contract
Esempio n. 5
0
 def create_contract(self, symbol, contract_type):
     if contract_type == "FX":
         contract = Contract()
         contract.symbol = contract_dict[symbol][0]  #FOAT DEC 17
         contract.secType = "CASH"  #FUT
         contract.currency = contract_dict[symbol][1]  #EUR
         contract.exchange = "IDEALPRO"  #DTP
         return contract
     elif contract_type == 'FUTURE':
         contract = Contract()
         contract.symbol = futures_dict[symbol][0]
         contract.secType = "FUT"
         contract.currency = futures_dict[symbol][1]
         contract.exchange = futures_dict[symbol][2]
         contract.lastTradeDateOrContractMonth = futures_dict[symbol][3]
         contract.multiplier = futures_dict[symbol][4]
         return contract
Esempio n. 6
0
 def create_contract(self, symbol, sec_type, exch, prim_exch, curr):
     contract = Contract()
     contract.m_symbol = symbol
     contract.m_secType = sec_type
     contract.m_exchange = exch
     contract.m_primaryExch = prim_exch
     contract.m_currency = curr
     return contract
Esempio n. 7
0
def Stock_contract(symbol, secType='STK', exchange='SMART', currency='USD'):
	''' custom function to create stock contract '''
	contract = Contract()
	contract.symbol = symbol
	contract.secType = secType
	contract.exchange = exchange
	contract.currency = currency
	return contract
Esempio n. 8
0
def stock_order(symbol):
	contract = Contract()	
	contract.symbol = symbol
	contract.secType = "STK"
	contract.currency = "USD"
	contract.exchange = "SMART"
	contract.primaryExchange = "ISLAND"
	return contract
Esempio n. 9
0
 def underlyer(self):
     underlyer = Contract()
     underlyer.symbol = self.statData.buyWrite["underlyer"]["@tickerSymbol"]
     underlyer.avPrice = self.statData.inistkprice
     underlyer.secType = "STK"
     underlyer.exchange = "SMART"
     underlyer.currency = "USD"
     return underlyer
Esempio n. 10
0
 def get_contract(self, symdct):
     ibcontract = Contract()
     ibcontract.symbol = symdct['symbol'].upper()
     ibcontract.secType = symdct['sectype'].upper()
     ibcontract.exchange = symdct['exchange'].upper()
     ibcontract.currency = symdct['currency'].upper()
     ibcontract.primaryExchange = symdct['priexg'].upper()
     return ibcontract
def create_contract(symbol: str, currency: Currencies, exchange: Exchanges,
                    sec_type: SecTypes) -> Contract:
    contract = Contract()
    contract.symbol = symbol
    contract.secType = sec_type.value
    contract.currency = currency.value
    # In the API side, NASDAQ is always defined as ISLAND in the exchange field
    contract.exchange = exchange.value
    return contract
Esempio n. 12
0
def basic_contract(symbol, sec_type, exch, prim_exch, curr):
    contract = Contract()
    contract.symbol = symbol
    contract.secType = sec_type
    contract.exchange = exch
    contract.primaryExchange = exch
    contract.currency = curr

    return contract
def create_contract(symbol, sec_type='STK', exchange='SMART', currency='USD'):
    # stk_aapl = create_contract('AAPL')
    # frx_eurusd = create_contract('EUR', 'CASH', 'IDEALPRO', 'USD')
    contract = Contract()
    contract.symbol = symbol
    contract.secType = sec_type
    contract.exchange = exchange
    contract.currency = currency
    return contract
Esempio n. 14
0
def combo_generator_Switch(symbol: str, abovedays=7, lessdays =120):
    specpath = r'E:\newdata\IB data\Option Specs'
    file = specpath + os.sep + symbol + '-specs.json'
    jf = open(file, 'r')
    jdict = json.load(jf)
    jf.close()

    underlyingfile = r'E:\newdata\IB data\Underlying_Contract_Details.csv'
    underlying = pd.read_csv(underlyingfile)
    syms = list(underlying['symbol'])
    idx = syms.index(symbol)
    last = underlying['Last'][idx]


    underlyingleg = ComboLeg()
    underlyingleg.conId = underlying['conID'][idx]
    underlyingleg.ratio = 100
    underlyingleg.action = 'BUY'
    underlyingleg.exchange = 'SMART'

    Pleg = ComboLeg()
    Pleg.ratio = 1
    Pleg.action = 'BUY'
    Pleg.exchange = 'SMART'

    Cleg = ComboLeg()
    Cleg.ratio = 1
    Cleg.action = 'SELL'
    Cleg.exchange = 'SMART'

    contract = Contract()
    contract.symbol = symbol
    contract.secType = 'BAG'
    contract.currency = 'USD'
    contract.exchange = 'SMART'

    Combos = []

    for mi, di in jdict.items():
        jm = IBdate_to_Date(mi)
        today = date.today()
        if abovedays < (jm - today).days <= lessdays:
            stricks = list(di['C'].keys())
            stricks_1 = [float(i) for i in stricks]
            print(symbol)
            ps = pick_stricks_2(last, stricks_1, 2)
            for si in ps:
                Pleg.conId = di['P'][str(si)]['conID']
                Cleg.conId = di['C'][str(si)]['conID']
                contract.comboLegs = []

                contract.comboLegs.append(underlyingleg)
                contract.comboLegs.append(Pleg)
                contract.comboLegs.append(Cleg)
                Combos.append([deepcopy(contract), si])

    return Combos
Esempio n. 15
0
 def get_data(self):
     contract = Contract()
     contract.symbol = "INGA"
     contract.secType = "STK"
     contract.currency = "EUR"
     contract.exchange = "AEB"
     #self.reqHistoricalTicks(106,contract,"20190307 21:39:33","",1,"TRADES",1,True,[])
     self.reqFundamentalData(1233, contract, "ReportsFinSummary", [])
     self.reqContractDetails(20, contract)
Esempio n. 16
0
 def FutureWithMultiplier():
     contract = Contract()
     contract.symbol = "DAX"
     contract.secType = "FUT"
     contract.exchange = "DTB"
     contract.currency = "EUR"
     contract.lastTradeDateOrContractMonth = "201609"
     contract.multiplier = "5"
     return contract
Esempio n. 17
0
 def futures_contract(ticker: str, exchange: str):
     # ! [futcontract_local_symbol]
     contract = Contract()
     contract.secType = "FUT"
     contract.exchange = exchange
     contract.currency = "USD"
     contract.localSymbol = ticker
     # ! [futcontract_local_symbol]
     return contract
Esempio n. 18
0
 def start(self):
     contract = Contract()
     contract.symbol = "TGP"
     contract.secType = "STK"
     contract.exchange = "SMART"
     contract.currency = "USD"
     contract.primaryExchange = "NASDAQ"
     self.reqMarketDataType(4)
     self.reqMktData(1, contract, '258,456', False, False, [])
Esempio n. 19
0
def ASX_contract(ticker):
    contract = Contract()
    contract.symbol = ticker
    contract.secType = 'STK'
    contract.exchange = 'SMART'
    contract.currency = 'AUD'
    contract.primaryExchange = 'ASX'

    return contract
Esempio n. 20
0
def makeSimpleContract(ct:OneContract):
    contract = Contract()
    contract.symbol=ct.symbol
    contract.secType=ct.sectype
    contract.currency=ct.currency
    contract.exchange=ct.exchange
    contract.lastTradeDateOrContractMonth=ct.expire
    #contract.conId=ct.contractID can't to this contract ID is different
    return contract
Esempio n. 21
0
def createContractObject(tickerlist):
    obj = [Contract() for i in range(len(tickerlist))]
    for cont, ticker in zip(obj, tickerlist):
        cont.symbol = ticker
        cont.secType = "STK"
        cont.currency = "AUD"
        cont.exchange = "ASX"

    return obj
Esempio n. 22
0
 def USStockWithPrimaryExch():
     contract = Contract()
     contract.symbol = "MSFT"
     contract.secType = "STK"
     contract.currency = "USD"
     contract.exchange = "SMART"
     # Specify the Primary Exchange attribute to avoid contract ambiguity
     # (there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
     contract.primaryExchange = "ISLAND"
     return contract
Esempio n. 23
0
def make_contract(symbol, exchange):
    if symbol.startswith('US.'):
        symbol = ''.join(symbol[3:])
    contract = Contract()
    contract.symbol = symbol
    contract.secType = "STK"
    contract.currency = "USD"
    contract.exchange = exchange
    contract.primaryExchange = "ISLAND"
    return contract
Esempio n. 24
0
 def getFxContract(self, symbol):
     symbolParts = symbol.split('.')
     if len(symbolParts) != 2:
         raise Exception('Invalid FX symbol. Must be in format XXX.YYY')
     contract = Contract()
     contract.symbol = symbolParts[0]
     contract.secType = 'CASH'
     contract.currency = symbolParts[1]
     contract.exchange = 'IDEALPRO'
     return contract
Esempio n. 25
0
    def start(self):
        contract = Contract()
        contract.symbol = "TGP PRb"
        contract.secType = "STK"
        contract.exchange = "SMART"
        contract.currency = "USD"
        contract.primaryExchange = "NASDAQ"

        self.reqHistoricalData(1, contract, "", "26 W", "1 day", "MIDPOINT", 0,
                               1, False, [])
Esempio n. 26
0
def contract_maker(instrument: str):
    market_map = {"FUTURE": "FUT", "SPOT": "CMDTY"}
    xchg, symbol, market = instrument.upper().split(".")
    sym = symbol.split("_")
    ib_contract = Contract()
    ib_contract.symbol = f"{sym[0]}USD"
    ib_contract.currency = "USD"
    ib_contract.secType = market_map.get(market, "ERR")
    ib_contract.exchange = xchg
    return ib_contract
Esempio n. 27
0
    def create_contract(self, symbol):
        """ Creates an IB contract."""

        contract = Contract()
        contract.symbol = symbol
        contract.exchange = 'SMART'
        contract.secType = 'STK'
        contract.currency = 'USD'

        return contract
Esempio n. 28
0
 def get_contract(self, code: str) -> Contract:
     contract = Contract()
     ss = code.split("_")
     contract.symbol = ss[0]
     contract.secType = ss[1]
     contract.currency = ss[2]
     contract.exchange = ss[3]
     contract_detail: ContractDetails = self.sync_get_contract_detail(contract)
     contract.conId = contract_detail.contract.conId
     return contract
def main():
    app = TestApp()
    app.connect("127.0.0.1", XXXX, 0)    # xxxx is your port number
    contact = Contract()
    contact.symbol = "ACC"
    contact.secType = "STK"
    contact.exchange = "NSE"
    contact.currency = "INR"
    app.reqHistoricalData(1, contact, "20191230 15:30:00", "1 M", "1 min", "MIDPOINT", 0, 1, False, []) # user specific date and time
    app.run()
Esempio n. 30
0
def SimpleFuture():
    #! [futcontract]
    contract = Contract()
    contract.symbol = "ES"
    contract.secType = "FUT"
    contract.exchange = "GLOBEX"
    contract.currency = "USD"
    contract.lastTradeDateOrContractMonth = "202006"
    #! [futcontract]
    return contract