Trader is a framework that automated cryptocurrency exchange with strategy

Related tags

Cryptography trader
Overview

Trader

kline

Introduction

Trader is a framework that automated cryptocurrency exchange with strategy.

Disclaimer: The profit and loss is yourself when use this framework!

Features

  • Current support spot/future of binance, more exchange work in progress.
  • Easy write your own strategy.
  • Back test engine support to test your strategy.

Quick Start

Write Strategy

Just see examples

Inherit strategy.Base

package strategy

type UpDownRate struct {
	strategy.Base
}

Implement OnConnect and On1mKline, or OnTicker.

package strategy

func (s *UpDownRate) OnConnect() {
	// you can do something initialization here.
}

func (s *UpDownRate) On1mKline() {
	// here you can buy or sell order depending on 1m kline.
}

Back test strategy

The result will store in orders table in database.

package tests

func TestUpDownRate(t *testing.T) {
	conf.InitConfig("config.yml")
	eng := (*engine.GetEngine(exchange.Mock, conf.BinanceApiKey, conf.BinanceApiSecret)).(*engine.Mock)
	BaseAsset := "ETH"
	QuoteAsset := "USDT"
	symbol := BaseAsset + QuoteAsset
	h, _ := time.ParseDuration("-48h")
	eng.Exchange.(*mock.Mock).StartTime = time.Now().Add(h)
	eng.Exchange.(*mock.Mock).EndTime = time.Now()
	eng.Exchange.(*mock.Mock).Symbol = symbol

	eng.RegisterStrategy(&UpDownRate{
		KLineLimit: 10,
		Rate:       decimal.NewFromInt(6).Div(decimal.NewFromInt(4)),
		Base: strategy.Base{
			Streams:    []string{strings.ToLower(symbol) + "@kline_1m"},
			FundRatio:  decimal.NewFromFloat(1),
			StopProfit: decimal.NewFromFloat(0.02),
			StopLoss:   decimal.NewFromFloat(0.06),
			BaseAsset:  BaseAsset,
			QuoteAsset: QuoteAsset,
			Exchange:   eng.Exchange,
		}},
	)
	eng.Start(false)
}

Run strategy

After test strategy, and it's effective, that's the time to run it.

package main

func main() {
	conf.InitConfig("config.yml")
	eng := (*engine.GetEngine(exchange.BinanceSpot, conf.BinanceApiKey, conf.BinanceApiSecret)).(*engine.Engine)
	eng.RegisterStrategy(&UpDownRate{
		KLineLimit: 10,
		Rate:       decimal.NewFromInt(6).Div(decimal.NewFromInt(4)),
		Base: strategy.Base{
			FundRatio:  decimal.NewFromFloat(1),
			StopProfit: decimal.NewFromFloat(0.02),
			StopLoss:   decimal.NewFromFloat(0.06),
			BaseAsset:  "ETH",
			QuoteAsset: "USDT",
			Exchange:   eng.Exchange,
			Streams:    []string{"ethusdt@kline_1m", "ethusdt@miniTicker"},
		}},
	)
	eng.Start(true)
}

Back test

Trader has a back test engine, for that you can test your strategy.

backtest

Config

Copy config.example.yaml to config.yaml then update it, and current use MySQL.

You can get other custom config by viper.GetString() etc, see viper framework for more details.

Run trader

Also see examples.

INFO[0001] Get account balances success                  balances="[{BTC 0.00000092 0} {ETH 0.0000053 0} {USDT 111.51295105 0} {BUSD 0.00914978 0}]"
INFO[0001] Register strategy success                     strategy=UpDownRate
INFO[0002] Subscribe account success                    
INFO[0005] Subscribe market data success                 streams="[ethusdt@kline_1m ethusdt@miniTicker]"
INFO[0005] Start trader success   

You can earn BTC and ETH when sleep now!

License

This project is licensed under the Apache-2.0 License.

You might also like...
This project was builded to improve my knowledge about blockchain and cryptocurrency

Blockchain Hello World in GoLang This project was builded to improve my knowledge about blockchain and cryptocurrency. To build this project, I've fol

Quoter - Get real-time Cryptocurrency quotes via CoinMarketCap

quoter Get real-time Cryptocurrency quotes via CoinMarketCap. Get it go get -u g

