Example #1
0
    def init_tasks(self):
        loop = asyncio.get_event_loop()
        # init task_exchanges
        task_exchanges = TaskExchanges(self.exchange_data,
                                       self.config["magicwalletkey"])
        task_exchanges.set_period(int(self.config["timer_minute"]) * 60)

        # init task_pusher
        if self.config["pusher"]["enable"]:
            topic = "bts.exchanges"
            login_info = None
            if self.config["pusher"]["user"]:
                login_info = self.config["pusher"]
            task_pusher = TaskPusher(self.exchange_data)
            task_pusher.topic = topic
            task_pusher.set_expired(self.config["timer_minute"] * 60 + 30)
            if "publish" in self.config["pusher"]:

                def publish_data(_type, _name, _data):
                    # print("publish: %s %s" % (_type, _name))
                    task_pusher.pusher.publish(topic, _type, _name, _data)

                task_exchanges.handler = publish_data
            task_pusher.run_tasks(loop, login_info)

        task_exchanges.run_tasks(loop)
Example #2
0
    def init_tasks(self):
        loop = asyncio.get_event_loop()
        # init task_exchanges
        task_exchanges = TaskExchanges(self.exchange_data)
        task_exchanges.set_period(int(self.config["timer_minute"])*60)

        # init task_pusher
        if self.config["pusher"]["enable"]:
            topic = "bts.exchanges"
            login_info = None
            if self.config["pusher"]["user"]:
                login_info = self.config["pusher"]
            task_pusher = TaskPusher(self.exchange_data)
            task_pusher.topic = topic
            task_pusher.set_expired(self.config["timer_minute"]*60+30)
            if "publish" in self.config["pusher"]:
                def publish_data(_type, _name, _data):
                    # print("publish: %s %s" % (_type, _name))
                    task_pusher.pusher.publish(topic, _type, _name, _data)
                task_exchanges.handler = publish_data
            task_pusher.run_tasks(loop, login_info)

        task_exchanges.run_tasks(loop)
Example #3
0
        self.pusher = Pusher(loop, login_info)
        self.pusher.sync_subscribe(onData, self.topic)

    def set_expired(self, sec):
        self.expired = sec


if __name__ == "__main__":
    exchange_data = {}
    task_pusher = TaskPusher(exchange_data)
    topic = "public.exchanges"

    def publish_data(_type, _name, _data):
        print("publish: %s %s" % (_type, _name))
        task_pusher.pusher.publish(topic, _type, _name, _data)

    from btsprice.task_exchanges import TaskExchanges
    task_exchanges = TaskExchanges(exchange_data)
    task_exchanges.handler = publish_data
    task_exchanges.set_period(20)

    loop = asyncio.get_event_loop()

    task_pusher.topic = topic
    task_pusher.run_tasks(loop)
    task_exchanges.run_tasks(loop)

    loop.run_forever()
    loop.close()
Example #4
0
                if order[0] > ask_price:
                    break
                # valid_depth[market]["ask_price"] = \
                #     order[0] * self.rate_cny[quote]
                valid_depth[market]["ask_volume"] += order[1]
        return valid_depth

    def get_magic_rate(self):
        return self.data["magic"]["Magicwallet"]


if __name__ == "__main__":
    import asyncio
    from btsprice.task_exchanges import TaskExchanges
    exchange_data = {}
    task_exchanges = TaskExchanges(exchange_data)
    task_exchanges.set_period(20)
    loop = asyncio.get_event_loop()
    task_exchanges.run_tasks(loop)

    bts_price = BTSPriceAfterMatch(exchange_data)

    @asyncio.coroutine
    def task_compute_price():
        yield from asyncio.sleep(1)
        while True:
            volume, volume_sum, real_price = bts_price.compute_price(
                spread=0.01)
            if real_price:
                valid_depth = bts_price.get_valid_depth(price=real_price,
                                                        spread=0.01)
Example #5
0
        self.pusher = Pusher(loop, login_info)
        self.pusher.sync_subscribe(onData, self.topic)

    def set_expired(self, sec):
        self.expired = sec


if __name__ == "__main__":
    exchange_data = {}
    task_pusher = TaskPusher(exchange_data)
    topic = "public.exchanges"

    def publish_data(_type, _name, _data):
        print("publish: %s %s" % (_type, _name))
        task_pusher.pusher.publish(topic, _type, _name, _data)

    from btsprice.task_exchanges import TaskExchanges

    task_exchanges = TaskExchanges(exchange_data)
    task_exchanges.handler = publish_data
    task_exchanges.set_period(20)

    loop = asyncio.get_event_loop()

    task_pusher.topic = topic
    task_pusher.run_tasks(loop)
    task_exchanges.run_tasks(loop)

    loop.run_forever()
    loop.close()
                # valid_depth[market]["bid_price"] = \
                #     order[0] * self.rate_cny[quote]
                valid_depth[market]["bid_volume"] += order[1]
            for order in sorted(self.orderbook[market]["asks"]):
                if order[0] > ask_price:
                    break
                # valid_depth[market]["ask_price"] = \
                #     order[0] * self.rate_cny[quote]
                valid_depth[market]["ask_volume"] += order[1]
        return valid_depth

if __name__ == "__main__":
    import asyncio
    from btsprice.task_exchanges import TaskExchanges
    exchange_data = {}
    task_exchanges = TaskExchanges(exchange_data)
    task_exchanges.set_period(20)
    loop = asyncio.get_event_loop()
    task_exchanges.run_tasks(loop)

    bts_price = BTSPriceAfterMatch(exchange_data)

    @asyncio.coroutine
    def task_compute_price():
        yield from asyncio.sleep(1)
        while True:
            volume, volume_sum, real_price = bts_price.compute_price(
                spread=0.01)
            if real_price:
                valid_depth = bts_price.get_valid_depth(
                    price=real_price,