ninjabot

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 17 Imported by: 6

README

Ninjabot

tests codecov Go Reference Discord Discord

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

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

DISCLAIMER
This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS

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[2023-03-25 13:54] [SETUP] Using paper wallet                   
INFO[2023-03-25 13:54] [SETUP] Initial Portfolio = 10000.000000 USDT 
---------+--------+-----+------+--------+--------+-----+----------+-----------+
|  PAIR   | TRADES | WIN | LOSS | % WIN  | PAYOFF | SQN |  PROFIT  |  VOLUME   |
+---------+--------+-----+------+--------+--------+-----+----------+-----------+
| ETHUSDT |      9 |   6 |    3 | 66.7 % |  3.407 | 1.3 | 21748.41 | 407769.64 |
| BTCUSDT |     14 |   6 |    8 | 42.9 % |  5.929 | 1.5 | 13511.66 | 448030.05 |
+---------+--------+-----+------+--------+--------+-----+----------+-----------+
|   TOTAL |     23 |  12 |   11 | 52.2 % |  4.942 | 1.4 | 35260.07 | 855799.68 |
+---------+--------+-----+------+--------+--------+-----+----------+-----------+

-- FINAL WALLET --
0.0000 BTC = 0.0000 USDT
0.0000 ETH = 0.0000 USDT
45260.0735 USDT

----- RETURNS -----
START PORTFOLIO     = 10000.00 USDT
FINAL PORTFOLIO     = 45260.07 USDT
GROSS PROFIT        =  35260.073493 USDT (352.60%)
MARKET CHANGE (B&H) =  407.09%

------ RISK -------
MAX DRAWDOWN = -11.76 %

------ VOLUME -----
BTCUSDT         = 448030.05 USDT
ETHUSDT         = 407769.64 USDT
TOTAL           = 855799.68 USDT
-------------------
Chart available at http://localhost:8080

Plot result

Features

Binance Spot Binance Futures
Order Market 🆗 🆗
Order Market Quote 🆗
Order Limit 🆗 🆗
Order Stop 🆗 🆗
Order OCO 🆗
Backtesting 🆗 🆗
  • Backtesting

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

    • CLI to download historical data
    • Plot (Candles + Sell / Buy orders, Indicators)
    • Telegram Controller (Status, Buy, Sell, and Notification)
    • Heikin Ashi candle type support
    • Trailing stop tool
    • In app order scheduler

Roadmap

  • Include Web UI Controller
  • Include more chart indicators - Details

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.

Support the project

Address
BTC bc1qpk6yqju6rkz33ntzj8kuepmynmztzydmec2zm4
ETH 0x2226FFe4aBD2Afa84bf7222C2b17BBC65F64555A
LTC ltc1qj2n9r4yfsm5dnsmmtzhgj8qcj8fjpcvgkd9v3j

Patreon: https://www.patreon.com/ninjabot_github

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

Run will initialize the strategy controller, order controller, preload data and start the bot

func (NinjaBot) SaveReturns added in v0.3.6

func (n NinjaBot) SaveReturns(outputDir string) 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()

Summary function displays all trades, accuracy and some bot metrics in stdout To access the raw data, you may access `bot.Controller().Results`

type Option

type Option func(*NinjaBot)

func WithBacktest added in v0.0.9

func WithBacktest(wallet *exchange.PaperWallet) Option

WithBacktest sets the bot to run in backtest mode, it is required for backtesting environments Backtest mode optimize the input read for CSV and deal with race conditions

func WithCandleSubscription

func WithCandleSubscription(subscriber CandleSubscriber) Option

WithCandleSubscription subscribes a given struct to the candle feed

func WithLogLevel

func WithLogLevel(level log.Level) Option

WithLogLevel sets the log level. eg: log.DebugLevel, log.InfoLevel, log.WarnLevel, log.ErrorLevel, log.FatalLevel

func WithNotifier

func WithNotifier(notifier service.Notifier) Option

WithNotifier registers a notifier to the bot, currently only email and telegram are supported

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

WithPaperWallet sets the paper wallet for the bot (used for backtesting and live simulation)

func WithStorage

func WithStorage(storage storage.Storage) Option

WithStorage sets the storage for the bot, by default it uses a local file called ninjabot.db

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[float64]

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