예제 #1
0
    def record(self, entity, start, end, size, timestamps):
        the_url = self.url.format("{}".format(entity.code),
                                  level_flag(self.level), size,
                                  now_time_str(fmt=TIME_FORMAT_DAY1))

        resp = requests.get(the_url)
        results = json_callback_param(resp.text)

        kdatas = []

        if results:
            klines = results['data']['klines']

            # TODO: ignore the last unfinished kdata now,could control it better if need
            for result in klines[:-1]:
                # "2000-01-28,1005.26,1012.56,1173.12,982.13,3023326,3075552000.00"
                # time,open,close,high,low,volume,turnover
                fields = result.split(',')
                the_timestamp = to_pd_timestamp(fields[0])

                the_id = generate_kdata_id(entity_id=entity.id,
                                           timestamp=the_timestamp,
                                           level=self.level)

                kdatas.append(
                    dict(id=the_id,
                         timestamp=the_timestamp,
                         entity_id=entity.id,
                         code=entity.code,
                         name=entity.name,
                         level=self.level.value,
                         open=to_float(fields[1]),
                         close=to_float(fields[2]),
                         high=to_float(fields[3]),
                         low=to_float(fields[4]),
                         volume=to_float(fields[5]),
                         turnover=to_float(fields[6])))
        return kdatas
예제 #2
0
 def generate_domain_id(self, entity, original_data):
     return generate_kdata_id(entity_id=entity.id,
                              timestamp=original_data['timestamp'],
                              level=self.level)