示例#1
0
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()
示例#2
0
    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)
示例#3
0
    def __init__(self, cash, barFeed, commission=None):
        super().__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
示例#4
0
 def onBars(self, bars):
     self.info("bla")
     logger.getLogger("custom").info("ble")
示例#5
0
def getLiveLogger(name):
    log = logger.getLogger(name)
    initLogger(log)
    return log
示例#6
0
#
# Modified from MooQuant okex and Xignite modules
"""
.. moduleauthor:: Mikko Gozalo <*****@*****.**>
"""

import datetime
import queue
import threading
import time

from mooquant import bar, barfeed, dataseries, logger, observer
from mooquant.utils import dt
from mooquant_okex import api

logger = logger.getLogger("okex")


def utcnow():
    return dt.as_utc(datetime.datetime.utcnow())


class TradeBar(bar.Bar):
    __slots__ = ('__dateTime', '__tradeId', '__price', '__amount', '__type')

    last_datetime = None

    def __init__(self, bardict):
        trade_dt = datetime.datetime.fromtimestamp(bardict['timestamp'])
        if TradeBar.last_datetime is not None:
            if trade_dt <= TradeBar.last_datetime:
示例#7
0
# -*- coding: utf-8 -*-

import datetime
import queue
import threading
import time

from mooquant_mercadobitcoin import api
from mooquant import bar, barfeed, dataseries, logger, observer
from mooquant.utils import dt

logger = logger.getLogger("mercadobitcoin")


def utcnow():
    return dt.as_utc(datetime.datetime.utcnow())


class TradeBar(bar.Bar):
    __slots__ = ('__dateTime', '__tradeId', '__price', '__amount', '__type')

    last_datetime = None

    def __init__(self, bardict):
        trade_dt = datetime.datetime.fromtimestamp(bardict['date'])
        if TradeBar.last_datetime is not None:
            if trade_dt <= TradeBar.last_datetime:
                trade_dt = (TradeBar.last_datetime +
                            datetime.timedelta(seconds=0.01))

        TradeBar.last_datetime = trade_dt