|
@@ -1,11 +1,8 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
-
|
|
|
|
|
import sys, traceback
|
|
import sys, traceback
|
|
|
import json
|
|
import json
|
|
|
import logging
|
|
import logging
|
|
|
-import ConfigParser
|
|
|
|
|
-from ib.ext.Contract import Contract
|
|
|
|
|
-from ib.opt import ibConnection, message
|
|
|
|
|
|
|
+from misc2.helpers import ContractHelper, ConfigMap
|
|
|
from time import sleep
|
|
from time import sleep
|
|
|
import time, datetime
|
|
import time, datetime
|
|
|
from os import listdir
|
|
from os import listdir
|
|
@@ -14,14 +11,11 @@ from threading import Lock
|
|
|
from comms.ib_heartbeat import IbHeartBeat
|
|
from comms.ib_heartbeat import IbHeartBeat
|
|
|
import threading, urllib2
|
|
import threading, urllib2
|
|
|
from optparse import OptionParser
|
|
from optparse import OptionParser
|
|
|
-#from options_data import ContractHelper
|
|
|
|
|
-
|
|
|
|
|
import finopt.options_data as options_data
|
|
import finopt.options_data as options_data
|
|
|
-#from kafka.client import KafkaClient
|
|
|
|
|
-#from kafka.producer import SimpleProducer
|
|
|
|
|
-from kafka import KafkaConsumer, KafkaProducer
|
|
|
|
|
-from comms.alert_bot import AlertHelper
|
|
|
|
|
-
|
|
|
|
|
|
|
+from kafka import KafkaProducer
|
|
|
|
|
+from misc2.observer import Publisher
|
|
|
|
|
+from ib.opt import ibConnection
|
|
|
|
|
+import importlib
|
|
|
##
|
|
##
|
|
|
## to run, start kafka server on vsu-01 <administrator, password>
|
|
## to run, start kafka server on vsu-01 <administrator, password>
|
|
|
## start ibgw or tws
|
|
## start ibgw or tws
|
|
@@ -29,53 +23,39 @@ from comms.alert_bot import AlertHelper
|
|
|
## check the settings in the console
|
|
## check the settings in the console
|
|
|
##
|
|
##
|
|
|
|
|
|
|
|
-class IbKafkaProducer():
|
|
|
|
|
|
|
+class IbKafkaProducer(Publisher):
|
|
|
|
|
|
|
|
- config = None
|
|
|
|
|
- con = None
|
|
|
|
|
- quit = False
|
|
|
|
|
- producer = None
|
|
|
|
|
- IB_TICK_PRICE = None
|
|
|
|
|
- IB_TICK_SIZE = None
|
|
|
|
|
- toggle = False
|
|
|
|
|
- persist = {}
|
|
|
|
|
- ibh = None
|
|
|
|
|
- tlock = None
|
|
|
|
|
- ib_conn_status = None
|
|
|
|
|
-
|
|
|
|
|
- id2contract = {'conId': 1, 'id2contracts': {} }
|
|
|
|
|
|
|
+ IB_TICK_PRICE = 'tickPrice'
|
|
|
|
|
+ IB_TICK_SIZE = 'tickSize'
|
|
|
|
|
+ IB_TICK_OPTION_COMPUTATION = 'tickOptionComputation'
|
|
|
|
|
|
|
|
|
|
+ EVENT_READ_FILE_LINE = 'event_read_file_line'
|
|
|
|
|
+ PUBLISH_EVENTS = [EVENT_READ_FILE_LINE, IB_TICK_PRICE, IB_TICK_SIZE, IB_TICK_OPTION_COMPUTATION]
|
|
|
|
|
|
|
|
def __init__(self, config, replay = False):
|
|
def __init__(self, config, replay = False):
|
|
|
|
|
|
|
|
|
|
+ Publisher.__init__(self, IbKafkaProducer.PUBLISH_EVENTS)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
self.config = config
|
|
self.config = config
|
|
|
self.tlock = Lock()
|
|
self.tlock = Lock()
|
|
|
-# host = self.config.get("ib_mds", "ib_mds.gateway").strip('"').strip("'")
|
|
|
|
|
-# port = int(self.config.get("ib_mds", "ib_mds.ib_port"))
|
|
|
|
|
-# appid = int(self.config.get("ib_mds", "ib_mds.appid.id"))
|
|
|
|
|
- kafka_host = self.config.get("cep", "kafka.host").strip('"').strip("'")
|
|
|
|
|
- kafka_port = self.config.get("cep", "kafka.port").strip('"').strip("'")
|
|
|
|
|
- self.persist['is_persist'] = self.config.get("ib_mds", "ib_mds.is_persist")
|
|
|
|
|
- self.persist['persist_dir'] =self.config.get("ib_mds", "ib_mds.persist_dir").strip('"').strip("'")
|
|
|
|
|
|
|
+ self.persist = {}
|
|
|
|
|
+ self.quit = False
|
|
|
|
|
+ self.toggle = False
|
|
|
|
|
+ self.id2contract = {'conId': 1, 'id2contracts': {} }
|
|
|
|
|
+ kafka_host = self.config["kafka.host"]
|
|
|
|
|
+ kafka_port = self.config["kafka.port"]
|
|
|
|
|
+ self.persist['is_persist'] = config["ib_mds.is_persist"]
|
|
|
|
|
+ self.persist['persist_dir'] =config["ib_mds.persist_dir"]
|
|
|
self.persist['file_exist'] = False
|
|
self.persist['file_exist'] = False
|
|
|
- self.persist['spill_over_limit'] = int(self.config.get("ib_mds", "ib_mds.spill_over_limit"))
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- IbKafkaProducer.IB_TICK_PRICE = self.config.get("cep", "kafka.ib.topic.tick_price").strip('"').strip("'")
|
|
|
|
|
- IbKafkaProducer.IB_TICK_SIZE = self.config.get("cep", "kafka.ib.topic.tick_size").strip('"').strip("'")
|
|
|
|
|
-# self.con = ibConnection(host, port, appid)
|
|
|
|
|
-# self.con.registerAll(self.on_ib_message)
|
|
|
|
|
-# rc = self.con.connect()
|
|
|
|
|
-# if rc:
|
|
|
|
|
-# self.ib_conn_status = 'OK'
|
|
|
|
|
-
|
|
|
|
|
-# logging.info('IbKafkaProducer: connection status to IB is %d' % rc)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ self.persist['spill_over_limit'] = int(config["ib_mds.spill_over_limit"])
|
|
|
|
|
+ self.load_processors(config['ib_mds.processors'])
|
|
|
|
|
+ IbKafkaProducer.IB_TICK_PRICE = config["kafka.ib.topic.tick_price"]
|
|
|
|
|
+ IbKafkaProducer.IB_TICK_SIZE = config["kafka.ib.topic.tick_size"]
|
|
|
logging.info('******* Starting IbKafkaProducer')
|
|
logging.info('******* Starting IbKafkaProducer')
|
|
|
logging.info('IbKafkaProducer: connecting to kafka host: %s...' % kafka_host)
|
|
logging.info('IbKafkaProducer: connecting to kafka host: %s...' % kafka_host)
|
|
|
logging.info('IbKafkaProducer: message mode is async')
|
|
logging.info('IbKafkaProducer: message mode is async')
|
|
|
|
|
|
|
|
-
|
|
|
|
|
kwargs = {
|
|
kwargs = {
|
|
|
'name': 'ib_mds',
|
|
'name': 'ib_mds',
|
|
|
'bootstrap_host': kafka_host,
|
|
'bootstrap_host': kafka_host,
|
|
@@ -86,17 +66,30 @@ class IbKafkaProducer():
|
|
|
'order_transmit': False
|
|
'order_transmit': False
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- #client = KafkaClient(**kwargs)
|
|
|
|
|
self.producer = KafkaProducer(bootstrap_servers='%s:%s' % (kwargs['bootstrap_host'], kwargs['bootstrap_port']))
|
|
self.producer = KafkaProducer(bootstrap_servers='%s:%s' % (kwargs['bootstrap_host'], kwargs['bootstrap_port']))
|
|
|
-
|
|
|
|
|
if not replay:
|
|
if not replay:
|
|
|
self.start_ib_connection()
|
|
self.start_ib_connection()
|
|
|
|
|
|
|
|
-# # start heart beat monitor
|
|
|
|
|
-# self.ibh = IbHeartBeat(config)
|
|
|
|
|
-# self.ibh.register_listener([self.on_ib_conn_broken])
|
|
|
|
|
-# #self.ibh.run()
|
|
|
|
|
|
|
+#from cep.ib_mds.processor.us_stkopt import StockOptionsSnapshot
|
|
|
|
|
+ self.main_loop()
|
|
|
|
|
+
|
|
|
|
|
+ def load_processors(self, plist):
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def instantiate_processor(p):
|
|
|
|
|
+ p_toks = p.split('.')
|
|
|
|
|
+ class_name = p_toks[len(p_toks)-1]
|
|
|
|
|
+ module_name = p_toks[:len(p_toks)-1]
|
|
|
|
|
+ module = importlib.import_module(p.replace('.%s' % class_name, ''))
|
|
|
|
|
+ class_ = getattr(module, class_name)
|
|
|
|
|
+ return class_(self.config)
|
|
|
|
|
+
|
|
|
|
|
+ processors = map(instantiate_processor, plist)
|
|
|
|
|
+ for p in processors:
|
|
|
|
|
+ map(lambda e: self.register(e, p, getattr(p, e)), IbKafkaProducer.PUBLISH_EVENTS)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def pub_cn_index(self, sec):
|
|
def pub_cn_index(self, sec):
|
|
|
#http://blog.csdn.net/moneyice/article/details/7877030
|
|
#http://blog.csdn.net/moneyice/article/details/7877030
|
|
@@ -129,13 +122,15 @@ class IbKafkaProducer():
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_contract(self, clist):
|
|
def add_contract(self, clist):
|
|
|
-
|
|
|
|
|
tuple = map(lambda x: x if x not in [''] else None, clist)
|
|
tuple = map(lambda x: x if x not in [''] else None, clist)
|
|
|
c = options_data.ContractHelper.makeContract(tuple)
|
|
c = options_data.ContractHelper.makeContract(tuple)
|
|
|
self.con.reqMktData(self.id2contract['conId'], c, '', False)
|
|
self.con.reqMktData(self.id2contract['conId'], c, '', False)
|
|
|
self.id2contract['id2contracts'][self.id2contract['conId']] = options_data.ContractHelper.makeRedisKeyEx(c)
|
|
self.id2contract['id2contracts'][self.id2contract['conId']] = options_data.ContractHelper.makeRedisKeyEx(c)
|
|
|
self.id2contract['conId']+=1
|
|
self.id2contract['conId']+=1
|
|
|
|
|
|
|
|
|
|
+ def delete_contract(self, id):
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
def on_ib_conn_broken(self, msg):
|
|
def on_ib_conn_broken(self, msg):
|
|
|
logging.error('IbKafkaProducer: connection is broken!')
|
|
logging.error('IbKafkaProducer: connection is broken!')
|
|
|
self.ib_conn_status = 'ERROR'
|
|
self.ib_conn_status = 'ERROR'
|
|
@@ -147,9 +142,9 @@ class IbKafkaProducer():
|
|
|
self.con.eDisconnect()
|
|
self.con.eDisconnect()
|
|
|
|
|
|
|
|
|
|
|
|
|
- host = self.config.get("ib_mds", "ib_mds.gateway").strip('"').strip("'")
|
|
|
|
|
- port = int(self.config.get("ib_mds", "ib_mds.ib_port"))
|
|
|
|
|
- appid = int(self.config.get("ib_mds", "ib_mds.appid.id"))
|
|
|
|
|
|
|
+ host = self.config["ib_mds.gateway"]
|
|
|
|
|
+ port = int(self.config["ib_mds.ib_port"])
|
|
|
|
|
+ appid = int(self.config["ib_mds.appid.id"])
|
|
|
self.con = ibConnection(host, port, appid)
|
|
self.con = ibConnection(host, port, appid)
|
|
|
self.con.registerAll(self.on_ib_message)
|
|
self.con.registerAll(self.on_ib_message)
|
|
|
rc = None
|
|
rc = None
|
|
@@ -163,8 +158,8 @@ class IbKafkaProducer():
|
|
|
if not self.quit:
|
|
if not self.quit:
|
|
|
# resubscribe tickers again!
|
|
# resubscribe tickers again!
|
|
|
self.load_tickers()
|
|
self.load_tickers()
|
|
|
- a = AlertHelper(self.config)
|
|
|
|
|
- a.post_msg('ib_mds recovered from broken ib conn, re-subscribe tickers...')
|
|
|
|
|
|
|
+# a = AlertHelper(self.config)
|
|
|
|
|
+# a.post_msg('ib_mds recovered from broken ib conn, re-subscribe tickers...')
|
|
|
logging.debug('on_ib_conn_broken: completed restoration. releasing lock...')
|
|
logging.debug('on_ib_conn_broken: completed restoration. releasing lock...')
|
|
|
self.ib_conn_status = 'OK'
|
|
self.ib_conn_status = 'OK'
|
|
|
|
|
|
|
@@ -189,7 +184,7 @@ class IbKafkaProducer():
|
|
|
return json.dumps(d)
|
|
return json.dumps(d)
|
|
|
|
|
|
|
|
|
|
|
|
|
- if msg.typeName in ['tickPrice', 'tickSize']:
|
|
|
|
|
|
|
+ if msg.typeName in ['tickPrice', 'tickSize', 'tickOptionComputation']:
|
|
|
|
|
|
|
|
t = create_tick_kmessage(msg)
|
|
t = create_tick_kmessage(msg)
|
|
|
logging.debug(t)
|
|
logging.debug(t)
|
|
@@ -199,7 +194,14 @@ class IbKafkaProducer():
|
|
|
if self.persist['is_persist']:
|
|
if self.persist['is_persist']:
|
|
|
self.write_message_to_file(t)
|
|
self.write_message_to_file(t)
|
|
|
|
|
|
|
|
|
|
+ event = msg.typeName
|
|
|
|
|
+ attrs = dir(msg)
|
|
|
|
|
+ params = dict()
|
|
|
|
|
+ for e in filter(lambda a: a not in ['typeName', 'keys', 'items', 'values'] and '__' not in a, attrs):
|
|
|
|
|
+ params[e] = getattr(msg, e)
|
|
|
|
|
+ params['contract_key'] = self.id2contract['id2contracts'][msg.tickerId]
|
|
|
|
|
|
|
|
|
|
+ self.dispatch(event, params)
|
|
|
|
|
|
|
|
# print ",%0.4f,%0.4f" % (msg.pos, msg.avgCost)
|
|
# print ",%0.4f,%0.4f" % (msg.pos, msg.avgCost)
|
|
|
# self.producer.send_messages('my.topic', "%0.4f,%0.4f" % (msg.pos, msg.avgCost))
|
|
# self.producer.send_messages('my.topic', "%0.4f,%0.4f" % (msg.pos, msg.avgCost))
|
|
@@ -228,9 +230,9 @@ class IbKafkaProducer():
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_ib_connection(self):
|
|
def start_ib_connection(self):
|
|
|
- host = self.config.get("ib_mds", "ib_mds.gateway").strip('"').strip("'")
|
|
|
|
|
- port = int(self.config.get("ib_mds", "ib_mds.ib_port"))
|
|
|
|
|
- appid = int(self.config.get("ib_mds", "ib_mds.appid.id"))
|
|
|
|
|
|
|
+ host = self.config["ib_mds.gateway"]
|
|
|
|
|
+ port = int(self.config["ib_mds.ib_port"])
|
|
|
|
|
+ appid = int(self.config["ib_mds.appid.id"])
|
|
|
self.con = ibConnection(host, port, appid)
|
|
self.con = ibConnection(host, port, appid)
|
|
|
self.con.registerAll(self.on_ib_message)
|
|
self.con.registerAll(self.on_ib_message)
|
|
|
rc = self.con.connect()
|
|
rc = self.con.connect()
|
|
@@ -239,18 +241,38 @@ class IbKafkaProducer():
|
|
|
logging.info('start_ib_connection: connection status to IB is %d' % rc)
|
|
logging.info('start_ib_connection: connection status to IB is %d' % rc)
|
|
|
|
|
|
|
|
# start heart beat monitor
|
|
# start heart beat monitor
|
|
|
- self.ibh = IbHeartBeat(config)
|
|
|
|
|
|
|
+ self.ibh = IbHeartBeat(self.config)
|
|
|
self.ibh.register_listener([self.on_ib_conn_broken])
|
|
self.ibh.register_listener([self.on_ib_conn_broken])
|
|
|
self.ibh.run()
|
|
self.ibh.run()
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ '''
|
|
|
|
|
+ SAMPLE FILE FORMAT
|
|
|
|
|
+
|
|
|
|
|
+ #
|
|
|
|
|
+ # US Stock options
|
|
|
|
|
+ # symbol, sectype, exch, ccy, expiry, strike, right
|
|
|
|
|
+ #
|
|
|
|
|
+ #
|
|
|
|
|
+ GOOG,STK,SMART,USD,,,
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1172.5,C
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1172.5,P
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1175,C
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1175,P
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1177.5,C
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1177.5,P
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1180,C
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1180,P
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1182.5,C
|
|
|
|
|
+ GOOG,OPT,SMART,USD,20190510,1182.5,P
|
|
|
|
|
+
|
|
|
|
|
+ '''
|
|
|
def load_tickers(self, path=None):
|
|
def load_tickers(self, path=None):
|
|
|
|
|
|
|
|
self.id2contract = {'conId': 1, 'id2contracts': {} }
|
|
self.id2contract = {'conId': 1, 'id2contracts': {} }
|
|
|
|
|
|
|
|
|
|
|
|
|
if path is None:
|
|
if path is None:
|
|
|
- path = self.config.get("ib_mds", "ib_mds.subscription.fileloc").strip('"').strip("'")
|
|
|
|
|
|
|
+ path = self.config["ib_mds.subscription.fileloc"]
|
|
|
logging.info('load_tickers: attempt to open file %s' % path)
|
|
logging.info('load_tickers: attempt to open file %s' % path)
|
|
|
fr = open(path)
|
|
fr = open(path)
|
|
|
for l in fr.readlines():
|
|
for l in fr.readlines():
|
|
@@ -258,6 +280,7 @@ class IbKafkaProducer():
|
|
|
|
|
|
|
|
self.add_contract([t for t in l.strip('\n').split(',')])
|
|
self.add_contract([t for t in l.strip('\n').split(',')])
|
|
|
|
|
|
|
|
|
|
+ self.dispatch(IbKafkaProducer.EVENT_READ_FILE_LINE, {'record': l})
|
|
|
|
|
|
|
|
def do_work(self):
|
|
def do_work(self):
|
|
|
while not self.quit:
|
|
while not self.quit:
|
|
@@ -311,28 +334,60 @@ class IbKafkaProducer():
|
|
|
process_msg(f)
|
|
process_msg(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
- def console(self):
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def main_loop(self):
|
|
|
|
|
+ def print_menu():
|
|
|
|
|
+ menu = {}
|
|
|
|
|
+ menu['1']="list all subscribed contracts,"
|
|
|
|
|
+ menu['2']="turn/on off output"
|
|
|
|
|
+ menu['3']="Start up configuration"
|
|
|
|
|
+ menu['4']=""
|
|
|
|
|
+ menu['9']="Exit"
|
|
|
|
|
+
|
|
|
|
|
+ choices=menu.keys()
|
|
|
|
|
+ choices.sort()
|
|
|
|
|
+ for entry in choices:
|
|
|
|
|
+ print entry, menu[entry]
|
|
|
|
|
+
|
|
|
|
|
+ def get_user_input(selection):
|
|
|
|
|
+
|
|
|
|
|
+ print_menu()
|
|
|
|
|
+ while 1:
|
|
|
|
|
+ resp = sys.stdin.readline()
|
|
|
|
|
+ response[0] = resp.strip('\n')
|
|
|
try:
|
|
try:
|
|
|
- while not self.quit:
|
|
|
|
|
- print "Available commands are: l - list all subscribed contracts, a <symbol> <sectype> <exch> <ccy>"
|
|
|
|
|
- print " t - turn/on off output q - terminate program"
|
|
|
|
|
- cmd = raw_input(">>")
|
|
|
|
|
- input = cmd.split(' ')
|
|
|
|
|
- if input[0] == "q":
|
|
|
|
|
- print 'quit command received...'
|
|
|
|
|
- self.quit = True
|
|
|
|
|
- elif input[0] == 'l' :
|
|
|
|
|
- print ''.join('%s: %s\n' % (k, v) for k, v in self.id2contract['id2contracts'].iteritems())
|
|
|
|
|
- elif input[0] == 'a':
|
|
|
|
|
- self.add_contract((input[1],input[2],input[3],input[4],'',0,''))
|
|
|
|
|
- elif input[0] == 't':
|
|
|
|
|
- self.toggle = False if self.toggle else True
|
|
|
|
|
- else:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
|
|
|
- except:
|
|
|
|
|
- exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
|
|
|
- traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
|
|
|
|
|
|
|
+ response = [None]
|
|
|
|
|
+ user_input_th = threading.Thread(target=get_user_input, args=(response,))
|
|
|
|
|
+ user_input_th.daemon = True
|
|
|
|
|
+ user_input_th.start()
|
|
|
|
|
+ self.pcounter = 0
|
|
|
|
|
+ self.menu_loop_done = False
|
|
|
|
|
+ while not self.menu_loop_done:
|
|
|
|
|
+
|
|
|
|
|
+ sleep(.5)
|
|
|
|
|
+
|
|
|
|
|
+ if response[0] is not None:
|
|
|
|
|
+ selection = response[0]
|
|
|
|
|
+ if selection =='1':
|
|
|
|
|
+ print ''.join('%s: %s\n' % (k, v) for k, v in self.id2contract['id2contracts'].iteritems())
|
|
|
|
|
+ elif selection == 't':
|
|
|
|
|
+ self.toggle = False if self.toggle else True
|
|
|
|
|
+ elif selection == '9':
|
|
|
|
|
+ print 'quit command received...'
|
|
|
|
|
+ self.quit = True
|
|
|
|
|
+ sys.exit(0)
|
|
|
|
|
+ break
|
|
|
|
|
+ else:
|
|
|
|
|
+ pass
|
|
|
|
|
+ response[0] = None
|
|
|
|
|
+ print_menu()
|
|
|
|
|
+
|
|
|
|
|
+ except (KeyboardInterrupt, SystemExit):
|
|
|
|
|
+ logging.error('ib_mds: caught user interrupt. Shutting down...')
|
|
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
@@ -343,7 +398,12 @@ if __name__ == '__main__':
|
|
|
parser.add_option("-r", "--replay",
|
|
parser.add_option("-r", "--replay",
|
|
|
dest="replay_dir",
|
|
dest="replay_dir",
|
|
|
help="replay recorded mds files stored in the specified directory")
|
|
help="replay recorded mds files stored in the specified directory")
|
|
|
-
|
|
|
|
|
|
|
+ parser.add_option("-s", "--symbols",
|
|
|
|
|
+ action="store", dest="symbols_file",
|
|
|
|
|
+ help="the file defines stocks symbols for which to save ticks")
|
|
|
|
|
+ parser.add_option("-f", "--config_file",
|
|
|
|
|
+ action="store", dest="config_file",
|
|
|
|
|
+ help="path to the config file")
|
|
|
|
|
|
|
|
|
|
|
|
|
options, arguments = parser.parse_args()
|
|
options, arguments = parser.parse_args()
|
|
@@ -354,17 +414,24 @@ if __name__ == '__main__':
|
|
|
print("Usage: %s [options] <config file>" % sys.argv[0])
|
|
print("Usage: %s [options] <config file>" % sys.argv[0])
|
|
|
exit(-1)
|
|
exit(-1)
|
|
|
|
|
|
|
|
- cfg_path= arguments[0]
|
|
|
|
|
- config = ConfigParser.SafeConfigParser()
|
|
|
|
|
- if len(config.read(cfg_path)) == 0:
|
|
|
|
|
- raise ValueError, "Failed to open config file"
|
|
|
|
|
|
|
|
|
|
|
|
+ kwargs = ConfigMap().kwargs_from_file(options.config_file)
|
|
|
|
|
+ for option, value in options.__dict__.iteritems():
|
|
|
|
|
+
|
|
|
|
|
+ if value <> None:
|
|
|
|
|
+ kwargs[option] = value
|
|
|
|
|
+ cfg_path= options.config_file
|
|
|
|
|
+
|
|
|
|
|
+ if options.symbols_file:
|
|
|
|
|
+ kwargs['ib_mds.subscription.fileloc']= options.symbols_file
|
|
|
|
|
|
|
|
- logconfig = eval(config.get("ib_mds", "ib_mds.logconfig").strip('"').strip("'"))
|
|
|
|
|
|
|
+ logconfig = kwargs['ib_mds.logconfig']
|
|
|
logconfig['format'] = '%(asctime)s %(levelname)-8s %(message)s'
|
|
logconfig['format'] = '%(asctime)s %(levelname)-8s %(message)s'
|
|
|
- logging.basicConfig(**logconfig)
|
|
|
|
|
|
|
+ logging.basicConfig(**logconfig)
|
|
|
|
|
+
|
|
|
|
|
+ logging.info('config settings: %s' % kwargs)
|
|
|
replay = True if options.replay_dir <> None else False
|
|
replay = True if options.replay_dir <> None else False
|
|
|
- ik = IbKafkaProducer(config, replay)
|
|
|
|
|
|
|
+ ik = IbKafkaProducer(kwargs, replay)
|
|
|
|
|
|
|
|
if not replay:
|
|
if not replay:
|
|
|
ik.load_tickers()
|
|
ik.load_tickers()
|