Example #1
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)
Example #2
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)
Example #3
0
 def unsubscribe(self, inst):
     logging.info('unsubscribe %s' % inst)
     try:
         self.factory.subscribers[normalize_pair(inst)].remove(self)
     except KeyError:
         logging.warning("Instrument %s not subscribed." % inst)
Example #4
0
 def subscribe(self, inst):
     logging.info('subscribe %s' % inst)
     self.factory.subscribers[normalize_pair(inst)].add(self)
Example #5
0
 def on_newinst(self, key):
     if key not in self.generators:
         self.generators[key] = rangen = RandomEventGenerator(self, Pair(normalize_pair(key)))
         rangen.start()
Example #6
0
 def unsubscribe(self, inst):
     logging.info('unsubscribe %s' % inst)
     try:
         self.factory.subscribers[normalize_pair(inst)].remove(self)
     except KeyError:
         logging.warning("Instrument %s not subscribed." % inst)
Example #7
0
 def subscribe(self, inst):
     logging.info('subscribe %s' % inst)
     self.factory.subscribers[normalize_pair(inst)].add(self)
Example #8
0
 def on_newinst(self, key):
     if key not in self.generators:
         self.generators[key] = rangen = (RandomEventGenerator(
             self, Pair(normalize_pair(key))))
         rangen.start()