Universal Trade bot for cryptocurrency markets with REST and web socket streams support, based on knowm Xchange(https://github.com/knowm/XChange) and bitrich-info Xchange-Stream(https://github.com/bitrich-info/xchange-stream) libraries.
It is simple and already has everything to start implementing strategy logic and forget about other technical details.
Very light weight and minimum of dependecies. Possible to use a bunch of this bots in one application(Documentation on this case coming soon)
rescources/application.yml
- configuration parameters
Connection parameters are mandatory
userName:
, apiKey:
, secretKey:
All strategy parameters dependce on strategy logic
There are two places to look for:
- Your implementation of
Configurator
interface. Source code contains complete eaxmpleDefaultConfigurator.java
- Your Implementation of
Strategy
interface. Source code contains base exampleAbstractStrategy.java
andDefaultStrategy.java
Look at DefaultConfigurator.java
. In most cases you just need to do 2 things in configure()
method:
- Set another
Strategy
interface implementation in place ofenv.setStrategy(new DefaultStrategy(env));
- Set used exchange Client in place of
env.setExchangeClient(new ExchangeClient(env, BinanceStreamingExchange.class.getName(), new BinanceExchange()));
. Notice that you will automatically receive market data streams after application starts. Not additional configuration needed except to set Market data stream(Look at Implementing Strategy interface section item 2).
Also change in pom.xml info.bitrich.xchange-stream
dependency if other than Binance exchange client used.
public class DefaultConfigurator implements Configurator {
Environment env;
public Environment configure() throws Exception {
env = new Environment();
env.setPropertiesFactory(new YamlPropertiesFactory());
env.setProperties(env.getPropertiesFactory().readProperties("default-strategy.yml"));
env.setExchangeClient(new ExchangeClient(env, BinanceStreamingExchange.class.getName(), new BinanceExchange()));
env.setStrategy(new DefaultStrategy(env));
env.setRepository(new CacheRepository());
return env;
}
public void initialize() throws Exception {
env.getExchangeClient().initStreams(env.getStrategy().usedCurrencyPairs());
env.getExchangeClient().writeData();
env.getStrategy().setup();
Runnable runnable = new StrategyRunnable(env);
Thread strategyThread = new Thread(runnable, "Strategy thread");
strategyThread.start();
}
}
If you implement Configurator
interface in other class, you also need to change one line in Application.java
. Insert your Configurator
interface realisation in this line AbstractConfigurator configurator = new DefaultConfigurator();
instead of default one.
Look at methods in DefaultStrategy.java
:
List<CurrencyPair> usedCurrencyPairs();
- contains initialisation logic for currancy pairs needed for your strategy. This pairs client will listen from exchange market data stream. You can find example inDefaultStrategy.java
MarketStreamType getMarketStreamTypeNeeded();
- Market stream type needed for your strategy.OrderBook
orTicker
. You can find example inDefaultStrategy.java
void setup() throws Exception;
- This is setup logic for strategy initialisation which shold be processed before strategy starts execution.void start() throws Exception;
- Write here your strategy logic.
Also Strategy contains Environment env
object level variable. There you will find all service to realise strategy.
Environment.java
this class is used for dependency injection of services in Strategy
.
Services:
ExchangeClient exchangeClient;
- this is an instance of exchange client. There you'll find all services to make API calls.AccountService
,TradeService
and other.Properties properties;
- this is a classProperties.java
where you should add all your strategy specific properties with same name like inapplication.yml
and this properties will be automatically initialised.Repository repository;
- This is repository where MarketData stream writes market data automatically after Application starts.
If you need to use multiple exchanges in one application, pehaps for arbitrage between exchanges, you steel may you this bot.
Initialize every exchange bot like in Application.java
. You will get environment for different exchanges.
Use those environments to work with each exchange.
Configurator default = new DefaultConfigurator();
Environment defaultEnv = default.configure();
default.initialize();
Configurator other = new OtherConfigurator();
Environment otherEnv = other.configure();
other.initialize();