Mike Fishy and Automation System Programming (Bots)


#162

Do a cap raise and build a company out of it. I know people in Aus who’d invest.


#163

Or a forex thread…while BTC is dormant… to introduce the working way of the Bot… :wink: :joy:
:beer:


#164

Hi Mike, long time follower of this thread.

Please let me know if I can be any help to you.
I am in Australia and would like to help contribute to the code base.
Perhaps you could share some of your problems you are having with & we can share our solution(in code).


#165

OK, my bot is complex and needs too much work.

If we were to create a much more simple bot that could be run yourselves, what platform would you like to use?

  • Windows
  • MAC
  • Linux
  • Mobile

0 voters

Lets see what comes up and I can create a new Github and start pushing framework and how-to stuff.

Edit: I put mobile in there, but to be honest, not a good choice for running a bot, but I’m interested to see what people would like to use.

Thanks.

Mike Fishy


#166

What is the bot written with?


#167

I was thinking of just using PHP, which is great to prototype in as it is so quick to code.
Then once that part is together, it will depend on the platform.
Or maybe could go multi-platform and use Java, but Java is not very reliable…

All up in the air at the moment, will accept what the majority would like as I can code in 26 languages on multiple platforms, so I don’t really care.

However, community effort, so it is not what I want, it is what you guys want.

Stay Fishy


#168

What can we, non-coders of this community, do to contribute? I could have a case of beer delivered to your doorstep, at the very least! :beers:


#169

Hi Mike,
Java is probably what the most majority can code in.
As far as mobiles go, it will not be reliable to run the bot on a mobile in my opinion.
You could even go full javascript with node js backend. So we can have 1 language to maintain frontend and backend.


#170

I’ll be happy to contribute to Github ! :smiley:
(Well depending on the language of course. I’m not a polyglot like Mike, but I know 5/6 languages I would say) :slight_smile:
(JS, python, ruby, golang, java…)


#171

All good and even non-coders can contribute with helping on decisions and testing, documentation, feedback and so on. Thats what a community effort is about, everyone is useful.

I think this thread is a bit long in the tooth, maybe we should start a new thread and do this.

Also, please have a think about what Exchange to use for the Bot, I would personally prefer one that doesn’t require KYC rubbish even if it has a 2 BTC limit. So it doesn’t have to be Binance, it could be any Exchange with an API, like KuCoin or Cryptopia, both of whom don’t require any KYC to sign up and get going with small amounts.

Now, 2 BTC limit is per day, which for many people might be a lot.

So hands up for new thread and poll for an Exchange?

Javascript/Node.js is fine for me, but might be a little complex for the non-technical.
As long as we also do step-by-step for newbies, I’m ok with it.

Stay Fishy


#172

I would love to get a bot up and running!


#173

Pardon my absence, but I’m definitely interested in working on something here. I have been slammed with dealing balancing a destroyed house (and returning it to livable conditions) and contract work, so have not been active around the pub much lately.

If language doesn’t much matter, then how about Ruby? I have a large part of the framework in Ruby already built as part of putting together the open source Prospero portfolio management app that is coming.

So if it’s in Ruby, I’m inclined to help build together on this side of the project. If it’s in PHP, well, let’s just say, I’m not a fan even though I’ve built more than a few WordPress plugin’s in my time and think it’s a solid language. I’m just a “good developer” in most other languages, but a master developer in Ruby and just absolutely love building and thinking in Ruby.

At the moment, I have exchange API’s for Binance, Bittrex and Kucoin. I have some tie-ins to Cobinhood, Trade Satoshi and began to do a Cryptopia one as well. Binance’s integration is pretty tight because it’s by far and away the most reliable and responsive.

There’s no reason Prospero can’t handle both portfolio management and algo trading, I just wasn’t going to get into to open sourcing and maintaining a trading platform because that’s a lot more time intensive and time sensitive with the app’s decision making tooling with a lot more things that can go wrong in the process.


#174

I would love for it to be written with Ruby. Love writing Ruby.


#175

Hi all,

Sorry, had to take a break for a while due to needing some surgery. The mind is still young, but the old carcass is starting to fall apart.

I’m in for writing some code, I always love building new stuff.

I was thinking of starting with something simple to prototype out a basic system with a simple strategy that can be run on fairly much any PC and using PHP as you can prototype in it really fast. Once a prototype is made, then can look at more formal things like running it in a Docker Container or more advanced options and robust language.

Since most people either have or can access a basic Windows 10 PC or MAC, lets start with a basic environment for PHP, use an existing framework to save time and write a super basic bot strategy that can be run by almost anyone that can follow a bouncing ball. It also lets me re-cycle some of my previous prototyping code, so I can get something together quickly for people to play with.