An easy-to-use XChaCha20-encryption wrapper for io.ReadWriteCloser (even lossy UDP) using ECDH key exchange algorithm, ED25519 signatures and Blake3+Poly1305 checksums/message-authentication for Go (golang). Also a multiplexer.

Quick start Prepare keys (on both sides): [ -f ~/.ssh/id_ed25519 ] && [ -f ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 scp ~/.ssh/id_ed25519.pub

Simple, fast and safe cross-platform linear binary stream communication protocol. AES key exchange based on ecc secp256k1

FFAX Protocol 2 dev 简体中文 Welcome to FFAX Protocol v2 Quick start go get github.com/RealFax/FFAX func example() { listener, err := net.Listen("tcp",

Diffie Hellman Exchange - A Generic Transport Upgrader Implementation

Diffie Hellman Exchange A simple but fastidious attempt to write a diffie-hellman key exchange utility that could be used as transport upgraders in di

Peer-to-peer encrypted message exchange

Constellation Constellation is a self-managing, peer-to-peer system in which each node: Hosts a number of NaCl (Curve25519) public/private key pairs.

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Yu is a highly customizable blockchain framework.
Yu is a highly customizable blockchain framework.

禹 Yu is a highly customizable blockchain framework. 中文文档 Overall Structure Introduction By using Yu, you can customize three levels to develop your ow

Releases(ATK-3.2.0)
A blockchain-based demo that shows an alternative strategy for ensuring data and log integrity on aircraft

A blockchain-based demo that shows an alternative strategy for ensuring data and log integrity on aircraft. (Coded in less than 24 hours for GunnHack)

sckzor 0 Feb 6, 2022
Community-run technology powering the cryptocurrency, and decentralized applications on TrustFi Network

Go TrustFi-Ethereum Official Golang implementation of the TrustFi-Ethereum protocol. Automated builds are available for stable releases and the unstab

TrustFi Network 786 May 26, 2021
SwissWallet is a deterministic cryptocurrency wallet generator heavily based on MindWallet and MemWallet

SwissWallet SwissWallet is a deterministic cryptocurrency wallet generator heavily based on MindWallet and MemWallet but using argon2 and scrypt by de

vortex.live 7 Jul 28, 2022
Arbitrum is a Layer 2 cryptocurrency platform that makes smart contracts scalable, fast, and private.

Arbitrum is a Layer 2 cryptocurrency platform that makes smart contracts scalable, fast, and private. Arbitrum interoperates closely with Ethereum, so Ethereum developers can easily cross-compile their contracts to run on Arbitrum. Arbitrum achieves these goals through a unique combination of incentives, network protocol design, and virtual machine architecture.

Offchain Labs 1k Jan 8, 2023
A Golang cryptocurrency trading API & Library. Support Binance, BitMEX, Deribit, Bybit, Huobi DM, OKEX Futures and more.

CREX 中文 | English CREX 是一个用Golang语言开发的量化交易库。支持tick级别数字币期货平台的回测和实盘。实盘与回测无缝切换,无需更改代码。 回测 示例 @backtest 交易结果 开源策略 https://github.com/coinrust/trading-stra

Paranoid 4 Nov 18, 2022
A decentralized, cryptocurrency platform that can change this world!

Go Detonus Official Golang implementation of the Detonus protocol. Building the source For prerequisites and detailed build instructions please read t

Detonus (DT) 3 Oct 19, 2021
🍕 PizzaCoin - cryptocurrency for buying and selling pizza or another stuff

?? PizzaCoin Cryptocurrency for buying and selling pizza or another stuff Installation Compilation Windows go build -o pizzacoin.exe ./cmd/PizzaCoin/m

PizzaNode 1 Nov 21, 2021
Example of a cryptocurrency portfolio balancer with Ninjabot

Ninjabot Portfolio Balancer Example of strategy that balances a given portfolio with weights. Related Discussion: https://github.com/rodrigo-brito/nin

Rodrigo Brito 4 Jan 8, 2022
A cryptocurrency implementation in less than 1500 lines of code

Naivecoin - a cryptocurrency implementation in less than 1500 lines of code Motivation Cryptocurrencies and smart-contracts on top of a blockchain are

Conrado Quilles Gomes 1.1k Dec 11, 2022
Monero: the secure, private, untraceable cryptocurrency

Monero Copyright (c) 2014-2021 The Monero Project. Portions Copyright (c) 2012-2013 The Cryptonote developers. Table of Contents Development resources

The Monero Project 7.5k Jan 2, 2023