Building my own Crypto Trading Software - Part 1

 The simple Bot at work on a Raspberry Pi

This week I began to start work on building my own crypto trading program, I've decided not to build a bot as I said I would in a previous post as it appears everyone has already done that! So instead I intend to build a Python program capable of assigning and controlling multiple bots, each with tailorable trading strategies. The program will incorporate a GUI displaying user selectable market data allowing users to modify strategies for their bots without having to leave the program and reference exchanges or other resources for market data. The program will be deployable on any machine running python but in my case I'm going to run it on a Raspberry pi as a low cost/power trading bot manager.

The Coinbase pro API is going to be used to access their exchange. The process of getting the API keys from Coinbase pro is not difficult and I am not going to cover it here as there are lots of videos and guides available to see how to do it but make sure you take care of those keys, for the sake of this project I've saved them into a text file. I chose to use the Coin base pro API as I already hold an account with the company and after some time researching I found a Python Package that would would streamline the API calls required, that package is cbpro which is available through PIP (The python package manager).

Now armed with all of the tools needed I opened my IDE and started throwing down code but nothing happens other than a string of errors and for a while I'm utterly clueless, until I realized I recently installed Python 3.10 and went back to check the documentation. Of course I needed to use an older version, so two installations of older versions of Python later and I found python 2.7.14 (That I already had installed anyway) was compatible with the package...phew. After configuring my IDE to work in the older Python I was off and running again. If you are reading this with the intention of building it yourself, I believe versions of Python 3 below 3.5 should work but I just went with what I had in the end.

The first task I set myself for working with the API was to start getting usable market data that can be available in the app for decision making so I set about writing a few functions that present data such as daily stats for a coin, a list of all currency pairs, current balances and some others that provide data the bots may use. The images below detail some of these functions.

 A simple function that displays the stats on a currency pair

 A function that displays 24 hour stats

 A function that displays all balances.


As can be seen it is relatively simple to extract data from the API although these functions in their current state will need to be modified later on when building the GUI, but for now I am happy that any data I may need further down the line can be extracted and manipulated.

Onto the next task, I wanted to build a very simple trading bot and started looking into the most acceptable (volatile) coins to work with and decided upon XLM and began writing the code for my first bot, if you visit https://pypi.org/project/cbpro/ the full documentation is available for the package in use including examples of creating buy and sell requests. The test bot I created is not fancy and does not involve any special algorithms however it is functional and theoretically should produce profits. For the sake of testing the bot I gave it some funds to play with and the image below shows the code used to create it.

 Python implementation of a simple trading bot


As you can see I have set a market buy and sell price that are within the range of the current price movements and although the difference is only 3 cents between the buy and sell prices the hope is that it will occur frequently, although this may need some adjusting of the values as it has only been up and running for a few hours.

I decided to also include a safety price which stands at 2/3 of the buy price, this has been done to (in theory)protect against a coin suddenly dropping value and being bought on its way down, however how well it works at the current value is yet to be seen and this and the delay between checking prices may need adjusting, but for now its my own functional trading bot! its been up and running for around 12 hours now on a raspberry pi3, but alas no buy/sells yet, in part two I will post an update of how it is performing.

So over the next few days to a week I intend on creating a GUI to combine all of the applicable data from the functions I've created into a dashboard, write the code to be able manipulate the settings for the bot from within the GUI, start writing a second bot that takes into account market data when making decisions about buying and selling as well as quantities to buy and send. I think that should be enough to keep me busy for a while and I will update readers with a part 2 documenting the progress made and the profits if any from the simple bot demonstrated.

Thank you for taking the time to read this article, feel free to follow if you found it interesting and any advice would be gladly received.

Also if anyone does want the code I have written so far just ask in comments and I will put it on Github but tbh I'd wait till its more complete.

Sort:  

Congratulations @pompeylad! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You distributed more than 50 upvotes.
Your next target is to reach 100 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

The new HiveFest⁶ attendee badge is waiting for you
Feedback from the November 1st Hive Power Up Day
Support the HiveBuzz project. Vote for our proposal!