stav / kingbot

Deno CLI trading robot
https://stav.github.io/kingbot/
2 stars 0 forks source link
trading-bot

K1NGBOT

This is a Deno command line application that

Currently the only exchange supported is XTB's XStation 5 appliance via websocket connections.

1.0

The kingbot Proof-of-concept started early October 2021 and within a month it was moving the Break-even on the exchange by:

  1. grouping multi-order positions into "families",
  2. listening for Take-profit events,
  3. moving the Stop-loss for all orders in the family to slightly better than the entry.

We began trading with real money in December, the worst month.

2.0

Kingbot 2.0 is a rewrite of the code switching the execution engine from Node.js to 🦕Deno. It started in December 2021. The plan is to have it in production come the spring with the following features:

With these features the bot can theoretically run fully-automatically.

Components

  1. Bot written in TypeScript
  2. Telegram client written in Python
  3. Log file tools written in Rust

Installation

The Kingbot uses these components:

Install Deno

Deno works on macOS, Linux, and Windows. Deno is a single binary executable. It has no external dependencies.

On Linux use cURL to download the installation script and run it in a shell:

curl -fsSL https://deno.land/x/install/install.sh | sh

For other platforms see the installation page.

Script Runner

Velociraptor makes it easy to run scripts.

Install Velociraptor:

deno install -qAn vr https://deno.land/x/velociraptor@1.4.0/cli.ts

Add Bash completion:

source <(vr completions bash)

Install the Kingbot

Deno doesn't use any package management files in the project. Modules are cached when they are first encountered in the code; therefore, the bot doesn't need to be installed. Just clone the repository:

git clone git@github.com:stav/kingbot.git
cd kingbot

Configuration

Edit the file .config/exchange.example.yaml with your real information and save it as .config/exchange.yaml.

Edit the file .config/telegram.example.yaml with your real information and save it as .config/telegram.yaml.

Usage

The Telegram client and server are currently decoupled. The server is able to be started from the main deno application but the client must be started manually.

Start the Application

Open a new command-line terminal.

Make sure you are in the kingbot directory.

Start the deno runtime with Velociraptor.

vr start

You will spawn an interactive Kingbot interpreter:

0[-]>

The prompt shows:

The exchange account index number currently active:

0

Zero (0) index is the Telegram connection.

The prompt also shows the login status of current connection surrounded by square brackets.

Dash (Telegram not connected):

[-]

Finally, the greater-than input pointer character

>

Start the Telegram Server

The Telegram server listens to HTTP traffic on localhost port 8000.

Enter the connect command to start the server:

0[-]> connect
input "connect" (function) [Function: bound connect]
Listening to localhost:8000 for { id:123456, name:"Demo", type:"demo" }

0[C]>

Send EOF (Ctrl-D End-of-file) to exit.

Start the Telegram Client

Open a second command-line terminal.

Make sure you are in the kingbot directory.

Start the Python script to listen to configured Telegram chats.

vr pyx

Connection to 149.154.175.52:443/TcpFull complete!

Please enter your phone (or bot token): +12345678901

Disconnection from 149.154.167.51:443/TcpFull complete!
Connection to 149.154.175.52:443/TcpFull complete!
Please enter the code you received: 12345
Signed in successfully

Send Interupt signal (Ctrl-C) to exit.

Tools

See the tools documentation to learn how to analyze the log files.

Development

Documentation

Coverage

deno test -A --import-map=denoPaths.json --coverage=coverage

deno coverage coverage
deno coverage coverage |grep '100.000%'
deno coverage coverage |grep 'cover file'

Dependency Debugging

# cache dependencies locally
DENO_DIR=$PWD/deno deno test tests/profits.test.ts -A --import-map=denoPaths.json

# query the location of the dependency file in question
DENO_DIR=$PWD/deno deno info --unstable https://deno.land/x/rhum@v1.1.12/src/mock_builder.ts