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

alp*_*per 7 web-crawler tradingview-api pine-script binance

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

合计清算量=币本位合约清算量+稳定币本位合约折算美元的清算量。目前仅包含 BTC/USD 和 BTC/USDT 合约。查看指标选项,您可以选择/取消选择单个合约。


=> 主要问题是如何获取用于加密货币清算的数据流(如果可能的话)从 Tradingview 或币安等交易所获取。

我尝试在https://www.tradingview.comAggregated liquidations上添加或直接Liquidations添加到期货下的加密货币图表中。我无法找到它的 pine-script 代码或其内置指示器,所以我相信数据是私有的,对我来说是死胡同。

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

rum*_*mpy 7

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

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

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

从那里您可以使用以下命令将其“导入”到脚本中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)
Run Code Online (Sandbox Code Playgroud)

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

获取聚合数据本身就是一个过程。您必须使用交易所的 API。

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

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

github 上已有相当多的 js 和 python 项目,我建议你从那里开始,而不是重新发明轮子。例如,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/


alp*_*per 4

我从这里开始:

您必须安装以下软件包: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()
Run Code Online (Sandbox Code Playgroud)

输出示例,将打印所有平仓对:

==> 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
Run Code Online (Sandbox Code Playgroud)

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