Beispiel #1
0
def place_plain_order(expiry, symbol, right, strike, orderType, quantity,
                      lmtPrice, orderId):
    """
    Place a sinlge option order orderType="LMT"
    """
    if orderId <= 0:
        orderId = None

    client, log_order = init_func()
    log_order.info("placing order ")
    ibcontract = IBcontract()
    ibcontract.secType = get_contract_details(symbol)["secType"]
    ibcontract.expiry = expiry
    ibcontract.symbol = symbol
    ibcontract.exchange = get_contract_details(symbol)["exchange"]
    ibcontract.right = right
    ibcontract.strike = strike
    ibcontract.multiplier = get_contract_details(symbol)["multiplier"]
    ibcontract.currency = get_contract_details(symbol)["currency"]

    iborder = IBOrder()
    iborder.action = bs_resolve(quantity)
    iborder.lmtPrice = lmtPrice
    iborder.orderType = orderType
    iborder.totalQuantity = abs(quantity)
    iborder.tif = get_order_defaults()["tif"]
    iborder.transmit = get_order_defaults()["transmit"]

    order_structure = client.place_new_IB_order(ibcontract,
                                                iborder,
                                                orderid=orderId)
    df1 = pd.DataFrame()
    for idx, x in order_structure.items():
        temp = pd.DataFrame.from_dict(x, orient='index').transpose()
        df1 = df1.append(temp)
    if not df1.empty:
        df1 = df1.set_index(['orderid'], drop=True)
    print(df1)
    end_func(client=client)
Beispiel #2
0
                            level=logging.INFO,
                            format='%(asctime)s [%(levelname)s] %(message)s',
                            datefmt='%j-%H:%M:%S')

    logging.debug(args)

    if args.sym: contract.symbol = args.sym
    if args.exc: contract.exchange = args.exc
    if args.st: contract.secType = args.st
    if args.cur: contract.currency = args.cur
    if args.id: contract.conId = args.id
    if args.exp: contract.expiry = args.exp
    if args.pex: contract.primaryExchange = args.pex
    if args.str: contract.strike = args.str
    if args.rt: contract.right = args.rt
    if args.mult: contract.multiplier = args.mult

    barsize = args.p
    datatype = args.t
    rth_only = args.rth
    pacing = args.pacing
    num_requests = args.n
    zerobased = args.z

    if barsize == "1 day" or barsize == "1W" or barsize == "1M":
        dt_format = "%Y%m%d"
    else:
        dt_format = "%Y%m%d %H:%M:%S"

    logging.info("Starting to download {}, series: {}, bartype: '{}'".format(
        contract_to_string(contract), datatype, barsize))
Beispiel #3
0
        logging.basicConfig(handlers=[logging.StreamHandler()], level=logging.DEBUG, format='%(asctime)s [%(levelname)s] %(message)s', datefmt='%j-%H:%M:%S')
    else:
        logging.basicConfig(handlers=[logging.StreamHandler()], level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s', datefmt='%j-%H:%M:%S')

    logging.debug(args)

    if args.sym: contract.symbol = args.sym
    if args.exc: contract.exchange = args.exc
    if args.st: contract.secType = args.st
    if args.cur: contract.currency = args.cur
    if args.id: contract.conId = args.id
    if args.exp: contract.expiry = args.exp
    if args.pex: contract.primaryExchange = args.pex
    if args.str: contract.strike = args.str
    if args.rt: contract.right = args.rt
    if args.mult: contract.multiplier = args.mult

    barsize = args.p
    datatype = args.t
    rth_only = args.rth
    pacing = args.pacing
    num_requests = args.n
    zerobased = args.z

    if barsize == "1 day" or barsize == "1W" or barsize == "1M":
        dt_format = "%Y%m%d"
    else:
        dt_format = "%Y%m%d %H:%M:%S"

    logging.info("Starting to download {}, series: {}, bartype: '{}'".format(contract_to_string(contract), datatype, barsize))