ninjabot

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 13 Imported by: 0

README

image

tests Go Reference

A fast cryptocurrency trading bot framework implemented in Go. Ninjabot permits users to create and test custom strategies for spot markets.

Caution: Working in progress - It's not production ready 🚧

Installation

go get -u github.com/enorith/ninjabot/...

Examples of Usage

Check examples directory:

  • Paper Wallet (Live Simulation)
  • Backtesting
  • Real Account (Binance)

CLI

To download historical data you can download ninjabot CLI from release page

  • Download 30 days: ninjabot download --pair BTCUSDT --timeframe 1d --days 30 --output ./btc.csv

Backtesting Example

  • Backtesting a custom strategy from examples directory:
go run examples/backtesting/main.go

Output:

[SETUP] Using paper wallet                   
[SETUP] Initial Portfolio = 10000.000000 USDT 
+---------+--------+-----+------+--------+--------+------------+
|  PAIR   | TRADES | WIN | LOSS | % WIN  | PAYOFF |   PROFIT   |
+---------+--------+-----+------+--------+--------+------------+
| ETHUSDT |     19 |   9 |   10 | 47.4 % |  6.975 |  6334.1268 |
| BTCUSDT |     17 |   6 |   11 | 35.3 % |  7.734 |  4803.0181 |
+---------+--------+-----+------+--------+--------+------------+
|   TOTAL |     36 |  15 |   21 | 41.7 % |  7.333 | 11137.1449 |
+---------+--------+-----+------+--------+--------+------------+
--------------
WALLET SUMMARY
--------------
0.000000 ETH
0.000000 BTC
21137.144920 USDT
--------------
START PORTFOLIO =  10000 USDT
FINAL PORTFOLIO =  21137.14492013396 USDT
GROSS PROFIT    =  11137.144920 USDT (111.37%)
MARKET CHANGE   =  396.71%

--------------
Chart available at http://localhost:8080

Plot result:

Roadmap:

  • Live Trading

    • Custom Strategy
    • Order Limit, Market, OCO
    • Stop Orders
  • Backtesting

    • Paper Wallet (Live Trading with fake wallet)
    • Load Feed from CSV
    • Market Orders
    • Limit Orders
    • OCO Orders
    • Stop Orders
  • Bot Utilities

    • CLI to download historical data
    • Plot (Candles + Sell / Buy orders)
    • Telegram Notifier
    • Plot Indicators

Exchanges:

Currently, we only support Binance exchange. If you want to include support for other exchanges, you need to implement a new struct that implements the interface Exchange. You can check some examples in exchange directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandleSubscriber

type CandleSubscriber interface {
	OnCandle(model.Candle)
}

type NinjaBot

type NinjaBot struct {
	// contains filtered or unexported fields
}

func NewBot

func NewBot(ctx context.Context, settings model.Settings, exch exchange.Exchange, str strategy.Strategy,
	options ...Option) (*NinjaBot, error)

func (*NinjaBot) OrderController added in v0.0.7

func (n *NinjaBot) OrderController() *order.Controller

func (*NinjaBot) Run

func (n *NinjaBot) Run(ctx context.Context) error

func (*NinjaBot) SubscribeCandle

func (n *NinjaBot) SubscribeCandle(subscriptions ...CandleSubscriber)

func (*NinjaBot) SubscribeOrder

func (n *NinjaBot) SubscribeOrder(subscriptions ...OrderSubscriber)

func (*NinjaBot) Summary

func (n *NinjaBot) Summary()

type Option

type Option func(*NinjaBot)

func WithCandleSubscription

func WithCandleSubscription(subscriber CandleSubscriber) Option

func WithLogLevel

func WithLogLevel(level log.Level) Option

func WithNotifier

func WithNotifier(notifier notification.Notifier) Option

func WithOrderSubscription

func WithOrderSubscription(subscriber OrderSubscriber) Option

func WithStorage

func WithStorage(storage *ent.Client) Option

func WithStrategyController added in v0.0.6

func WithStrategyController(register StrategyControllerRegister) Option

type OrderSubscriber

type OrderSubscriber interface {
	OnOrder(model.Order)
}

type StrategyController added in v0.0.6

type StrategyController interface {
	CandleSubscriber
	Start()
}

type StrategyControllerRegister added in v0.0.6

type StrategyControllerRegister func(pair string, settings model.Settings, strategy strategy.Strategy, broker exchange.Broker) StrategyController

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL