示例#1
0
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: oanserver.py 项目: ndawe/oanpy
    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
文件: rateserv.py 项目: ndawe/oanpy
    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)