Smartphone Trading Bot

#1

We will keep the latest QR code image at the top of this thread rather than in each post. Makes it easier for everyone. This is for PubBot 2.2.

2

This is a thread associated with the trading bot being developed by @Mike_Fishy and others at Mike Fishy and Automation System Programming (Bots).

About 9 months ago I built a smartphone “app” which notified me when specific cryptographic digital assets (CDA) reached my target BUY or SELL price. Alerts were sent out by Super Push notifications (overrides phone silent settings), email and SMS.

At the time I didn’t set up the system to actually trade the CDA’s automatically but having followed the bot thread I have now set up automatic trading. After each automatic BUY or SELL order is placed with a leading CDA exchange I receive a PUSH confirmation of the trade.

As shown in the configuration screen the app is currently in simulation mode so it doesn’t actually trade with the exchange. SHA256 cryptographic signature verification is used even for the simulated trades and live trading is enabled by clicking the LIVE button and entering a six digit PIN.

The main screen is shown below and covers the period just prior to the latest Bitcoin pump.

The app charts the data for moving averages and RSI which can also be exported as CSV files for further analysis in Excel etc.

The graphs are also available in landscape mode.

The short term RSI gave a good correlation of price movements as shown below.

The app runs on Android or iPhone but I am NOT an app developer.

Someone who sings is a singer, someone who runs is a runner so someone that uses the “Blynk easy iOT smartphone app builder” is a Blynker (hence my username). Other than using their app to build iOT projects I have no association with the company.

Links for the Blynk app in the Apple and Google Play stores are available from their website https://www.blynk.cc/

I converted the PHP scripts provided in the bot thread to C++ and added the code to my original CDA price alerts projects. Added the API calls for actually trading and flashed a $3 WiFi enabled MCU with the C++ code.

The WiFi enabled MCU performs the trading calculations and acts as a bridge between my cloud server and my smartphone.

Once a project is built with the Blynk tools you simply generate a QR code image in the project and make it available to anyone that wants a clone of your project.

Some of the Blynk widgets like video streaming and GPS work without an MCU but as we need to perform the trading calculations it’s an essential part of the project.

Further updates in due course.

8 Likes
Mike Fishy and Automation System Programming (Bots)
#2

Binance general API: as documented at https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

The general public can pull an enormous amount of CDA data from the Binance servers even without having an account with the exchange.

The basic allowance is 100,000 calls per day or a call every 1157 ms. For heavy duty data analysis Binance also provides Web Sockets Streams as documented at https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md

For now we are working with the general API so pasting the following into a browser
https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT

Returns the latest Bitcoin price as:
{"symbol":"BTCUSDT","price":"3383.56000000"}

Once you decide to enable your API keys on the Binance exchange you can move on to automated trading but ensure you follow all the recommended security warnings. By default enabling the API keys will not permit funds to be withdrawn via an API call.

This only offers a certain amount of protection though as we saw from the successful phishing attack on the exchange earlier this year. The phishing hack enabled / used API keys to trade a lesser known CDA without the account holders consent. This has the same effect as withdrawing your funds as the hackers can sell your CDA’s for next to nothing.

I have now added “one click” manual trading to the bot project. The option is off the bottom of the main page so it can’t be activated by mistake. Prior to using the feature you also have to follow the process of switching from simulated to live trades.

So if I see a trade set up that the bot hasn’t spotted or I simply wish to BUY / SELL a CDA I can trade with a single click. Might also be useful for people wanting to do their regular DCA buys.

For those following the “real” bot thread you will notice the manual trades are available before the trend analysis has completed i.e. as soon as you boot up the app. Also the ST RSI and MT RSI is available without waiting for LT trend analysis to finish. SMA and MMA could also be processed prior to having the MMA data.

This leads on to my next task which is the “replay” / data harvesting / logging routines. If the MCU is connected to a PC it already provides a log as shown below (using Termite or similar).

The normal expectation is that the MCU operates in standalone mode, without a PC, so I am looking to add logging / data harvesting on the MCU. Hopefully this will be handled with SPIFFS (SPI Flash File System).

Scan the latest QR code image from the first post in this thread. Our server details are available via PM.

5 Likes
#3

Very nice :smiley:

Staying Fishy

3 Likes
#4

In my copy of the PHP bot script I have switched from serialize to json_encode (and from unserialize to json_decode).

Also changed data file name to data001.txt, which becomes /data001.txt in SPIFFS 8.3 file format (note 1 character for /).

This allows for “automatic” upload of the data to the MCU.

Reading about 12 minutes of data (which is only about 140 data points for each of the 430 tickers on Binance) from SPIFFS takes about 420 ms.

1 Like
#5

Version 2.1 of the “PubBot”

Major change for this version is that it doesn’t interface with a $3 MCU. It interfaces with something much more powerful and something that most people have i.e. a PC.

All the bot does at the moment is that it lets you set a trailing stop loss on Binance and it will buy and sell at your target prices. You can see the status of any open orders and cancel them from the app.

True bot trading algorithms still need to be added.

As per earlier posts, install the Blynk app on your Android or iOS device and then set the server in the app to ours.

Then create an account on our server and scan the latest QR code image from the first post in this thread. All done from within the Blynk app.

You should then have the Bot on your phone. Send me a DM for details of how the app on your phone interfaces with your PC.

5 Likes
#6

Very interested to see where this goes, great job!!!

2 Likes
#7

Latest screenshots for PubBot2.2. Images should give you an idea of what the app does but I will add further details in due course.

Latest QR code image is contained in the first post of this thread.

