Пример #1
0
    def event(self, ts, pair, bid, ask):

        # Store the event in the dumpfile.
        if self.dumpfile is not None:
            ntime = sec2milli(time())
            msg = self.encode(ntime, ts, VENUE, pair.pair, bid, ask)
            self.dumpfile.write(msg)

        # Notify the listeners.
        self.factory.notify_subscribers(ts, VENUE, pair.pair, bid, ask)
Пример #2
0
    def event(self, ts, pair, bid, ask):

        # Store the event in the dumpfile.
        if self.dumpfile is not None:
            ntime = sec2milli(time())
            msg = self.encode(ntime, ts, VENUE, pair.pair, bid, ask)
            self.dumpfile.write(msg)

        # Notify the listeners.
        self.factory.notify_subscribers(ts, VENUE, pair.pair, bid, ask)
Пример #3
0
    def handle(self, ei, _):
        """ Convert the data and dispatch it to the clients. """
        tick = ei.tick
        bid, ask = f2i(tick.bid), f2i(tick.ask)
        ts = sec2milli(tick.timestamp)

        # Reschedule kill call for a later time.
        if self.killsecs:
            if self.d is not None:
                self.d.cancel()
            self.d = reactor.callLater(self.killsecs, self.on_idle)

        self.dispatch.event(ts, ei.pair, bid, ask)
Пример #4
0
    def handle(self, ei, _):
        """ Convert the data and dispatch it to the clients. """
        tick = ei.tick
        bid, ask = f2i(tick.bid), f2i(tick.ask)
        ts = sec2milli(tick.timestamp)

        # Reschedule kill call for a later time.
        if self.killsecs:
            if self.d is not None:
                self.d.cancel()
            self.d = reactor.callLater(self.killsecs, self.on_idle)

        self.dispatch.event(ts, ei.pair, bid, ask)
Пример #5
0
    def gen(self):
        spair = str(self.pair)
        xrates = self.factory.xrates

        ts = sec2milli(time())
        if spair in xrates:
            (_, bid, ask) = xrates[spair]
        else:
            bid, ask = f2i(self.init_bid), f2i(self.init_ask)

        delta = f2i(self.mininc) * randint(-2, +2)
        bid += delta
        ask += delta

        self.m.dispatch.event(ts, self.pair, bid, ask)

        if not self.stopping:
            reactor.callLater(random() * self.tdelay, self.gen)
Пример #6
0
    def gen(self):
        spair = str(self.pair)
        xrates = self.factory.xrates

        ts = sec2milli(time())
        if spair in xrates:
            (_, bid, ask) = xrates[spair]
        else:
            bid, ask = f2i(self.init_bid), f2i(self.init_ask)

        delta = f2i(self.mininc) * randint(-2, +2)
        bid += delta
        ask += delta

        self.m.dispatch.event(ts, self.pair, bid, ask)

        if not self.stopping:
            reactor.callLater(random() * self.tdelay, self.gen)
Пример #7
0
    def getrate(self, inst):
        logging.info('getrate %s' % inst)
        spair = normalize_pair(inst)
        xrates = self.factory.xrates

        venue = 'O'  # FIXME: hard-coded to OANDA for now.
        if spair in xrates:
            ts, bid, ask = xrates[spair]
        elif spair:
            if self.fxclient is not None:
                # We're online, initialize and send from the live rate.
                rtable = self.fxclient.getRateTable()
                tick = rtable.getRate(Pair(spair))
                (ts, bid, ask) = xrates[spair] = (sec2milli(tick.timestamp),
                                                  f2i(tick.bid), f2i(tick.ask))
            else:
                # We're offline, send 0 rate.
                self.rate(0, spair, 0, 0)
                return
        else:
            self.error("Invalid instrument %s." % repr(inst))
            return
        self.rate(ts, spair, bid, ask)
Пример #8
0
    def getrate(self, inst):
        logging.info('getrate %s' % inst)
        spair = normalize_pair(inst)
        xrates = self.factory.xrates

        venue = 'O' # FIXME: hard-coded to OANDA for now.
        if spair in xrates:
            ts, bid, ask = xrates[spair]
        elif spair:
            if self.fxclient is not None:
                # We're online, initialize and send from the live rate.
                rtable = self.fxclient.getRateTable()
                tick = rtable.getRate(Pair(spair))
                (ts, bid, ask) = xrates[spair] = (sec2milli(tick.timestamp),
                                                f2i(tick.bid),
                                                f2i(tick.ask))
            else:
                # We're offline, send 0 rate.
                self.rate(0, spair, 0, 0)
                return
        else:
            self.error("Invalid instrument %s." % repr(inst))
            return
        self.rate(ts, spair, bid, ask)