Code Monkey home page Code Monkey logo

trader's Introduction

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.

trader's People

Contributors

long2ice avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.