Building a trading bot in Python

Building a trading bot in Python

A bot is an automated software application. There are different kinds of bots and even though chatbots are quite popular now, there is another favoured 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 it’s 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 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 community and here are a few popular one’s 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:

Decision on which Database to be used for cryptocurrency trade bot by using 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 being 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 the 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 a 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 a high performance tool which is popular for the 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. 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-nonrel but they are not as good.

There is a better one, Djongo (Read more on: https://nesdis.github.io/djongo/), keeps the django ORM intact but it is relatively new with small community.

Also, it couldn’t find a roadmap for “MongoEngine for Django” because they mostly promote Djongo 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 the link 3.0 mentioned in the list of references.  Also few insider thoughts can be encountered in the link 4.0 from the list of references.

Technology –

References

1.0 http://www.numpy.org/ (Accessed)

2.0 https://blog.panoply.io/top-5-alternatives-to-mongodb (Accessed)

3.0 https://github.com/edx/edx-platform/wiki/Frequently-Asked-Questions#database. (Accessed)

4.0 https://www.pydanny.com/when-to-use-mongodb-with-django.html (Accessed)

Author: Raj Sanghvi

Raj Sanghvi is a technologist, innovator and founder/CEO of BitCot, a full service award-winning application development company. With BitCot, Sanghvi has helped over 100 clients develop mobile apps & SaaS platforms, making them affordable and successful. Visit Raj Sanghvi on LinkedIn and follow him on Twitter, @BitCot.View Full Bio

Free project quote

Fill out the enquiry form and we'll get
back to you as soon as possible.
Contact Us: 858-683-3692
Dave S

Dave S

Co-Founder- StompSessions

Quote

I have Known BitCot for 4 years and have been impressed with the diversity and quality of BitCot’s work. With that solid foundation it was really easy to select BitCot as our development partner. Quote

Show Buttons
Hide Buttons