KungFu Setup

This note is for setting up KungFu trading platform on Linux. KungFu is an open source project by Taurus.ai

KungFu is running on a Linux environment, and the opearting system prefers CentOS. Once you setup the system, you may move forward.

First install docker:

1
2
3
$ sudo yum install docker
$ sudo systemctl start docker
$ sudo systemctl status docker

From here you could see details about the docker

1
2
3
4
5
6
7
8
docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-03-15 12:34:55 +08; 6s ago
Docs: http://docs.docker.com
Main PID: 71053 (dockerd-current)
CGroup: /system.slice/docker.service
├─71053 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-r...
└─71076 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --me...

Then pull the image of KungFu

1
$ sudo docker pull image.taurusai.com/library/kungfu-devel

Then activate the docker container/image

1
$ sudo docker run --name kungfu-devel --privileged --ulimit memlock=-1 --net=host -td taurusai/kungfu-devel /usr/sbin/init

After this you could us $ sudo docker ps -ato check:

1
2
3
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
141880c19eb3 taurusai/kungfu-devel "/usr/sbin/init" 7 seconds ago Up 3 seconds kungfu-devel

The next step is to get into the container/image:

1
$ sudo docker exec -it kungfu-devel bash

Once you are inside the container, Clone kungfu code from github and do the following compile job:

1
2
3
4
5
6
7
$ git clone https://github.com/taurusai/kungfu
$ cd kungfu
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make package

It takes a while to compile…

After make package I recommend to use ls command to see what is inside the folder. Here we find rpm file and its latest version: kungfu-0.0.5-Linux.rpm

1
2
3
4
5
6
CPack: Create package
CPackRPM: Will use GENERATED spec file: /kungfu/build/_CPack_Packages/Linux/RPM/SPECS/kungfu.spec
CPack: - package: /kungfu/build/kungfu-0.0.5-Linux.rpm generated.
[root@localhost build]# ls
CMakeCache.txt CPackConfig.cmake Makefile cmake_install.cmake kungfu-0.0.5-Linux.rpm rpm yijinjing
CMakeFiles CPackSourceConfig.cmake _CPack_Packages install_manifest.txt longfist wingchun

Then we install this rpm

1
[root@localhost build]# yum install kungfu-0.0.5-Linux.rpm

Ok if it shows compelete, we can check the status of Kungfu:

1
2
3
4
5
6
7
8
[root@localhost /]# sudo systemctl status kungfu
* kungfu.service - Kungfu Master Trading System Daemon
Loaded: loaded (/etc/systemd/system/multi-user.target.wants/kungfu.service)
Active: active (running) since Thu 2018-03-15 15:36:39 CST; 3s ago
Process: 1460 ExecStart=/usr/bin/supervisord -c /opt/kungfu/master/etc/supervisor/supervisord.conf (code=exited, status=0/SUCCESS)
Main PID: 1463 (supervisord)
CGroup: /system.slice/docker-5f80f25d46a4bd5fe8fa9df4b550f13f33e046788544ad0e5df01a8114aff35c.scope/system.slice/kungfu.service
`-1463 /usr/bin/python /usr/bin/supervisord -c /opt/kungfu/master/etc/supervisor/supervisord.conf

If the Active option shows inactive, just input sudo systemctl start kungfu. Now the environment has established.

If you already install KungFu on your system, everytime you follow those steps:

1
2
3
4
5
$ sudo systemctl start docker
$ sudo docker start kungfu
$ sudo docker exec -it kungfu bash
$ sudo systemctl start kungfu
$ sudo systemctl status kungfu

Then edit your account info

1
2
$ cp /opt/kungfu/master/etc/kungfu/kungfu.json.sample /opt/kungfu/master/etc/kungfu/kungfu.json
$ vi /opt/kungfu/master/etc/kungfu/kungfu.json

Press “o” to edit, then “ESC” and :wq
:wq means save and quit.
Go to SimNow to creat your account and replace them here.
Now hope you can run kungfuctl and kungfuctl>status to see more details.

1
2
3
4
5
6
7
8
kungfu> start md_ctp
md_ctp: started
kungfu> status
md_ctp RUNNING pid 212, uptime 0:00:17
md_xtp STOPPED Not started
td_ctp STOPPED Not started
td_xtp STOPPED Not started
yijinjing RUNNING pid 193, uptime 0:05:02

To run your strategy:

1
sudo -u bruce wingchun strategy -n band_demo -p /your/path/band_demo_strategy.py

Other useful commands for KungFu:

1
2
wingchun report -n XXXX(stratName) -t  # Show Latency
yjj status # Show system background status

Referrence

https://github.com/taurusai/kungfu

Some useful commands about dockers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$ sudo docker

Usage: docker COMMAND

A self-sufficient runtime for containers

Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to (default [])
-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit

Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes

Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes