Skip to main content

Building a trading bot in Python

By May 12, 2018December 11th, 2023Emerging Tech, Startups
trading bot thumbnail

A bot is an automated software application. There are different kinds of bots and even though chatbots are quite popular now, there is another favored segment that is Cryptocurrencies. We have built a trading bot for cryptocurrency and have chosen Python as a language of choice to build the trading bot. Python language is similar to mathematics that has a huge community around it. It is a really good tool for solving problems such as data analysis, pattern recognition, simulation, image processing, scientific computing and a whole bunch of other uses.

We really like Ruby and Python for back-end and at the syntactic and semantic levels, Ruby and Python both are capable of expressing the same concepts and algorithms. However, Ruby may have a slight advantage due to the influence of Smalltalk in its design, which makes it easier to use for constructing Domain-Specific Languages. Ruby and it’s ecosystem is still richest and popular in areas that are related to the web application and API development. Python started out being applied to diverse uses, such as system scripting and text processing which led to simulation, data processing, and several other cases.

Python bridges to NumPy

The use of Python in scientific computing and simulation prompted the development of higher performance extensions such as Numeric and Numarray, which then gave rise to NumPy in 2003, an extension that provides data types for arrays and matrices and high-performance mathematical operations, including operations on those arrays. NumPy is itself further extended by other libraries like SciPy and Pandas.


Python has a lot of really solid libraries backed by the community and here are a few popular ones NumPy, Keras, TensorFlow, scipy, matplotlib, pandas, Jupyter, etc for machine learning and in areas where you need to run statistical functions or data analysis. NumPy is a scientific computing library that can be used to model N-dimensional array objects and run several sophisticated functions against them. NumPy can also be used as an efficient multi-dimensional container of generic data. This allows NumPy to seamlessly and quickly integrate with a wide variety of databases.

CryptoBot Database Design:

The decision on which Database to be used for cryptocurrency trade bot by using the Django framework? And the reasons behind opting MongoDB by us.

There are several reasons for choosing MongoDB which are briefly discussed as follows;

Firstly, MongoDB documents have the ability to store unstructured complex information and data in a way that is relatively straightforward to update. MongoDB offers a high-interest rate and therefore it helps in scenarios where the write load in high. MongoDB is an open-source, stores data as documents in a binary representation called BSON (Binary JSON).



Secondly, the use of MongoDB can prevent and reduce the complex object-relational mapping (ORM) layer which is used to translate objects in code to the relational tables. The database schema has also improved on the bases of business requirements due to MongoDB’s flexible data model.

Finally, MongoDB scales quickly without changing the application and time when the deployments increase with respect to data volume. If compared to other databases like MySQL it is often a requirement for significant and custom engineering work.

Why did we choose MongoDB instead of MySQL?

Databases like MySQL, it is important to understand the requirements of the project and future goals. Talking about, MySQL it is a well-recognized and high-performance tool that is popular for flexibility, reliability on data protection and availability. However, if the data is said to be unsystematic and unstructured it would be advised to opt for MongoDB. The reason being, MongoDB can be measured within and also across multiple distributed data centers, providing new levels of availability and measurability which were previously unachievable with relational databases like MySQL.

Django and Mongo Support Problem

Django does not provide native MongoDB support, so using MongoEngine is one of the options.

But currently, MongoEngine does not support Django ORM, so models cannot be serialized and hence admin setup is a problem.

There are some alternatives, MongoDB-engine, mongo-nonrenal but they are not as good.

There is a better one, Django (Read more on, keeps the Django ORM intact but it is relatively new with a small community.

Also, it couldn’t find a roadmap for “MongoEngine for Django” because they mostly promote Django in their documents.

Hybrid Approach

Models like users, accounts, static data collections can live in SQLite/Postgres adhering to Django ORM. And all the robust data models can live in MongoDB (using PyMongo), which might compromise with ORM, but it turns out we might not really need the object-relational mapping support.

This should solve the problem.

This approach used by one of the bigger communities and therefore to understand further refer to link 3.0 mentioned in the list of references.  Also, a few insider thoughts can be encountered in link 4.0 from the list of references.

Technology –


1.0 (Accessed)

2.0 (Accessed)

3.0 (Accessed)

4.0 (Accessed)

Raj Sanghvi

Raj Sanghvi is a technologist and founder of BitCot, a full-service award-winning software development company. With over 15 years of innovative coding experience creating complex technology solutions for businesses like IBM, Sony, Nissan, Micron, Dicks Sporting Goods, HDSupply, Bombardier and more, Sanghvi helps build for both major brands and entrepreneurs to launch their own technologies platforms. Visit Raj Sanghvi on LinkedIn and follow him on Twitter. View Full Bio

Leave a Reply