I shall start with a “How-To” for setting up the environment ready for the code to run first, which I shall work on next week and post it in this thread. I am going to assume a Windows 10 PC and someone with little to no knowledge of coding and setting up an environment to run code, but has basic skills on using Windows to run commands and install tools following a step-by-step procedure. The goal to to introduce new people on how they can get started, because the ones with little to no knowledge often want to achieve things but don’t know where to start. Whereas many people who do know what to do, often dont.

Stay tuned and Stay Fishy.


#176

Glad to hear that you are on the mend.

PHP sounds good if it means that you have an existing framework to start it off with. I look forward to contributing.


#177

Relieved you’re ok Mike! Welcome back! I really enjoy understanding the “mechanics” behind these bots and you’re particularly gifted in teaching/explaining it.


#178

Hi all,

The below is a “How-To” for setting up an environment on Windows 10 for running a PHP based bot on Binance. If you have a Windows 10 PC about, you can follow these steps to get a basic environment up and running for creating your very first Binance bot.

I assume you know basic Windows skills, but will try and keep it as simple as possible.

We are going to create some simple things using the PHP Language.
PHP is one of the easiest languages and is widely used, but getting setup is a bit cumbersome.

Step 1. Download PHP
Go to: https://windows.php.net/download/
Select the latest non-thread safe Zip download and save it.

VC15 x64 Non Thread Safe (2018-Nov-08 07:50:04)

  • Zip [24.53MB]

Once we have it downloaded, we shall create a new directory where we will install it.

Step 2. Open Powershell and install PHP7
To open powershell, click the “Start” menu button at the bottom left and start typing “Powershell”
You should see it after typing a few characters, so click Powershell and open it.
In Powershell, we shall create a new directory called PHP7.

mkdir C:\php7
cd C:\php7

Copy the file you downloaded above into our new C:\php7 directory.
(The file will be in your “Downloads” folder, so use File Explorer to copy it)

Now we have our new folder with the zip file in there, its time to install.

In Powershell, expand the zip file:

PS C:\php7> powershell.exe -NoP -NonI -Command “Expand-Archive ‘php-7.2.12-nts-Win32-VC15-x64.zip’ ‘.’”

We can test to see it worked by using:

PS C:\php7> .\php.exe -v
PHP 7.2.12 (cli) (built: Nov 8 2018 05:47:24) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright © 1998-2018 Zend Technologies

Now we need to edit the php configuration file, which will be called php.ini

PS C:\php7> copy php.ini-production php.ini
PS C:\php7> notepad php.ini

This configuration file has a lot of options, but the ones we need to edit is to uncomment some extensions so that php will use these extensions when we run our code.

The parts we edit are as follows (we remove the leading “;” from several lines)

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = “./”
; On windows:
extension_dir = “ext”

; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
;extension=interbase
extension=ldap
extension=mbstring
extension=exif ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=snmp
extension=soap
extension=sockets
extension=sqlite3
extension=tidy
extension=xmlrpc
extension=xsl

Once you have your php.ini as above, save it and exit notepad.

Step 3. Add PHP to our system path, so it knows where to find it.
Click the “Start” menu on the bottom left and start typing “Control”
You should see “Control Panel” appear, so go ahead and click it to open.
Open Control Panel
Click on System and Security
Click on Sysyem
Click ‘Advanced System Settings’ (on the left)
Click the ‘Environment Variables…’ button.
Click on the Path row under ‘System variables’, and click ‘Edit…’
Click ‘New’ and add the row C:\PHP7.
Click OK, then OK, then OK, and close out of the System Control Panel.

So it should look like this:

Once done, click ok and exit control panel.

The path gets updated after we close and re-open Powershell, so go ahead and close Powershell for now.

Step 4. We will be using the Github repository to download our Binance framework from, so we need to install Git for Windows as well.
Go to https://gitforwindows.org/
Download and install git
https://github.com/git-for-windows/git/releases/download/v2.19.2.windows.1/Git-2.19.2-64-bit.exe
(Make sure to select “Use Git from Windows command prompt” during the install)

Step 5. The Binance API Framework is setup using PHP composer, which is a tool that automatically downloads code and dependencies for us. So now we need to install composer for PHP which is as follows:

Open Powershell again and in Powershell, run the following:

PS C:> cd C:\php7
PS C:\php7> php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
PS C:\php7> php composer-setup.php
All settings correct for using Composer
Downloading…
Composer (version 1.7.3) successfully installed to: C:\php7\composer.phar
Use it: php composer.phar

