Beispiel #1
0
    def get_minute(self, symbol, timestamp, format='npy'):
        """Get daily minutes history.

        Arguments:
        symbol: String of security.
        timestamp: Which day data to get.
        format: npy or json
        """
        try:
            ts = int(timestamp)
            if ts > 0:
                store = self.dbm.get_minutestore_at(ts)
            else:
                store = self.dbm.minutestore
                
            y = store.get(symbol)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del(y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #2
0
    def get_day(self, symbol, length_or_date, format='npy'):
        """Get OHLCs quotes.

        Return chronicle ordered quotes.
        """
        try:
            if len(length_or_date) == 8:  # eg: 20101209
                date = datetime.datetime.strptime(length_or_date,
                                                  '%Y%m%d').date()
                y = self.dbm.daystore.get_by_date(symbol, date)
            else:
                length = length_or_date
                y = self.dbm.daystore.get(symbol, int(length))
                if length == 1:
                    y = y[0]

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del (y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #3
0
    def get_minute(self, symbol, timestamp, format='npy'):
        """Get daily minutes history.

        Arguments:
        symbol: String of security.
        timestamp: Which day data to get.
        format: npy or json
        """
        try:
            ts = int(timestamp)
            if ts > 0:
                store = self.dbm.get_minutestore_at(ts)
            else:
                store = self.dbm.minutestore

            y = store.get(symbol)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del (y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #4
0
    def get_day(self, symbol, length_or_date, format='npy'):
        """Get OHLCs quotes.

        Return chronicle ordered quotes.
        """
        try:
            if len(length_or_date) == 8: # eg: 20101209
                date = datetime.datetime.strptime(length_or_date, '%Y%m%d').date()
                y = self.dbm.daystore.get_by_date(symbol, date)
            else:
                length = length_or_date
                y = self.dbm.daystore.get(symbol, int(length))
                if length == 1:
                    y = y[0]

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del(y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #5
0
 def get_report(self, symbol, format):
     try:
         data = self.dbm.get_report(symbol)
         if format == 'json':
             data = json_encode(data)
         self._write_response(data)
     except KeyError:
         self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #6
0
 def get_sector(self, name, format='json'):
     try:
         data = self.dbm.sectorstore[name]
         if format == 'json':
             data = json_encode(data)
         self._write_response(data)
     except KeyError:
         self.request.write("-ERR Sector %s not exists.\r\n" % name)
Beispiel #7
0
 def get_sector(self, name, format='json'):
     try:
         data = self.dbm.sectorstore[name]
         if format == 'json':
             data = json_encode(data)
         self._write_response(data)
     except KeyError:
         self.request.write("-ERR Sector %s not exists.\r\n" % name)
Beispiel #8
0
 def get_report(self, symbol, format):
     try:
         data = self.dbm.get_report(symbol)
         if format == 'json':
             data = json_encode(data)
         self._write_response(data)
     except KeyError:
         self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #9
0
    def get_reports(self, *args):
        assert len(args) > 1
        format = args[-1]
        data = self.dbm.get_reports(*args[:-1])

        if format == 'json':
            data = json_encode(data)
            
        self._write_response(data)
Beispiel #10
0
    def get_reports(self, *args):
        assert len(args) > 1
        format = args[-1]
        data = self.dbm.get_reports(*args[:-1])

        if format == 'json':
            data = json_encode(data)

        self._write_response(data)
Beispiel #11
0
    def get_list(self, match=None, format='json'):
        assert format == 'json'

        if match != '':
            _re = re.compile('^(%s)' % match, re.I)
            ret = dict([(r, v) for r, v in self.dbm.reportstore.iteritems() \
                            if _re.search(r)])
        else:
            ret = self.dbm.reportstore.to_dict()

        return self._write_response(json_encode(ret))
Beispiel #12
0
    def get_list(self, match=None, format='json'):
        assert format == 'json'

        if match != '':
            _re = re.compile('^(%s)' % match, re.I)
            ret = dict([(r, v) for r, v in self.dbm.reportstore.iteritems() \
                            if _re.search(r)])
        else:
            ret = self.dbm.reportstore.to_dict()

        return self._write_response(json_encode(ret))
Beispiel #13
0
    def get_dividend(self, symbol, format='npy'):
        try:
            try:
                y = self.dbm.divstore.get(symbol)[:]
            except TypeError:
                y = np.zeros(0)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del(y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #14
0
    def get_dividend(self, symbol, format='npy'):
        try:
            try:
                y = self.dbm.divstore.get(symbol)[:]
            except TypeError:
                y = np.zeros(0)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del (y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR Symbol %s not exists.\r\n" % symbol)
Beispiel #15
0
    def get_5minute(self, symbol, date, format='npy'):
        """Get 5min historical quotes.

        Arguments:
          symbol: String of security.
          date: Which day data to get.
          format: npy or json
        """
        try:
            if isinstance(date, str):
                date = datetime.datetime.strptime(date, '%Y%m%d').date()

            y = self.dbm.fiveminstore.get(symbol, date)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del (y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR No data.\r\n")
Beispiel #16
0
    def get_5minute(self, symbol, date, format='npy'):
        """Get 5min historical quotes.

        Arguments:
          symbol: String of security.
          date: Which day data to get.
          format: npy or json
        """
        try:
            if isinstance(date, str):
                date = datetime.datetime.strptime(date, '%Y%m%d').date()

            y = self.dbm.fiveminstore.get(symbol, date)

            if format == 'npy':
                memfile = StringIO()
                np.save(memfile, y)
                data = memfile.getvalue()
                del(y)
            else:
                data = json_encode(y.tolist())
            self._write_response(data)
        except KeyError:
            self.request.write("-ERR No data.\r\n")
Beispiel #17
0
 def get_stats(self, name, format='json'):
     stats = self.request.connection.stats
     self._write_response(json_encode(stats))
Beispiel #18
0
 def get_stats(self, name, format='json'):
     stats = self.request.connection.stats
     self._write_response(json_encode(stats))