def main(): bf = TestBarFeed(bar.Frequency.DAY) bars = [ bar.BasicBar(datetime.datetime(2000, 1, 1), 10, 10, 10, 10, 10, 10, bar.Frequency.DAY), bar.BasicBar(datetime.datetime(2000, 1, 2), 10, 10, 10, 10, 10, 10, bar.Frequency.DAY), ] bf.addBarsFromSequence("orcl", bars) logger.getLogger().setLevel(logging.DEBUG) strat = BacktestingStrategy(bf, 1) strat.run()
class redis_db(object): def __init__(self): serv = getConfigInfo('Redis') self._host = serv['host'] self._port = serv['port'] self.__logger = getLogger('Redis') self._conn = self.connect()
def main(): """ prepare logging object """ # logging.basicConfig(level=logging.DEBUG, # format='%(asctime)s %(levelname)s\t%(name)s\t: %(message)s', # datefmt='%a, %d %b %Y %H:%M:%S', # filename='debug.log') log = l.getLogger('main') log.debug(' #################### Starting ####################') """ Create config object and parse command line options """ conf = EC.Instance() conf.setPath(os.path.abspath(os.path.join(os.path.dirname(__file__)))) conf.loadConfig() conf.setConfValue('baseDir', os.path.dirname(__file__)) log.debug((docopt(__doc__, version='0.1'))) log.debug('Creating core object') gfx = Core() # Hide the mouse cursor and prevent the mouse from leaving the window. log.debug('Setting up core object') gfx.set_exclusive_mouse(True) gfx.setup()
def __init__(self, collection): serv = getConfigInfo('Mongo') self.__host = serv['host'] self.__port = serv['port'] self.__dbname = serv['dbname'] self.__logger = getLogger('Mongodb') self.__client = self.__connect() self.__col = self.__client[self.__dbname][collection]
def __init__(self, cash, barFeed, commission=None): super(Broker, self).__init__() assert (cash >= 0) self.__cash = cash if commission is None: self.__commission = NoCommission() else: self.__commission = commission self.__shares = {} self.__activeOrders = {} self.__useAdjustedValues = False self.__fillStrategy = fillstrategy.DefaultStrategy() self.__logger = logger.getLogger(Broker.LOGGER_NAME) # It is VERY important that the broker subscribes to barfeed events before the strategy. barFeed.getNewValuesEvent().subscribe(self.onBars) self.__barFeed = barFeed self.__allowNegativeCash = False self.__nextOrderId = 1
def __init__(self, msg_queue): """API对象的初始化函数""" super(CTPTdApi, self).__init__() self.reqID = 0 # 操作请求编号 self.orderRef = 0 # 订单编号 self.connectionStatus = False # 连接状态 self.loginStatus = False # 登录状态 self.userID = None # 账号 self.password = None # 密码 self.brokerID = None # 经纪商代码 self.address = None # 服务器地址 self.frontID = None # 前置机编号 self.sessionID = None # 会话编号 self.__msg_queue = msg_queue self.__oders = set() self._logger = getLogger('CTP')
def __init__(self, barFeed, broker): self.__barFeed = barFeed self.__broker = broker self.__activePositions = set() self.__orderToPosition = {} self.__barsProcessedEvent = observer.Event() self.__analyzers = [] self.__namedAnalyzers = {} self.__resampledBarFeeds = [] self.__dispatcher = dispatcher.Dispatcher() self.__broker.getOrderUpdatedEvent().subscribe(self.__onOrderEvent) self.__barFeed.getNewValuesEvent().subscribe(self.__onBars) self.__dispatcher.getStartEvent().subscribe(self.onStart) self.__dispatcher.getIdleEvent().subscribe(self.__onIdle) # It is important to dispatch broker events before feed events, specially if we're backtesting. self.__dispatcher.addSubject(self.__broker) self.__dispatcher.addSubject(self.__barFeed) # Initialize logging. self.__logger = logger.getLogger(BaseStrategy.LOGGER_NAME)
def __init__(self, msg_queue): """API对象的初始化函数""" super(CTPTdApi, self).__init__() self.reqID = 0 # 操作请求编号 self.orderRef = 0 # 订单编号 self.connectionStatus = False # 连接状态 self.loginStatus = False # 登录状态 self.userID = None # 账号 self.password = None # 密码 self.brokerID = None # 经纪商代码 self.address = None # 服务器地址 self.frontID = None # 前置机编号 self.sessionID = None # 会话编号 self.__msg_queue= msg_queue self.__oders = set() self._logger = getLogger('CTP')
Created on Sun Dec 11 14:31:04 2016 """ import time import Queue from datetime import datetime from engine import broker from engine.logger import getLogger from engine.api.ctp import CTPTdApi from components.database.mongo import * from components.celery.tasks import * from components.celery.tasksmgmt import * logger = getLogger('CTP_broker') class FutureTraits(broker.InstrumentTraits): def roundQuantity(self, quantity): return round(quantity, 2) def getCommission(self, instrument_id): return 0 class LiveBroker(broker.Broker): """A CTP live broker. .. note:: * Only limit orders are supported.
def onBars(self, bars): self.info("bla") logger.getLogger("custom").info("ble")
# limitations under the License. Created on Sun Dec 11 14:31:04 2016 """ import time import Queue from datetime import datetime from engine import broker from engine.logger import getLogger from engine.api.ctp import CTPTdApi from components.database.mongo import * from components.celery.tasks import * from components.celery.tasksmgmt import * logger = getLogger('CTP_broker') class FutureTraits(broker.InstrumentTraits): def roundQuantity(self, quantity): return round(quantity, 2) def getCommission(self, instrument_id): return 0 class LiveBroker(broker.Broker): """A CTP live broker. .. note:: * Only limit orders are supported. * Orders are automatically set as **goodTillCanceled=True** and **allOrNone=False**.