Coinbase new Listings Trading Bot source code [part 2] Buying from Bittrex.

My trading bot is too much hassle for me at the moment to maintain so I decided to release the source code with an explanation of what it does and how to use it. Another reason is that with time the Coinbase pump is not that strong and sometimes a coin instead of pumping it will dump, so I decided that it does not worth the risk of running it anymore. Lastly it seems like Coinbase for the time being is not doing any listings and I am not in the mood to have the Bot running for weeks without any listing. Having an instance running in AWS for months without getting any Coinbase listing is frustrating.

This bot is constantly fetching the Coingbase blog looking for new posts that include new coin listing in their titles and then buys them instantly on Bittrex. For example when Coinbase announces a new listing they title their Blog post something in the lines of:

ZEC trading on Coinbase Pro is about to begin. The ZEC/USDC order book will now enter Post-Only mode.

So we have previously defined a list of all currencies that we expect Coinbase to list in the future and we just keep fetching their website until one of them is listed. If multiple currencies are listed on Coinbase together as it happened in the past, the list defined mentioned above is ordered so the currency higher in the order will be bought in the end. For example if Stellar is higher in the listing than Ripple, it will be bought instead of Ripple.

Note that Coinbase Pro makes a new tweet every time they list a new coin, however their blog post announcement always comes first since their tweet includes a link to their blog post, so it makes sense to directly query the site instead of twitter, and believe me every millisecond counts.

The bot is written in Javascript has no GUI and runs as a Chrome browser extension. I have being running the bot in an AWS Ubuntu instance since they offer decent internet connection but the bot is platform agnostic. if you have Chrome you can run it. Every browser extension has a predefined structure in order to be able to get loaded into Chrome. The main logic of the extension follows below commented:

We define the Bittrex key and the Bittrex secret we have generated from Bittrex. You can generate one from your account settings and also make sure to enable trading for this key but disable account withdrawals as a safe practice. This is because the bot uses your Bittrex account to buy the coin once it is listed on Coinbase.

We also define how often we query Coinbase for new listings, the order book depth that we want to run the buy order and the amount of $BTC we are willing to sell. I explain below what is the depth of the order book and why it is important for Bittrex.

Last variable is the Coinbase URL we are querying. Note that we only query their initial page. What that means is that Coinbase blog supports infinite scrolling and the more we scroll down the more articles are fetched and shown. However we only fetch the “top” page since new coins are listed on their first page always, as it is important to get visibility. We do this via the URL that you see above. It returns the Coinbase blog in a JSON format we can easily filter for every post title.

That is the main loop of the application that is performing the function fetch coinbase every 460ms as we defined above. You can adjust this value according to your needs and your network.

All the function does is continuously fetching the latest Coinbase blog posts. As they are fetched in JSON format we can easily filter and take all the titles from the latest posts. We pack all the titles in a single line and convert it into uppercase and then we call the extract_currencies function which will check if there are any currencies mentioned in the titles.

Here is how the output looks like:

Here is the extract_currencies function which is pretty simple. It checks if the titles that were fetched before contain the word STELLAR or XLM. We do this for every available currency which is available to buy on Bittrex and is not yet listed on Coinbase. You see above if the blog title contains one of these two words the function get_bittrex_price_by_currency() is called and we also pass the trade_amount which is the amount of BTC that we want to sell in order to buy XLM. Let’s move to this function then.

We first make a query on Bittrex in order to get the latest market price. As you see we do not fetch the best available price but we get a bit lower in the orderbook as defined in the variable bittrex_order_depth. We do that because with Bittrex we cannot perform a market buy. We need to specifically define the price we are willing to pay.

Imagine a scenario where the latest BTCXLM price is 0.00003000. If we put this value in our order we have a chance that someone else’s bot is quicker than us to buy at 0.00003000 so all we have left is an open buy order that is not executed.

Since the price is rising tremendously in the second of the announcement we want to make sure that we will eventually get XLM, therefore we just buy the 40th order. I have done some experimenting and this is a good depth which can give us a 10% – 15 % return.

So once we have the price that we want to buy we call the function set_bittrex_order(currency,price,trade_amount) with the currency we want to buy and the amount of Bitcoin we are willing to pay for it.

This is the last part where we construct the signed request to Bittrex to execute our order. We need to include our Bittrex key and our Bittrex secret as defined by the Bittrex API and then perform an HTTP Get to the /marketbuy endpoint.

Once the bot places the order it then stops execution as it has fulfilled its goal.

You can download the Chrome Extension here. Make sure you add your Bittrex keys and secrets and you know exactly what you are doing. Make sure to add the coins you want to track and remove the ones that are already configured. If you mindlessly get the add on and start running it you will lose your money.

Leave a Reply

Your email address will not be published. Required fields are marked *