GitHub – lgalabru/gotrading: Golang library for trading on crypto-exchanges


First, we need to instanciate the EC2 or gatling, that will be responsible for fetching the quotes and sending orders (ideally one per exchange). This node needs to be in the same / nearest datacenter hosting the exchange (ap-northeast-1a for Binance), in order to limit latency.

The configuration of this node is a bit special: we will be attaching as many Virtual Network Interfaces as possible (2 for a t2-micro), and attaching as many Elastic IP as possible (2 EIP / VNI for t2-micro).

This part of the project is managed with Terraform (also in a separate repo, open a new issue if you’re interested):

module “binance” {
source = “../modules/instances/worker”

instance_type = “t2.micro”
ami = “ami-12572374”

network_interfaces_count = 2
ips_per_network_interface = 2

availability_zone = “ap-northeast-1a”

Thanks to this tuning, instead of having our worker being limited to 5 req/sec, we can have 20 req/sec, and we could theoritically scale this limit to 3,750 req/sec with a c5d.18xlarge.

This parameter is important, since the first strategy implemented is an arbitrage using 3 quotes on one exchange (ex: BTC→ETH, ETH→TRX, TRX→BTC).
By fetching the 3 quotes 6 times per seconds, we are more reactive than the users getting the quotes using the websocket API.

How to use

This project is designed in layers free of inter-dependencies, and you should be able to be used as a library.

core: types required for modelizing the space (Currency, Pair, Orderbook, etc)

networking: mainly abstracting the concept of gatling

graph: utils for manipulating the graph of pairs available on one exchange.

exchanges: where new exchanges should be added

You can also definitely have a look at the code available in ./strategies, to have a better of how everything can be orchestrated.


You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *