如何查看 Binance 加密货币的汇总清算?

How to view aggregated liquidations for cryptocurrencies from Binance?

在这些站点 (https://coinalyze.net/ethereum-classic/liquidations/, BTC/USDT) 上,我可以将以下指示添加到 grpah [LiquidationsLong LiquidationsShort LiquidationsAggregated Liquidations COIN-margined ContractsAggregated Liquidations STABLECOIN-margined Contracts].

Aggregated liquidations = liquidations of coin-margined contracts + liquidations of stablecoin-margined contracts converted to USD. For the moment only BTC/USD and BTC/USDT contracts are included. See the indicator options, you can select/deselect individual contracts.


=> 主要问题是如何从 Tradingview 或 Binance 等交易所获取加密货币清算数据流。

我已尝试将 Aggregated liquidations 或只是 Liquidations 添加到我的 https://www.tradingview.com 图表中,用于期货下的加密货币。我找不到它的 pine-script 代码或它的内置指标,所以我认为数据是私有的,对我来说是死胡同。

是否可以从 Binance 等交易所或其他交易所获取用于加密货币清算的数据流?或将 Aggregated liquidations 添加到 TradingView 的加密货币图表中?

简短的回答是否定的,这是不可能的,因为 Tradingview 不提供该级别的数据。像 coinalyze 这样的网站正在使用 Tradingview 插件并提供自己的清算数据流。

要在 Trandingview 平台本身上创建等效项,有一些解决方法,但不太理想。它不会是实时数据,您必须自己手动更新数据阵列。您还必须自己获取清算数据。

您必须记下第一个数据条目的时间戳,并将清算数据解析为一组逗号分隔值。

从那里您可以使用 array.from()

将其“导入”到脚本中
start_timestamp = timestamp(2021, 7, 9, 0, 0, 0)

var float[] a_longLiqs = array.from(17, 13458.4, 87453.56, 2345.23 , 23457.983, 353, .... etc)

var int index = na
var bool started = false
float longLiqs = na

if time == start_timestamp
    started := true
    index := 0
else if time > start_timestamp
    index += 1

if started and index < array.size(a_longLiqs)
    longLiqs := array.get(a_longLiqs, index)

plot(longLiqs)

至此,您已经有效地将数组转换为时间序列变量 longLiqs,您可以像使用任何其他变量一样使用它,例如 closevolume、等。但是,只有在手动将其添加到数组时才能获得新数据。

获取聚合数据本身就是一个过程。你必须利用交易所的 APIs.

例如: https://www.bitmex.com/api/explorer/#/Liquidation

https://bybit-exchange.github.io/docs/inverse/#t-query_liqrecords

在js和python上github上已有相当多的现有项目,我建议你从那里开始而不是重新发明轮子。例如,cryptofeed py 包可能是一个很好的起点,因为它似乎支持通过多个交易所提取清算数据。

https://pypi.org/project/cryptofeed/

https://github.com/bmoscon/cryptofeed/blob/master/docs/callbacks.md

获得数据后,您必须自己聚合并像我上面提到的那样解析它才能将其插入到 pine 数组中。

或者,如果您愿意为数据付费,则有付费数据提供商可能会更容易一些。您可能仍需要对其进行聚合和解析,但您只需处理一个 API 而不必从每个交换中管理它。

这是我发现的似乎提供汇总清算数据的数据:https://www.cryptometer.io/api-doc/

我从这里开始:

您必须安装以下软件包:pip install websocket-client websocket


#!/usr/bin/env python3

import websocket


class Liq:
    def __init__(self):
        self.socket = "wss://fstream.binance.com/ws/!forceOrder@arr"
        self.ws = websocket.WebSocketApp(self.socket, on_message=self.on_message, on_close=self.on_close)
        self.symbol: str = ""
        self.order_quantity = 0
        self.event_time: int = 0
        self.average_price: float = 0.0
        self.side = ""
        self.price: float = 0.0
        self.order_last_filled_quantity = 0.0
        self.order_filled_accumulated_quantity = 0
        self.order_trade_time = 0

    def print_result(self):
        amount = int(self.order_quantity * self.average_price)
        print(f"==> symbol={self.symbol}")
        print(f"==> side={self.side} | ", end="")
        if self.side == "BUY":
            print("shorts liquadated")
        else:
            print("longs liquadated")

        print(f"==> order_quantity={self.order_quantity}")
        print(f"==> event_time={self.event_time}")
        print(f"==> order_last_filled_quantity={self.order_last_filled_quantity}")
        print(f"==> order_filled_accumulated_quantity={self.order_filled_accumulated_quantity}")
        print(f"==> order_trade_time={self.order_trade_time}")
        print(f"==> price={self.price}")
        print(f"==> average_price={self.average_price}")
        print(f"==> liq_amount={amount}")
        print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")

    def on_message(self, ws, message):
        """Fetch liquidation Order Streams.

        __ https://binance-docs.github.io/apidocs/futures/en/#liquidation-order-streams
        """
        for item in message.split(","):
            item = item.replace("}", "").replace("{", "").replace('"', "").replace("o:s:", "s:")
            if "forceOrder" not in item:
                _item = item.split(":")
                if _item[0] == "E":
                    self.event_time = int(_item[1])
                elif _item[0] == "s":
                    self.symbol = _item[1]
                elif _item[0] == "S":
                    self.side = _item[1]
                elif _item[0] == "q":
                    self.order_quantity = float(_item[1])
                elif _item[0] == "p":
                    self.price = _item[1]
                elif _item[0] == "ap":
                    self.average_price = float(_item[1])
                elif _item[0] == "l":
                    self.order_last_filled_quantity = _item[1]
                elif _item[0] == "z":
                    self.order_filled_accumulated_quantity = _item[1]
                elif _item[0] == "T":
                    self.order_trade_time = _item[1]

        self.print_result()


    def on_close(self):
        print("closed")


liq = Liq()
liq.ws.run_forever()

示例输出,将打印所有液化对:

==> symbol=KEEPUSDT
==> side=SELL | longs liquadated
==> order_quantity=4705.0
==> event_time=1634474643639
==> order_last_filled_quantity=278
==> order_filled_accumulated_quantity=4705
==> order_trade_time=1634474643630
==> price=0.9877
==> average_price=1.0
==> liq_amount=4705
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
==> symbol=FTMUSDT
==> side=BUY | shorts liquadated
==> order_quantity=1458.0
==> event_time=1634474896201
==> order_last_filled_quantity=1240
==> order_filled_accumulated_quantity=1458
==> order_trade_time=1634474896197
==> price=2.257972
==> average_price=2.236581
==> liq_amount=3260

之后您可以将此结果存储在数据库中,例如 mongadb