Ejemplo n.º 1
0
    def on_event(self, event_item):
        self.logger.debug(event_item)
        if not self.last_date or not is_same_date(self.last_date,
                                                  self.current_time):
            self.last_date = to_timestamp(
                event_item['timestamp']) - timedelta(days=1)
            self.last_kdata = get_kdata(self.security_item,
                                        the_date=to_time_str(self.last_date))

            if self.last_kdata is None:
                fetch_kdata(exchange_str=self.security_item['exchange'])
                self.last_kdata = get_kdata(self.security_item,
                                            the_date=to_time_str(
                                                self.last_date))

            if self.last_kdata is not None:
                self.last_close = self.last_kdata.loc[
                    to_time_str(self.last_date), 'close']
            else:
                self.logger.exception("could not get last close for:{}".format(
                    self.last_date))

            self.update_today_triggered()

        change_pct = (event_item['price'] - self.last_close) / self.last_close

        self.logger.info(
            "{} last day close is:{},now price is:{},the change_pct is:{}".
            format(self.security_item['id'], self.last_close,
                   event_item['price'], change_pct))
        self.check_subscription(current_price=event_item['price'],
                                change_pct=change_pct)
Ejemplo n.º 2
0
def scheduled_job2():
    for item in CRYPTOCURRENCY_EXCHANGES:
        fetch_kdata(item)
Ejemplo n.º 3
0
from fooltrader.datasource.ccxt_wrapper import init_markets, fetch_kdata
from fooltrader.utils.utils import init_process_log

init_process_log('crawling_cryptocurrency_data.log')

logger = logging.getLogger(__name__)

sched = BackgroundScheduler()


@sched.scheduled_job('cron', hour=00, minute=00)
def scheduled_job1():
    init_markets()


@sched.scheduled_job('cron', hour=00, minute=30)
def scheduled_job2():
    for item in CRYPTOCURRENCY_EXCHANGES:
        fetch_kdata(item)


if __name__ == '__main__':
    init_markets()
    for item in CRYPTOCURRENCY_EXCHANGES:
        fetch_kdata(item)

    sched.start()

    logger.info("I would crawl cryptocurrency at 00:00")
    sched._thread.join()