ninjabot

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 15 Imported by: 6

README

image

tests codecov Go Reference

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

Documentation: https://rodrigo-brito.github.io/ninjabot/

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

Installation

go get -u github.com/rodrigo-brito/ninjabot/...

Examples of Usage

Check examples directory:

  • Paper Wallet (Live Simulation)
  • Backtesting (Simulation with historical data)
  • Real Account (Binance)

CLI

To download historical data you can download ninjabot CLI from:

  • Pre-build binaries in release page
  • Or with go install github.com/rodrigo-brito/ninjabot/cmd/ninjabot@latest

Example of usage

# Download candles of BTCUSDT to btc.csv file (Last 30 days, timeframe 1D)
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:

INFO[2021-09-29 00:00] [SETUP] Using paper wallet                   
INFO[2021-09-29 00:00] [SETUP] Initial Portfolio = 10000.000000 USDT 
finished
+---------+--------+-----+------+--------+--------+----------+-----------+
|  PAIR   | TRADES | WIN | LOSS | % WIN  | PAYOFF |  PROFIT  |  VOLUME   |
+---------+--------+-----+------+--------+--------+----------+-----------+
| BTCUSDT |     17 |   6 |   11 | 35.3 % |  7.038 |  7424.37 | 250246.73 |
| ETHUSDT |     17 |   9 |    8 | 52.9 % |  7.400 |  9270.30 | 168350.93 |
+---------+--------+-----+------+--------+--------+----------+-----------+
|   TOTAL |     34 |  15 |   19 | 44.1 % |  7.219 | 16694.67 | 418597.66 |
+---------+--------+-----+------+--------+--------+----------+-----------+

--------------
WALLET SUMMARY
--------------
0.000000 ETH
0.000000 BTC

TRADING VOLUME
ETHUSDT        = 185030.63 USDT
BTCUSDT        = 255182.59 USDT

26694.674186 USDT
--------------
START PORTFOLIO =  10000 USDT
FINAL PORTFOLIO =  26694.674186473057 USDT
GROSS PROFIT    =  16694.674186 USDT (166.95%)
MARKET CHANGE   =  420.18%
VOLUME          =  440213.22 USDT
COSTS (0.001*V) =  440.21 USDT (ESTIMATION) 
--------------
Chart available at http://localhost:8080

Plot result:

Features:

  • Live Trading

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

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

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

Roadmap

  • Include trailing stop tool
  • Stop Orders in backtesting

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

View Source
var (
	SideTypeBuy                    = model.SideTypeBuy
	SideTypeSell                   = model.SideTypeSell
	OrderTypeLimit                 = model.OrderTypeLimit
	OrderTypeMarket                = model.OrderTypeMarket
	OrderTypeLimitMaker            = model.OrderTypeLimitMaker
	OrderTypeStopLoss              = model.OrderTypeStopLoss
	OrderTypeStopLossLimit         = model.OrderTypeStopLossLimit
	OrderTypeTakeProfit            = model.OrderTypeTakeProfit
	OrderTypeTakeProfitLimit       = model.OrderTypeTakeProfitLimit
	OrderStatusTypeNew             = model.OrderStatusTypeNew
	OrderStatusTypePartiallyFilled = model.OrderStatusTypePartiallyFilled
	OrderStatusTypeFilled          = model.OrderStatusTypeFilled
	OrderStatusTypeCanceled        = model.OrderStatusTypeCanceled
	OrderStatusTypePendingCancel   = model.OrderStatusTypePendingCancel
	OrderStatusTypeRejected        = model.OrderStatusTypeRejected
	OrderStatusTypeExpired         = model.OrderStatusTypeExpired
)

Functions

This section is empty.

Types

type CandleSubscriber

type CandleSubscriber interface {
	OnCandle(model.Candle)
}

type Dataframe added in v0.0.7

type Dataframe = model.Dataframe

type NinjaBot

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

func NewBot

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

func (*NinjaBot) Controller added in v0.0.6

func (n *NinjaBot) Controller() *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() string

type Option

type Option func(*NinjaBot)

func WithBacktest added in v0.0.9

func WithBacktest(wallet *exchange.PaperWallet) Option

func WithCandleSubscription

func WithCandleSubscription(subscriber CandleSubscriber) Option

func WithLogLevel

func WithLogLevel(level log.Level) Option

func WithNotifier

func WithNotifier(notifier service.Notifier) Option

func WithOrderSubscription added in v0.0.2

func WithOrderSubscription(subscriber OrderSubscriber) Option

func WithPaperWallet added in v0.0.7

func WithPaperWallet(wallet *exchange.PaperWallet) Option

func WithStorage

func WithStorage(storage storage.Storage) Option

type OrderStatusType added in v0.0.7

type OrderStatusType = model.OrderStatusType

type OrderSubscriber

type OrderSubscriber interface {
	OnOrder(model.Order)
}

type OrderType added in v0.0.7

type OrderType = model.OrderType

type Series added in v0.0.7

type Series = model.Series

type Settings added in v0.0.7

type Settings = model.Settings

type SideType added in v0.0.7

type SideType = model.SideType

type TelegramSettings added in v0.0.7

type TelegramSettings = model.TelegramSettings

Jump to

Keyboard shortcuts

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