rodrigo-brito / ninjabot

A fast trading bot platform for cryptocurrency in Go (Binance)
https://rodrigo-brito.github.io/ninjabot/
MIT License
1.37k stars 173 forks source link

Futures support #106

Closed andreimerfu closed 1 year ago

andreimerfu commented 2 years ago

Do you have any plan to add support for Binance futures in the near future? Thanks!

rodrigo-brito commented 2 years ago

Hi @andreimerfu, I am planning to support Binance Futures. But this will take a while. I'm working alone on the project.

andreimerfu commented 2 years ago

Let me know how I can help with this feature. I'm not sure how do you want to include this feature in the current codebase. I'm wondering how we can change the Balance struct by using terms like Wallet Balance, Margin Balance, and Unrealized PNL without damaging the SPOT market. Also, I'm not sure where we'll introduce the leverage details for each asset.

Any feedback, ideas from your side will be helpful. Thanks! 🙇🏻

rodrigo-brito commented 2 years ago

I do not have any idea yet. The logic is more complex for Futures Market. Maybe we can split in different brokers. Split the wallets and exchanges into two different kinds. The backtesting is more complex too. The project needs a big refactoring for this feature.

rodrigo-brito commented 2 years ago

@andreimerfu we can create a new branch to explore some ideias, what you think?

rodrigo-brito commented 2 years ago

Currently, this is the structure of the bot image

We can use all the structure of Data Feeds, Order Feeds, Plugins and Storage.

We have to modify controllers and exchange modules. The exchange is an interface composed by two parts

When we are in a backtesting, we use Broker = Paperwallet, Feeder = CSV Feeder When we are in a simulation with live data, we use Broker = Paperwallet, Feeder = Binance When we are in production environment, we user Broker = Binance, Feeder = Binance

Theses abstractions helps to create different scenarios.

All the orders and candles are transmitted with pub-sub pattern in "feeds". For exemple, the chart moduele receives candles and orders, then it requires a subscription in OrderFeed and DataFeed.

The concept is simple, but we have a big issue with the leverage token and isolation of wallets.

rodrigo-brito commented 1 year ago

Now we have a testnet for futures market, it will be great in the module implementation: https://testnet.binancefuture.com/en/futures/BTCUSDT

rodrigo-brito commented 1 year ago

Initial support available

binance, err := exchange.NewBinanceFuture(ctx,
    exchange.WithBinanceFutureCredentials(cfg.BinanceKey, cfg.BinanceSecret),
)