Example #1
0
 def on_tick(self, tick: TickData) -> None:
     tick.datetime = str(tick.datetime)
     data = {
         "type": "tick",
         "data": tick._to_dict()
     }
     self.io.emit("tick", data)
Example #2
0
 def on_tick(self, tick: TickData) -> None:
     tick.datetime = str(tick.datetime)
     data = {"type": "tick", "data": tick._to_dict()}
     self.io.emit("tick", data)
     data = {
         "type": "position",
         "data": self.app.recorder.get_all_positions()
     }
     self.io.emit("position", data)
Example #3
0
    def on_tick(self, tick: TickData) -> None:
        self.local_status.setdefault(tick.local_symbol, False)
        self.global_bar.setdefault(tick.local_symbol, [])

        tick.datetime = str(tick.datetime)
        data = {"type": "tick", "data": tick._to_dict()}
        self.io.emit("tick", data)
        data = {
            "type": "position",
            "data": self.app.recorder.get_all_positions()
        }
        self.io.emit("position", data)
        if not self.local_status.get(tick.local_symbol):
            try:
                with open(
                        f"{os.path.dirname(__file__)}/static/json/{tick.symbol}.json",
                        "r") as f:
                    from json import load
                    st = True
                    try:
                        data = load(f)
                    except JSONDecodeError:
                        st = False
                    if data.get("data") is not None and st:
                        klines = data.get("data").get("lines")
                        assert type(klines) == list
                        if len(klines) != 0:
                            self.global_bar.get(
                                tick.local_symbol).extend(klines)
            except FileNotFoundError:
                pass
            self.local_status[tick.local_symbol] = True

        with open(
                f"{os.path.dirname(__file__)}/static/json/{tick.symbol}.json",
                "w") as f:
            from json import dump
            update_result = {
                "success": True,
                "data": {
                    "lines": self.global_bar.get(tick.local_symbol),
                    "depths": {
                        "asks": [[tick.ask_price_1, tick.ask_volume_1]],
                        "bids": [[tick.bid_price_1, tick.bid_volume_1]]
                    }
                }
            }
            f.truncate(0)
            dump(update_result, f)

        self.io.emit("update_all", update_result)