State of play:

  1. Added email alerts in addition to PUSH messages
  2. Added time check to match Binance server
  3. Added “magic” indicators
  4. Early alpha testing commenced
  5. Annoying target reset bug to iron out.
  6. Multiple scripts now running for different tasks
  7. Early Windows executable to Smartphone interface tests completed.
  8. Switching tickers code improved.

We might be looking for a charitable graphic designer (?) that can produce images to give this effect:

Obviously with a pub / beer / crypto / bot theme rather than a tacho.

2 Likes
#8

Trading View snapshot of Bitcoin’s move up today.

Our Bot pulling out the same indicators for candlesticks, Moving Averages, RSI and MACD.

We only produce the charts to ensure that our data is valid. We have volume indicators to add and a few others. Then we can start feeding them into our strategies.

4 Likes
#9

Trading View snapshot for BTCUSDT on Binance exchange.

Bot data validation, now with volume.

2 Likes
#10

@blynker this is looking really good. Do you have graphs of other coin pairs too?

2 Likes
#11

Yes the bot can graph any Binance pairs.

4 Likes
#12

On the daily time frame It takes about 2.2s to get the data, plot the chart and save as png and csv.

There are currently 434 tickers on Binance with more than 26 days history (required for MACD). Took a little over 16 minutes to produce all 434 charts this morning. It’s much quicker for the bot though as it doesn’t need the charts. It’s just working on the underlying data.

When I have a minute I will check the processing time for the data without charts.

2 Likes
#13

pretty impressive and pretty quick to graph them all, about 2.2seconds per chart. Not too shabby really.

Crash

1 Like
#14

I think when I did tests the other day it was about 0.5s per ticker for data only.

2 Likes
#16

@Blynker your progress on this space is awesome. Looks like is is really coming together.

Crash

2 Likes
#17

For some reason it no longer looks like I can edit the first post in this thread, to add the latest QR code image, so it will be included in this post.

Firstly the screenshots for PubBotV4.1. Fairly self explanatory but we have moved away from the smartphone app being a bot to it being more of an interface to the bot. It still lets you change some of the bot parameters and start and stop the bot but with more of an emphasis on showing the ROI etc.



1%20QR%20code
One thing you will probably notice is that the ROI figures are tiny, so 0.25% not 25% :slight_smile:
My aims when I started with the project were:

  1. Build a smartphone automated trading bot.
  2. Generate 1% ROI per day.

Stage 1 is virtually complete and work is ongoing to generate the 1% daily returns. 1% might not seem very much but it’s 35% per month and would turn $10,000 into almost $380,000 within 1 year. If it was simple everyone would have their own trading bot.

Over the coming days I want to add details here of the different programs and files we are using. More for my own record keeping as much as anything else. There are quite a few py, csv, json and MongoDB files. I’m starting to lose track of what each one does, hence the forthcoming documentation.

4 Likes
#18

DOCUMENTATION:

Capital invested is broken down into holding a maximum of 10 different CDA’s at any one time. Currently prices are obtained for Binance USDT pairs including 1 stable coin (TUSD). We monitor BTC but we do not trade it.

When a buy signal is generated for a particular CDA it is added to our portfolio with a trailing stop loss (SL) and ROI sell trigger. Sell trigger is disregarded if trading conditions for the CDA indicates a continued uptrend.

If SL is reached for a CDA the CDA is sold. All CDA’s in the portfolio are sold if BTC falls sharply. Portfolio is continuously monitored and if overall required ROI, plus selling fees, is reached the portfolio is sold off.

When the portfolio is sold off the smartphone app sends out a PUSH message and an email. It also updates the original capital balance held in a json template. Users can disable the auto sell off from the app if required.

A couple of screenshots of the “end game”.

File list and descriptions to follow.

3 Likes
#19

WARNING wall of text to follow.

Get prices for USDT pairs.

Filename populate_database.py runs 24/7 to populate a capped collection MongoDB with up to 3 hours of price data so the Bot is ready to go at all times. Reads available CDA pairs from a fixed json file (pairs_for_db.json). Json file is used so CDA’s can be added or deleted without stopping the database updates. Accompanying file delete_db.py is available if the MongoDB collection ever needs to be deleted i.e. if switching from say USDT to BNB pairs.

Records all prices in a supplementary csv file (cda_data0003.csv) for backtesting purposes. Suffix of 0003 is incremented from time to time when the file gets too large.

%20populate%20database
Small supplementary file forever.py to ensure all Python files run “forever” i.e. restart on error or on request.

Filename trader.py with buy / sell functions and update CDA holdings in a dynamic json file (Client00001.json). No trading logic in trader.py but does include:

  • Secret key hmac encoding
  • Min notional order value check
  • Timestamp hack for Windows users
  • Order depth price tolerance
  • Exchange fee calculation

Filename PubBot4.1.py is the main trading bot. Features include:

  • Reading MongoDB for CDA prices
  • Buy and sell logic
  • Call trader.py to buy or sell the CDA
  • Update json file (usdt_pairs.json) with trend and signals data
  • Update json file (Client00001.json) with CDA holding incl Quantity, Buy Price, SL etc
  • Update csv file (Signals.csv) with a log of each trade

Filename PubBot4.1app.py is the smartphone code and features:

  • Displays each trade added to Signals.csv log
  • Ability to pause or restart main bot
  • Send PUSH and email alerts for CDA target price etc
  • Option to manually buy or sell CDA’s
  • Change working parameters for main bot
  • Display latest ROI
  • Manually sell off all CDA’s
  • Disable auto sell off in the main bot
  • Reset json files to default position from backup_usdt_pairs.json and backup_Client00001.json
  • Manually change capital balance in json files
  • Create new Signals.csv from fresh_signals.csv

Supplementary file for sensitive data.

So about 15 files in total, excluding MongoDB files.

3 Likes