A simple HitBTC trade notification

in #bitcoin6 years ago (edited)

If you trade on HitBTC, you might find yourself yearning for a trade notification that lets you know whenever one of your orders has been filled.

Until now, the best option I had found was to set an alert in Coinigy for my order price. But then you have to constantly adjust the alert when you move your order. In the end, more often than not, I would just skip this and check the reports tab in HitBTC periodically. Not ideal.

If this sounds familiar, here are instructions for a simple HitBTC trade monitor I built today. This works on Mac, but probably needs some tweaking for Windows. Please share if you get it to work on Windows.

This is just a simple bash script you can run in Terminal. It pings the HitBTC API every 60 seconds – though you can easily change the frequency – and says 'new trade executed' (you could also have it say something more fun if you're so inclined) when it detects changes to your trade history, and also displays the last 3 trades.

Much could be improved, but I've found it to be a good start. Definitely beats setting manual price alerts in Coinigy for every order.

So, without further ado, here goes:


INSTRUCTIONS

  1. Set up an API key.
    https://hitbtc.com/settings/api-keys

    You only need an API key with the lowest permissions (Order book, History, Trading balance) for this to work, so there's virtually no risk of this falling in the wrong hands.

  2. Go to Swagger UI (a visual interface to the API hosted by HitBTC) https://api.hitbtc.com/api/2/explore/

  3. On the Swagger UI, click Authorize.
    Note: You'll need to use your public and private keys from the API key created above as user and password.

  4. Once you're authorized, scroll down to Trading History and expand the first item (/account/balance).

  5. Click Try it out on the right hand side and then Execute a little further down.

  6. Under Responses just below the Execute button, you'll see a Curl field. Copy its contents and insert below where it says so (replace everything between the quotes, including the curly brackets)

  7. Open any text editor, paste this, and save as e.g. hitbtc_monitor.sh:

#!/bin/bash

for (( ; ; )); do
    mv new.json old.json 2> /dev/null
    HTTP_CODE=`curl -X GET "{{ INSERT CONTENTS OF CURL FIELD HERE }}" -s \
      --write-out "%{http_code}" \
      --output temp-output.json`
    if [ "$HTTP_CODE" != "200" ]; then
        # catch errors
        cat temp-output.json
        echo
    else
        # code 200, write to new.json and compare to old.json
        mv temp-output.json new.json
        DIFF_OUTPUT="$(diff new.json old.json)"
        if [ "0" != "${#DIFF_OUTPUT}" ]; then
            # output has changed, new trade executed
            say new trade executed
            cat new.json | python -m json.tool
        else
            # output has not changed, no new trades
            echo "."
        fi
    fi
    sleep 60
done

.
To run this, open a Terminal window and run sh hitbtc_monitor.sh (from the directory where you saved this file).

Hope you enjoy!


Update: I have also built similar notifications for Binance (https://gist.github.com/fsboehme/89f5c239a3248df6443327b54f7f989b) and Cryptopia (https://gist.github.com/fsboehme/e71e83e741f51f36de6ee9aa91b5c414)

Sort:  

Congratulations @travelix! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 3 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

@travelix, I gave you an upvote on your post!

If you are interested in claiming free Byteballs ($10+), just for having a Steem account, please visit this post for instructions: https://steemit.com/steem/@berniesanders/do-you-want-some-free-byteballs

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62104.41
ETH 2404.22
USDT 1.00
SBD 2.49