Example #1
0
def test4():
    #global host, port

    f = open(
        '/home/larry/l1304/workspace/finopt/data/subscription-nov-HSI.txt')
    lns = f.readlines()
    cs = map(
        lambda l: ContractHelper.makeContract(tuple(l.strip('\n').split(','))),
        lns)
    c = SampleClient(host, port, 'SampleClient-777')
    c.connect()
    #for contract in cs:
    #c.get_command_handler().reqMktData(cs[0])
    #
    #     contract = Contract() #
    #     contract.m_symbol = 'EUR'
    #     contract.m_currency = 'USD'
    #     contract.m_secType = 'CASH'
    #     contract.m_exchange = 'IDEALPRO'
    #     c.get_command_handler().reqMktData(contract)
    #
    #     contract.m_symbol = 'HSI'
    #     contract.m_currency = 'HKD'
    #     contract.m_secType = 'OPT'
    #     contract.m_exchange = 'HKFE'
    #     contract.m_strike = 21000
    #     contract.m_multiplier = 50.0
    #     contract.m_includeExpired = False
    #
    #     contract.m_right = 'P'
    #     contract.m_expiry = '20151127'
    contract = Contract()
    contract.m_symbol = 'GOOG'
    contract.m_currency = 'USD'
    contract.m_secType = 'STK'
    contract.m_exchange = 'SMART'
    #contract.m_strike = 58.5
    #contract.m_multiplier = 100
    #contract.m_includeExpired = False

    #contract.m_right = 'P'
    #contract.m_expiry = '20151120'
    c.get_command_handler().reqMktData(contract)
    contract = Contract()
    contract.m_symbol = 'EWT'
    contract.m_currency = 'USD'
    contract.m_secType = 'STK'
    contract.m_exchange = 'SMART'
    c.get_command_handler().reqMktData(contract)
    sleep(1)
    c.get_command_handler().gw_req_subscriptions()

    sleep(10)
    c.disconnect()
Example #2
0
def test_subscription():
    s = SubscriptionManager()
    contractTuple = ('HSI', 'FUT', 'HKFE', 'HKD', '20151029', 0, '')
    c = ContractHelper.makeContract(contractTuple)
    print s.is_subscribed(c)
    print s.add_subscription(c)
    print s.is_subscribed(c)
    s.dump()

    fr = open('/home/larry-13.04/workspace/finopt/data/subscription-hsio.txt')
    for l in fr.readlines():
        if l[0] <> '#':

            s.add_subscription(
                ContractHelper.makeContract(
                    tuple([t for t in l.strip('\n').split(',')])))
    fr.close()
    s.dump()

    fr = open('/home/larry-13.04/workspace/finopt/data/subscription-hsio.txt')
    for l in fr.readlines():
        if l[0] <> '#':

            print s.add_subscription(
                ContractHelper.makeContract(
                    tuple([t for t in l.strip('\n').split(',')])))
    s.dump()
    contractTuple = ('HSI', 'FUT', 'HKFE', 'HKD', '20151127', 0, '')
    c = ContractHelper.makeContract(contractTuple)
    print s.is_subscribed(c)
    print s.add_subscription(c)
    print s.is_subscribed(c), ContractHelper.printContract(
        s.itemAt(s.is_subscribed(c)))

    print 'test itemAt:'
    contractTuple = ('HSI', 'OPT', 'HKFE', 'HKD', '20151127', 21400, 'C')
    c = ContractHelper.makeContract(contractTuple)
    print s.is_subscribed(c), ContractHelper.printContract(
        s.itemAt(s.is_subscribed(c)))
Example #3
0
def test7():
    contractTuple = ('VMW', 'STK', 'SMART', 'USD', '', 0, '')
    contract = ContractHelper.makeContract(contractTuple)
    oc = OptionsChain('t7')

    oc.set_underlying(contract)

    oc.set_option_structure(contract, 0.5, 100, 0.0012, 0.0328, '20151211')
    oc.build_chain(59.3, 0.08, 0.22)

    c = SampleClient(host, port, 'SampleClient-777')
    c.connect()
    #c.get_command_handler().reqIds()
    c.get_command_handler().gw_req_subscriptions()

    c.get_command_handler().reqMktData(contract)
    for ct in oc.get_option_chain():
        c.get_command_handler().reqMktData(ct.get_contract())
        print ContractHelper.object2kvstring(ct.get_contract())
    sleep(3)
    c.disconnect()
Example #4
0
def test6():

    contractTuple = ('HSI', 'FUT', 'HKFE', 'HKD', '20151127', 0, '')
    #contractTuple = ('VMW', 'STK', 'SMART', 'USD', '', 0, '')
    contract = ContractHelper.makeContract(contractTuple)
    oc = OptionsChain('test6')

    oc.set_underlying(contract)
    oc.set_option_structure(contract, 200, 50, 0.005, 0.003, '20151127')
    oc.build_chain(22300, 0.1)
    c = SampleClient(host, port, 'SampleClient-777')
    c.connect()
    #c.get_command_handler().reqIds()
    c.get_command_handler().gw_req_subscriptions()

    c.get_command_handler().reqMktData(contract)
    for ct in oc.get_option_chain():
        c.get_command_handler().reqMktData(ct.get_contract())
        print ContractHelper.object2kvstring(ct.get_contract())
    sleep(8)
    c.disconnect()
Example #5
0
        exit(-1)

    cfg_path = sys.argv[1:]
    config = ConfigParser.SafeConfigParser()
    if len(config.read(cfg_path)) == 0:
        raise ValueError, "Failed to open config file"

    logconfig = eval(
        config.get(
            "options_chain",
            "options_calculation_engine.logconfig").strip('"').strip("'"))
    logconfig['format'] = '%(asctime)s %(levelname)-8s %(message)s'
    logging.basicConfig(**logconfig)

    contractTuple = ('QQQ', 'STK', 'SMART', 'USD', '', 0, '')
    contract = ContractHelper.makeContract(contractTuple)
    oc = OptionsChain('QQQ-MAR24')
    oc.set_option_structure(contract, 2.5, 100, 0.005, 0.003, '20160324')
    oc.build_chain(98.0, 0.025, 0.25)
    for c in oc.get_option_chain():
        print '%s' % ContractHelper.makeRedisKeyEx(c.get_contract())

    near_expiry = '20160226'
    contractTuple = ('HSI', 'FUT', 'HKFE', 'HKD', near_expiry, 0, '')
    contract = ContractHelper.makeContract(contractTuple)
    oc1 = OptionsChain('HSI-%s' % near_expiry)
    oc1.set_option_structure(contract, 200, 50, 0.0012, 0.0328, near_expiry)
    oc1.build_chain(19200, 0.08, 0.219)
    for c in oc1.get_option_chain():
        print '%s' % ContractHelper.makeRedisKeyEx(c.get_contract())
Example #6
0
 def subscribe_tuple(self, tuple):
     return self.subscribe(ContractHelper.makeContract(tuple))