Composer part as Web might have mucked it up:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php

We need to create a batch file for running composer, which need to be done in a Command Prompt, not Powershell, so close Powershell for now.

Open a Windows Command prompt, by clicking on the “Start” menu at the bottom left and type “cmd”
In Windows Command prompt window, run the following:

cd C:\php7
echo @php “%~dp0composer.phar” %*>composer.bat

You can test it by running “composer” and it should list a bunch of help stuff.

Right, that’s the hard part, now onto building our first bot.

Step 6. Create our bot directory and install the Binance API Framework

Open Powershell again.

In Powershell, run the following:

PS C:> mkdir C:\Fishy
PS C:> cd C:\Fishy
PS C:\Fishy> composer require “jaggedsoft/php-binance-api @dev

This will install the framework we are going to use for our bot program. Much of the code needed to use the Binance API is done for us in this framework, so our code will be small and simple.

Step 7. Create our first Binance API Test code.

In Powershell, lets create our first bot code that simply queries the API and returns some pricing data.
Binance does not require you to have an API Key for doing this query, so no API key needed yet.

So, in Powershell, lets create usdtprices.php as follows:

PS C:\Fishy> notepad usdtprices.php

Notepad will prompt to create a new file, so click yes.
Paste the following code into Notepad and save the file:

<?php
require 'vendor/autoload.php';
function getprices()
{
  $api = new Binance\API("<api key>","<secret>");
  $mp = $api->prices();
  return $mp;
}
$p = getprices();
foreach ($p as $key => $value)
{
  if(strpos($key, "USDT"))
  {
    print "$key : $value\n";
  }
}
?>

What this code does is load the Binance API Framework using the autoloader.
It then has a function which queries the API for the current prices.
Then finally, we search the returned output for “USDT” and print the result.

So, in Powershell we run it as follows:

PS C:\Fishy> php usdtprices.php
Curl error: SSL certificate problem: self signed certificate in certificate chain

However, we get an error with the SSL Certificate, that we need to fix.
The Certificate bundle gets downloaded automatically for us, we need to tell PHP where it is, otherwise it cannot verify the SSL Certificate from Binance and gives us an error.

So, in Powershell, we need to edit the C:\php7\php.ini file:

PS C:\Fishy> notepad C:\php7\php.ini

Find the section for Curl where the cainfo goes and modify it to read as follows:

; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = C:\Fishy\ca.pem

Save the file and exit. The above tells PHP to find the ca.pem certificate bundle in our bot directory.

Now, when we run our code:

PS C:\Fishy> php usdtprices.php
BTCUSDT : 4147.60000000
ETHUSDT : 119.71000000
BNBUSDT : 5.34020000
BCCUSDT : 448.70000000
NEOUSDT : 7.94100000
LTCUSDT : 31.90000000
QTUMUSDT : 2.12000000
ADAUSDT : 0.03936000
XRPUSDT : 0.38976000
EOSUSDT : 3.43950000
TUSDUSDT : 1.03970000
IOTAUSDT : 0.29400000
XLMUSDT : 0.16380000
ONTUSDT : 0.90000000
TRXUSDT : 0.01273000
ETCUSDT : 4.90880000
ICXUSDT : 0.25100000
VENUSDT : 0.00010000
NULSUSDT : 0.50750000
VETUSDT : 0.00480000
PAXUSDT : 1.03330000
BCHABCUSDT : 191.40000000
BCHSVUSDT : 95.80000000

And that’s it, we have the price data for all pairs with USDT.

So today, we have installed PHP7, installed Git, installed Composer, installed the Binance PHP API Framework and created our first API code that queries Binance for the current prices.

We now have a complete environment ready to start writing our own code.

The Binance API from Jaggedsoft and all the API calls can be seen here:

Kudos for the guy for writing an API for us to use and fixing the bugs I told him about :slight_smile:

Did you get this far? Need any help? Let me know!

Stay Fishy


#179

@Mike_Fishy, thanks for putting up detailed instructions. I’m not a coder, so this is all pretty new to me. My last programming experience was at school in the early 80’s, using BASIC.

I got to Step 5 and encountered an error.

This returns the following:

PHP Parse error: syntax error, unexpected ‘:’, expecting ‘,’ or ‘)’ in Command line code on line 1

I tried a few things but couldn’t get past this error.


#180

Hi Seikin,

The code is:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

You can see the instructions here:

https://getcomposer.org/download/

Let me know how you go :slight_smile:

Stay Fishy


#181

Thanks, that worked. I got to the end of your first tutorial no problem. I’m excited to see what comes next.