Skip to content

Winster332/FarmMachine

Repository files navigation

Icon FarmMachine

I tried to write a system of autonomous earnings using TradeView and PineScript. It was an experimental project. Unfortunately, this project was not successful due to the principle of the TradeView platform using their backtesting strategies. At the moment, I suspend work on this project.

Project closed

It was experimentally found that this method is not profitable or working. The reason is that the TradeView platform dynamically changes the results of strategies, making them unstable. For this reason, it is not possible to be sure that the placed order is true, because TradeView can change the indicators at any time.

This is a service consisting of two microservices that allows you to configure offline trading. For this, services are integrated with external exchanges, and TradeView. TradeView is necessary for conducting backtests and receiving signals. Since there is currently no suitable tool for executing PineScript in the local system, I had to put TradeView into the Chromium engine, and already through it execute js scripts on the TradeView side. The FarmMachine.MonitorStrategy microservice is responsible for this. Microservices are connected by the RabbitMQ bus, and the MongoDB database is used for storage. When a new signal arrives, FarmMachine.MonitorStrategy sends the RabbitMQ bus signal. This signal is caught by the FarmMachine.ExchangeBroker service. He is responsible for integration with exchanges. When a buy / sell signal arrives, some calculations occur, after which a conclusion is made - what to buy, at what price and in what volume.

The data project is experimental, and is not recommended for reliable use.

Reports on the work of Rabbit can be seen in this table.
The project works exclusively on Windows. Since the project uses the chromium engine, this greatly complicates the transfer of the project to other OS.

Supported exchanges

Name Version Support
BITTREX 1.0.0 Yes
BINANCE 1.0.0 Yes
POLONIEX future No
HitBTC future No
Bitstamp future No
Bitfinex future No

Use the api key and secret to authorize your api exchange

Services

Scheme

orange - development in progress
red - part due to which docker is not used
blue - direct functions not available

N|Solid

Google Drive - Draw.IO scheme

Build and start

Before you start building a project, you need to install a Docker. After installation and configuration. And after the launch of the infrastructure, you can start assembling the project services

Start infrastructure

You must go to the configuration/docker/ directive, and then run the following commands:

PS> FarmMachine\configuration\docker> docker-compose -f docker-compose.infrastructure.local.yml build

Wait for the completion of the containers.
After that, you can begin to deploy the infrastructure.

PS> FarmMachine\configuration\docker> docker-compose -f docker-compose.infrastructure.local.yml up

Also worth noting, docker is not a required link. You can deploy everything on a real host. The minimum list consists of MongoDB and RabbitMQ.

If no errors appear, then the infrastructure is deployed correctly and you can proceed to the next step - to services.

Start services

Before that, you need to configure RabbitMq and MongoDB. Then change the settings appsettings.json for yourself, and after that you can execute these commands

PS> .\farmmachine.ps1 build
Microsoft (R) Build Engine version 16.2.0-preview-19278-01+d635043bd for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 512.73 ms for C:\Users\Winster332\Desktop\FarmMachine\FarmMachine.ExchangeBroker\FarmMachine.ExchangeBroker.csproj.
...
...

PS> .\farmmachine.ps1 start
Begin start FarmMachine.ExchangeBroker
Begin start FarmMachine.MonitorStrategy

After that, the integration service with exchanges should start. If everything went well, a terminal with your settings will appear. And after it, a second service will be launched to monitor the strategy

Configurations

The configuration file is located in FarmMachine/FarmMachine.ExchangeBroker/appsettings.json

{
  "database": { // MongoDB config section
    "dataBaseName": "FarmMachine",
    "connectionString": "mongodb://localhost:27017/"
  },
  "rabbitMq": { // RabbitMQ config section
    "host": "rabbitmq://127.0.0.1/yuor_virtual_host", 
    "concurrencyLimit": 64
  },
  "bittrex": {
    "key": "your_bittrex_key", // Need set your key from bittrex api
    "secret": "your_bittrex_secret", // Need set your secret from bittrex api
    "market": "USD-BTC", // Maker name
    "riskManager": {
      "baseCurrency": "USD", // Your base currency
      "type": "percent", // types risk manager: percent and fixed
      "amount": 0, // for type fixed. Need if you selected type fixed. Fixed amount
      "percent": 100, // // for type percent
      "balanceMinLimit": 15 // minimal balance on you wallet
    }
  },
  "telegram": {
    "enabled": false,
    "apiKey": your_telegram_api_key,
    "apiHash": "your_telegram_api_hash",
    "phoneNumber": "your_phone_number"
  }
}

Logs

All logs are stored in the upper directory Log, and are divided by type of service, and by day.
They look like this:

N|Solid

Integration through RabbitMQ

If you want to use only part of this project. You can easily integrate through the RabbitMQ bus. To do this, you need to connect to the queue

farm_machine

and after that send messages to buy or sell:

FarmMachine.Domain.Commands.Exchange:SellCurrency

public interface BuyCurrency
{
    Guid Id { get; set; }
    DateTime Created { get; set; }
    decimal Amount { get; set; }
    decimal Bid { get; set; }
}

FarmMachine.Domain.Commands.Exchange:BuyCurrency

public interface SellCurrency
{
  Guid Id { get; set; }
  DateTime Created { get; set; }
  decimal Amount { get; set; }
  decimal Ask { get; set; }
}

Links

MassTransit - for RabbitMQ
TradeView - read strategy
Chromium - load and integration with TradeView
Bittrex.Net - for integration with BITTREX API
Binance.Net - for integration with Binance API
Topshelf - run app as service
CQ - html parser
Serilog - logger
Autofac - DI
MongoDB - as load and save documents
TLSharp - telegram integrations

LICENCE

GNU General Public License v3.0