Git Product home page Git Product logo

bitmex-liquidations's Introduction

BitMEX Liquidation

Minimal code to show how to receive the liquidations in realtime on Bitmex. It does work and does not hang randomly.

NOTE: From my experience, even though the feed is realtime according to Bitmex, by the time you receive the liquidation messages, they already happened a few seconds earlier. So it would be hard to profit from it directly. But it could use as a data feature.

Installation

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt

Run

python example.py               # All instruments.
python example.py XBTUSD        # Only XBTUSD.

And be patient! You might have to wait more than one hour to see your first liquidation.

Browse this link for more information: https://app.rek.to/.

Output

2019-11-10 16:33:11,486 - Connecting to wss://www.bitmex.com/realtime?subscribe=liquidation.
2019-11-10 16:33:11,486 - Connected to WS.
2019-11-10 16:33:12,478 - Websocket Opened.
2019-11-10 16:33:12,479 - [<] Welcome to the BitMEX Realtime API.
2019-11-10 16:33:12,479 - [<] Subscribed to liquidation.
2019-11-10 16:33:16,493 - Symbol    B/S   USD Value   Quantity  @   Price     Time
2019-11-10 17:02:34,396 - EOSZ19    Buy   0           600       @   0.0004007 2019-11-10 17:02:34.396
2019-11-10 17:30:08,324 - XBTUSD    Sell  68,000      68,000    @   8829.5    2019-11-10 17:30:08.324
2019-11-10 17:30:14,103 - XBTUSD    Sell  807         807       @   8827.0    2019-11-10 17:30:14.103
2019-11-10 18:44:40,254 - XBTUSD    Sell  1,013       1,013     @   8818.5    2019-11-10 18:44:40.254

Messages

This message corresponds to the first line of the banner:

{ 
   "table":"liquidation",
   "action":"insert",
   "data":[ 
      { 
         "orderID":"8b4a95db-815a-f93a-c9a2-ffbbabeddbac",
         "symbol":"TRXZ19",
         "side":"Buy",
         "price":2.17e-06,
         "leavesQty":5000
      }
   ]
}

bitmex-liquidations's People

Contributors

philipperemy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bitmex-liquidations's Issues

How do you fetch USD Values

Hello,

Thank you for sharing your liquidation bot.

I was wondering, how are you able to convert a contract size value to USD, aside from XBT?

I have seen, that you used:

usd_value = price * qty if not symbol.startswith('XBT') else qty

But I think that is not all. Since if I cross check that formula with your website's values they are all different.

Looking at for example ETHUSD each contract is worth 0.001 mXBT per $1 price, currently 0.00121444 XBT. A simple price * qty should not be enough.

Another not clear example would be:
img

If I do price * qty it would result in 63 and not 2, as shown in the screenshot. I might be missing something here, thats why I thought to shoot you a message.

Aside from that I have also noticed that the usd_value is different from the GitHub's version vs the rek.to.

GitHub Bot:
img

Website:
img

GH Bot has USD = 1,935. Website = 68.

When looking at bitmex.com the order value of 7,000 XRP is also a complete different one:

img

Thanks for enlighten me on this.

Web socket disconnecting after 2 days, can we run only example.py --symbol for production

I ran the example.py XBTUSD and see that the script stopped running after two days.

Error message:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_app.py", line 278, in run_forever
    dispatcher.read(self.sock.sock, read)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_app.py", line 63, in read
    callback()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_app.py", line 251, in read
    op_code, frame = self.sock.recv_data_frame(True)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_core.py", line 330, in recv_data_frame
    frame = self.recv_frame()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_core.py", line 364, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_core.py", line 434, in _recv
    return recv(self.sock, bufsize)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_socket.py", line 94, in recv
    "Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/logging/__init__.py", line 994, in emit
    msg = self.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 840, in format
    return fmt.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 577, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/datahub/src/indicators/bitmex-liquidations/bitmex_liquidation/api.py", line 111, in <lambda>
    self.wst = threading.Thread(target=lambda: self.ws.run_forever(ping_interval=5),
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_app.py", line 280, in run_forever
    self._callback(self.on_error, e)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/websocket/_app.py", line 315, in _callback
    callback(self, *args)
  File "/home/ubuntu/datahub/src/indicators/bitmex-liquidations/bitmex_liquidation/api.py", line 147, in _on_error
    logger.info('on_error()', error)
Message: 'on_error()'
Arguments: (WebSocketConnectionClosedException('Connection is already closed.',),)
2020-04-14 23:05:13,037 - Websocket Closed

Getting past data

Do you know if there is a way of getting past liquidation data?
Like getting data from liquidation since 01/01/2020 to 18/01/2020

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.