sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.97k stars 2.19k forks source link

[help] How can I fetch liquidation data of all the users in futures? #1060

Closed avatar-lavventura closed 2 years ago

avatar-lavventura commented 2 years ago

On these sites (https://coinalyze.net/ethereum-classic/liquidations/, BTC/USDT), I am able to add following indications into graph [Liquidations, Long Liquidations, Short Liquidations, Aggregated Liquidations COIN-margined Contracts, Aggregated Liquidations STABLECOIN-margined Contracts], which make me think that its possible to fetch liquidations of all the pairs in Binance/Futures.

=> Is it possible to obtain data for liquidations (all the users) in cryptocurrencies using python-binance?

I have tried following code, which returns empty list as []:


client = Client(api_key, api_secret)

class Fetch_liq:
    def _futures_coin_liquidation_orders(self, **params):
        """Get all liquidation orders

         __ https://binance-docs.github.io/apidocs/delivery/en/#user-39-s-force-orders-user_data
        """
        # return client._request_futures_api('get', 'forceOrders', signed=True, data=params)
        return client._request_futures_coin_api("get", "forceOrders", data=params, signed=True)

    def get_future_coin_liquidation_orders(self, symbol=None):
        return self._futures_coin_liquidation_orders(
            symbol=symbol,
            autoCloseType="LIQUIDATION",
            limit=100
        )

cf = Fetch_liq()
print(cf.get_future_coin_liquidation_orders(symbol="ETCUSD_PERP"))  # returns `[]`

Any help would be appreciated.

Related:

avatar-lavventura commented 2 years ago

Fetching from self.socket = "wss://fstream.binance.com/ws/!forceOrder@arr" solved my issue.

#!/usr/bin/env python3

import websocket

def on_message(ws, msg):
    print(msg)

def on_close():
    print("closed")

socket = "wss://fstream.binance.com/ws/!forceOrder@arr"
ws = websocket.WebSocketApp(socket, on_message=on_message, on_close=on_close)
ws.run_forever()
Fabio007 commented 2 years ago

Hi there, I was looking at your code and see that this only returns real-time liquidations. Do you also know if historical data can be retrieved? Can't find it anywhere. Thanks!

QuantFlows commented 1 year ago

Hi ! Have you found a way to get that data ? Thanks for your help

StephanAkkerman commented 3 months ago

@Fabio007 @QuantFlows

Hi there, I was looking at your code and see that this only returns real-time liquidations. Do you also know if historical data can be retrieved? Can't find it anywhere. Thanks!

It took some time for me to find a source, but I discovered that Binance keeps track of this historical data and can easily be accessed on https://data.binance.vision/. Here you can see the historical liquidation data, for instance for USD-M BTC-USD perp is this URL: https://data.binance.vision/?prefix=data/futures/cm/daily/liquidationSnapshot/BTCUSD_PERP/. You can also find other useful historical data on that website.

I also found this repo https://github.com/aoki-h-jp/binance-bulk-downloader that implemented a downloader for it.

QuantFlows commented 3 months ago

@Fabio007 @QuantFlows

Hi there, I was looking at your code and see that this only returns real-time liquidations. Do you also know if historical data can be retrieved? Can't find it anywhere. Thanks!

It took some time for me to find a source, but I discovered that Binance keeps track of this historical data and can easily be accessed on https://data.binance.vision/. Here you can see the historical liquidation data, for instance for USD-M BTC-USD perp is this URL: https://data.binance.vision/?prefix=data/futures/cm/daily/liquidationSnapshot/BTCUSD_PERP/. You can also find other useful historical data on that website.

I also found this repo https://github.com/aoki-h-jp/binance-bulk-downloader that implemented a downloader for it.

Thanks