If automation through an application isn’t your speed. You can always leverage exchange APIs to collect information about your asset balances, detect when those balances change, and automate the process of executing trades on the exchange to sell your mined asset.

Shrimpy provides the most robust set of developer APIs. These APIs can simplify the way you automatically check your exchange account and execute trades to buy and sell the assets you want.

The following Python scripts will provide a detailed example of how you can automate this process.

Install Trading Library

Since each crypto exchange is unique in the way they have developed their APIs, integrating with every exchange has become a nightmare situation for many developers.

To simplify the way we interact with exchanges, the following scripts will use the Shrimpy Trading Library. That way we can focus less time on how to manage each of these exchange connections and more time on developing our scripts.

Get started by installing Shrimpy for Python.

pip install shrimpy-python

API Keys

Before we can connect to any exchanges, we will need access to both our Exchange API Keys and our Shrimpy Master API Keys.

Exchange API Keys

Retrieve your exchange API keys by logging into your exchange account and following the necessary steps to create a new set of API keys.

How to Get Exchange API Keys

Since the scripts we are writing will actually trade on your account, make sure you enable the API permissions for both reading data from your account as well as executing trades. Do NOT enable withdrawal permissions.

Securely store the keys you generate. They will be needed in the following scripts. The place where you will include your exchange API keys will look something like the following section in the code.

exchange_name = 'bittrex' exchange_public_key = 'fbnnn1xzimjustkeyboardmashing8xn1t8' exchange_secret_key = '09672v4n09xn0morekeyboardmashing947'

Note: Shrimpy supports these exchanges: binance, binanceus, bittrex, bittrexinternational, kucoin, poloniex, bibox, hitbtc, bitstamp, bitfinex, coinbasepro, kraken, gemini, huobiglobal, bitmart, and okex.

Shrimpy Master Keys

Since we will manage all of our exchange connections through Shrimpy, we must now create our Shrimpy Master API Keys. These keys will maintain the connections to all of our exchanges, authorize trading, and collect account data from each exchange.

Start by signing up for the Shrimpy developer APIs.

Once you sign up, select the button to “Create Api Master Key”. During the process of creating your Shrimpy Master API Keys, make sure you have enabled all of the permissions for “User”, “Account”, “Trading”, and “Data”. Without the first 3 permissions, we won’t be able to connect to exchanges and trade. The last permission is used when we collect websocket or historical data from the exchange (It will not be necessary for this tutorial, but you may wish to use it in the future).

Save your keys to a secure location. In the following scripts, you will input your keys into the script at places that look like this in the code.

shrimpy_public_key = '8x7138n1xzimjustkeyboardmashing8xn1t8jv5098' shrimpy_secret_key = '771dc5n72v4n09xn0morekeyboardmashing9475c0294n50'

Note: The Shrimpy Developer APIs cost $19/mo for the personal plan. This will allow you to connect up to 20 exchange accounts.

Setting up your Shrimpy account

Before we can start gathering data from our exchange accounts and trade, we must first set up our Shrimpy account. This will include some of the steps that we previously discussed in the sections above.

Once you run this script, make sure to store your user_id and account_id for later use.

# import required libraries import shrimpy # assign your Shrimpy Master API keys for later use shrimpy_public_key = '8x7138n1xzimjustkeyboardmashing8xn1t8jv5098' shrimpy_secret_key = '771dc5n72v4n09xn0morekeyboardmashing9475c0294n50' # assign your exchange keys for which you wish to access the balance data exchange_name = "bittrex" exchange_public_key = 'fbnnn1xzimjustkeyboardmashing8xn1t8' exchange_secret_key = '09672v4n09xn0morekeyboardmashing947' # create the Shrimpy client client = shrimpy.ShrimpyApiClient(shrimpy_public_key, shrimpy_secret_key) # create a user which will be linked to our exchange create_user_response = client.create_user('The Shrimp Master') user_id = create_user_response['id'] # link our first exchange so we can access balance data link_account_response = client.link_account( user_id, exchange_name, exchange_public_key, exchange_secret_key ) account_id = link_account_response['id'] # copy and save these values print(user_id) print(account_id)

Automating your selling strategy

The next script will continuously run, check your account information, and trade when we find that some new assets have been deposited into your account.

Everything in your account will automatically be sold to the asset marked as “consolidation_symbol”.

Notice: In this script, we use the user_id and account_id that should have been stored from the previous step.

Warning! Running this script will literally sell everything you own into the asset selected as the “consolidation_symbol”. If you don’t want this to happen DO NOT RUN THIS SCRIPT. We are not responsible for the use, abuse, or misuse of this script.

# import required libraries import shrimpy import time # input your user and account IDs user_id = 'dc12349b-1234-12k4-123n12n12nnf' account_id = 12345 # assign your Shrimpy Master API keys for later use shrimpy_public_key = '8x7138n1xzimjustkeyboardmashing8xn1t8jv5098' shrimpy_secret_key = '771dc5n72v4n09xn0morekeyboardmashing9475c0294n50' # create the Shrimpy client client = shrimpy.ShrimpyApiClient(shrimpy_public_key, shrimpy_secret_key) While True: # collect asset balances on the exchange balance = client.get_balance(user_id, account_id) holdings = balance['balances'] # select the asset for which you would like to consolidate consolidation_symbol = 'BTC' # sell every asset besides the consolidation asset for asset in holdings: asset_symbol = asset['symbol'] asset_amount = asset['nativeValue'] if asset_symbol != consolidation_symbol: print('Selling ' + str(asset_amount) + ' of ' + asset_symbol) create_trade_response = client.create_trade( user_id, account_id, asset_symbol, consolidation_symbol, asset_amount ) # check every 15 minutes time.sleep(900)

That’s it! You are now automating your mining operation to automatically sell your rewards. Experiment with the APIs and develop new scripts to help further automate your portfolio.

Additional Reading

A Comparison Of Rebalancing Strategies for Crypto Portfolios

Cryptocurrency Trading Bots - The Complete Guide

How to Make a Crypto Trading Bot Using Python

Script for Bitcoin Price Live Ticker (Using Websockets)

How to Calculate Your Crypto Portfolio Performance

Our Trading Bot

Shrimpy is an application for constructing custom cryptocurrency index funds, rebalancing, and managing a diverse portfolio of digital assets. Automate your portfolio by linking to any of the 16 crypto exchanges we support.

Shrimpy’s Universal Crypto Exchange APIs are designed for developers. Integrating with our unified APIs gives you instant access to uniform endpoints for trading, data collection, user management, and more across every major cryptocurrency exchange.

To access the complete Python and Node libraries, follow these links:

Node

Python

If you’re building something with the Shrimpy APIs, let us know! We would love to hear how we can continue to support you at every stage of your development.