GalacticBot is a PHP 7.x library for creating trading bots on the Stellar platform.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demo Revert "Revert "Merge branch 'master' of https://github.com/unwindnl/… Sep 6, 2018
src
.gitignore First import of working but undocumented code. Aug 9, 2018
LICENSE
README.md Update README.md Oct 3, 2018
composer.json Fix for packagist.org Aug 9, 2018

README.md

GalacticBot

GalacticBot is a PHP 7.x library for creating trade bots on the Stellar platform.

With GalacticBot you can run bot(s) with our default trading algorithm or create and test your own custom trading algorithm(s).

Bots can be run locally on your machine, on a server or you could let us run it for you on https://www.galacticbot.com/ for a small fixed monhtly fee (service will be available Q4 2018) (Of course payable in XLM).

Features

  • An abstract bot class which you can extend to do implement your own trading logic
  • Bots can be run both the Stellar public net as well as on the Stellar testnet for testing
  • Bots can be run in real time or as an simulation to test out bots and settings
  • Exponential Moving Average (EMA) bot implemention which is currently being live tested (see below for links)
  • Demo project to get a bot up and running in minutes
  • Demo project also includes a script to manage bot processes

Requirements

  • PHP version 7.1
  • No extra PHP modules are required
  • MySQL is needed for running the demo EMA bot, but you could create an implementation for any other type of database

Warning

Please note that this library is still under development. It is not advisable to trade with large amounts at this stage.

Installation

This package is available on Composer.

Use composer require unwindnl/galacticbot to add this library to your PHP project.

Demo

This project contains a demo project of how to setup and run a bot with a minimal web interface to interact with the bot. Please see the demo/README.md demo/README.md folder for more information.

A live demo is available on: https://www.galacticbot.com/libdemo/.

We also created an example of a custom (graphical) view for the live bot on: https://www.galacticbot.com/demo/.

Data(base) abstraction

The bot does not interact with a database directly but uses the DataInterface interface for describing how an implemention should look like.

Please see the example MysqlDataInterface implementation of how to implement your own if you would want to interface with another database. This example implementation is not optimized and could slow down with more data in the database. So its best to clear our older data or optimize/create your own implementation.

Implementing your own trading algorithm

Create a class that extends the GalacticBot\Bot class.

Add a list of custom trading states your bot can have, for example:

const TRADE_STATE_BUY_WAIT = "BUY_WAIT";
const TRADE_STATE_SELL_WAIT = "SELL_WAIT";

Implement the following abstract methods:

initialize()

Here you could load for example data from a database you going to need for your algorithm. This is only called once.

getTradeStateLabel($forState)

This is were you return a more descriptive text for each of your custom states you defined earlier.

process(\GalacticBot\Time $time, $sample)

A very minimal example:

protected function process(\GalacticBot\Time $time, $sample)
{
	// Get current trade state
	$tradeState = $this->data->get("tradeState");

	// Get the last added trade
	$lastTrade = $this->data->getLastTrade();

	// If we have a trade and it isn't completed yet, then update it to get the latest state
	if ($lastTrade && !$lastTrade->getIsFilledCompletely())
	{
		// Get the latest state from the Stellar network
		$lastTrade->updateFromAPIForBot($this->settings->getAPI(), $this);
		
		// If it isn't done, we'll have to return and wait for it to complete
		// You could also cancel it or change it if you want
		if (!$lastTrade->getIsFilledCompletely())
			return;
	}	
	
	if ($tradeState == self::TRADE_STATE_NONE || $tradeState == self::TRADE_STATE_BUY_WAIT)
		if (time to buy / do something with $sample)
		{
			$this->buy();
			$tradeState = self::TRADE_STATE_SELL_WAIT;
		}
	}
	else if ($tradeState == self::TRADE_STATE_SELL_WAIT)
	{
		if (time to sell / do something with $sample)
		{
			$this->sell();
			$tradeState = self::TRADE_STATE_BUY_WAIT;
		}
	}
}

Open issues

  • You need to setup a trustline for the assets you want to trade with your Stellar account. The library will do this for you in the future but for now you will have to do this yourself (with for example StellarTerm).