Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Ninjabot – A fast cryptocurrency bot implemented in Go (github.com/rodrigo-brito)
107 points by rodrigobrito on May 21, 2021 | hide | past | favorite | 55 comments


I warmly recommend the book Systematic Trading by Robert Carver. [1]

The perils of trading bots are explained in it. The author himself runs one for a long time. [2]

In particular, the greatest risks are overtrading (so you get eaten up by fees), and overexposure (so you get eaten up by volatility).

[1] - https://www.systematicmoney.org/systematic-trading

[2] - https://qoppac.blogspot.com/2021/04/trading-and-investing-pe...


Bitcoin averaged 300% returns YoY the past decade (most other crypto followed to a degree, or did similar or better - with some doing worse).

Anyone looking for a trading strategy, automated or not, needs to consistently beat such numbers to do anything other than lose money versus just buying and holding.

Given prior (lack of) success in every other market this kind of thing has been attempted, makes this a hugely tall-order. The most successful quant firms all average well under 100% returns, even with years of experience, armies of experts, and loads of investment in assets and infrastructure.

Buying and holding crypto already outdoes them (massively). Why take on greater risk and spend time to try and get yet more out of such a market?


If you are confident that these returns will continue, I’d happily loan you a couple of million at 50% interest rate, so you can buy even more crypto. (Of course, I’ll take your crypto as collateral).


I'll do you a deal:

Put 5% of that 2 million into a spread of the top 10 crypto by market cap.

After a few years, and despite some of those coins going to zero, you'll likely have done way better than just the 50% you'd have got from me.

If you don't though and it all goes to zero, you only lost 5%, as opposed to the entire 2 million to a random person you met on the internet.

You're welcome.


Yeah, HODLing is underappreciated. I once tried mining, a long time ago. Dumped $5k in mining equipement and, at the time, barely broke even. Had I bought and held, instead of wasting countless hours on the project, I would've been way better off.

Then again, I did have the somewhat limited foresight to keep ~33% of what I've mined in crypto form so not a total loss ;)


Same here. Former miner. Wish I bought coins instead. It worked out ok in the end though because I learned pretty quick. :)


Time in the market always beats timing the market.


I like that!


If those are the greatest risks, it sounds like it's easy to buy low and sell high. I would have thought that that's the biggest challenge.


Well it kinda is.

Empirically, you could have bought a share of the SPX at any point in time, and sold it with profit later. The real problem is what happened in the time between, and whether you were able to hold on.


You can buy shares in an index?


You can buy shares in an ETF (exchange-traded fund) that tracks an index (buys and sells to attempt to keep exposure the same as the index).


what does this have to do with OP's post? Does the book directly contradict OP's work


This is trading cryptocurrencies, so the actual greatest risks are: Exchanges frontrunning you and manipulating the market, exchanges just taking your money and running, prices crashing without you being able to sell your assets, and all kinds of other stuff.

Cryptocurrency is NOT a market you want to be in.


As someone who been in the cryptocurrency market since ~2015, it's possible to be in that market without actually encountering any of those problems (I've never had those issues for example).

Except the market manipulation, that'd be hard for me to see. It's also a kind of extraordinary claim, so please provide some extraordinary proofs that there actually is manipulation.

Cryptocurrency is a market that everyone should be in, it is after all created for and by everyone. Be careful of putting in money you really need though, and see it as gambling more than anything.


"Except the market manipulation, that'd be hard for me to see. It's also a kind of extraordinary claim, so please provide some extraordinary proofs that there actually is manipulation."

I guess that depends on your priors. Given the nature of the market, its opacity, its lack of regulation, the sheer proliferation of the number of cryptocurrencies, the growing interest by large entities like hedge funds with a history of active manipulation, I'd personally consider it the extraordinary claim that there isn't manipulation occurring. Like, if I were to set out to design a fertile ground for manipulations, it would pretty much look like the cryptocurrency space.


So... You want people to provide proof that the cryptocurrency market isn't manipulated? That feels slightly backwards. Usually we want to have proof that something is happening, not proof that something is not happening.

And since you also claim it's do easy to manipulate, wouldn't it be easier to provide proof of this?

When thinking about it, i'm not even sure how I could provide any evidence that it isn't manipulated... Any ideas?

> Like, if I were to set out to design a fertile ground for manipulations, it would pretty much look like the cryptocurrency space.

One tip for your future scam-network: don't design your entire ecosystem around the idea that you want to have a forever-stored global ledger of all the transactions, as it'll be easy to trace everything whenever. Better to have a few entities controlling the ecosystem that the public don't have insight into.


"You want people to provide proof that the cryptocurrency market isn't manipulated?"

That's not what "priors" mean. It simply means that based on my experience of the world and my understanding, I would very heavily assume it is being manipulated. I'm not asking for anything. I already have a solid opinion. If you choose to try to disagree with that with solid evidence, feel free, but I'm not asking you to.

"don't design your entire ecosystem around the idea that you want to have a forever-stored global ledger of all the transactions, as it'll be easy to trace everything whenever. Better to have a few entities controlling the ecosystem that the public don't have insight into."

I think that counts for a lot less than you probably do. Nationstates may be able to back wallets to individual entities, but you and I can not in general. Moreover, I wasn't just talking about BitCoin. Some of the cryptos are even more impenetrable than that.


> I already have a solid opinion. If you choose to try to disagree with that with solid evidence, feel free, but I'm not asking you to.

So I guess you see Hacker News as your platform to share your opinions without wanting to discuss them at all? You might want to refine how you use Hacker News then, as when commenting, it seems that you want to discuss. But since it's clear you do not, maybe it's more appropriate you create a blog and then submit the posts here?

In these days of misinformation, it sucks that people feel like it's fine to write "Exchanges frontrunning you and manipulating the market" without any sort of evidence and when challenged for the evidence, the rebut is "you don't have to believe me and I already believe in what I believe". In particular, it's not the kind of content I hope to see on HN, where many people are open to both providing evidence of their claims and also open to listen to others.


> Exchanges frontrunning you and manipulating the market

This should not be a concern, just don't HFT your trades. Play longer time-frames (like a few months between a buy and sell); and don't use leverage.

> exchanges just taking your money and running

There are many established/regulated exchanges which have guarantees as good as the traditional exchanges.

> prices crashing without you being able to sell your assets

Maybe that's when you should buy?

> Cryptocurrency is NOT a market you want to be in.

I have been in this market for 6 years, and I was able to generate double digit yields every year (even on bear markets, actually these were the most profitable).


Beauty is in the eye of the beholder.

- Frontrunning and market manipulations are as many opportunities: the game for small players is to detect occurrences and free ride them. In clear markets there's no opportunity left in fast trading for anyone without access to institutional fee structures.

- Exchanges doing a runner: diversification and gross (not net) leverage can mitigate that.

- Price crashing: be short-only or market neutral (long=short) if need be.


I'm the CTO of a crypto hedge fund since 2014. If you are newb and want to start working with bots/algos/signals; I must advice you that when I started on early 2014, it was already late for deploying HFT. Also you compete against the frontrunning happening inside the exchanges, so traditional finance tools don't translate to crypto very well. Took me between 4-6 years to refine a valid strategy that is able to move thousands of coins at the same time and beat the crypto market on any condition. This is probably one of the hardest thing I ever did. So if you expect to make money with open source, algos, strategies, you still very far from the objective.


Our PHD quant spent his first 5 years at a prop shop, 7 years at CME, 5 at Trading Technologies before consulting. He said it took him his entire career to realize that the name of the game is risk management, not seeking alpha. Happy to pay his $500/hr for lessons learned. Worth his weight in gold.


It's funny, I played around on the platform kryll.io for some time. It's a place where you can use decision blocks in a drag and drop manner to compose strategies.

They have a marketplace where people can share strategies, etc.

The marketplace always shows these massive returns, like "30% over the last week on BTC/USDT". Nowhere do they make it clear that this includes the natural evolution of the market (lol). Worse, if a bot / strategy works for many different pairs, it cherry-picks the one that happened to have good returns that week.

So far as I can tell, there are no strategies on the entire platform that outperform a bull market and in a bear market the strategies were always way too slow to pick up on things crashing.

It turned into a gigantic pyramid-scheme style scam, where the fanciest imagery / language for your BS strategy was what determined how many people ended up using it. Of course you get a cut of the user's fees paid for trading.

Honestly, the whole crypto-trading world seems incredibly dishonest.

If kryll actually had a working product, they would advertise gains above the natural evolution of the market and gains in bear markets.

They would also only charge fees on strategy profits. They do neither.

Another issue I ran into quickly, is the incredibly opaque fee model of many exchanges.

Take Binance: They will tell you the fees you paid for the last 3 months only, there is no place anywhere in the app or the website where they just tell you your cumulative spend on fees. And the 3 month fee CSV you can download has the fees in the cryptos traded, using their value AT THE TIME OF TRADING. So if you want to figure out the fees you paid, you have to build a thing that back-traces what a given crypto was worth at the time and calculate it from that.

With bot-trading, I can tell you that that gets real complicated real quick.

It's such a shame that so much of the crypto world relies on people being uninformed. I myself am a huge crypto fan and have done well just by holding. Trading hasn't worked out for me yet. I remain skeptical it ever will.


> It's such a shame that so much of the crypto world relies on people being uninformed.

You can extend that take to almost all of DeFi yield farming as well. APYs almost always rely either on a greater fool buying the useless governance tokens (which almost always trend down in price), or on late-comers paying entrance/exit taxes to early entrants. That's without even going into the tokens whose central mechanics are merely about disguising Ponzi schemes (Fei, Safemoon, Hex, to name only the billion dollar+ ones).

I'm also a die-hard crypto fan, but having to constantly look out for Ponzis around every corner is tiring.


The elephant in the room with DeFi is always the underlying asset. It’s like being your own bank (but only if your bank vaporizes your balance every so often).


> but only if your bank vaporizes your balance every so often

What you mean here exactly? I've been doing DeFi stuff for almost a year (Ethereum) and my "balance" has never been "reset". You must be doing something very wrong if that keeps happening to you.


There is the risk of impermanent loss with providing liquidity and the risk of the underlying asset. Thinking this is anything like a bank account is a big mistake.


Sure, risks exist everywhere. But you claimed "but only if your bank vaporizes your balance every so often" which when read seems to indicate that your balance gets reset randomly/at a set interval, which couldn't be further from the truth.

Also, no one ever said DeFi is like a normal bank account. In fact, the biggest feature of cryptocurrencies and DeFi is exactly that it's not a bank account. It's likely the top reason people are involved in the first place.


I'm curious about the frontrunning.

How much of it is based on social dynamics/having access to the right social networks vs. monitoring transactions vs. monitoring mempool/transaction pool?


> START PORTFOLIO = 10000 USDT

> FINAL PORTFOLIO = 19015.904019955597 USDT

> GROSS PROFIT = 9015.904020 USDT (90.16%)

> MARKET CHANGE = 396.71%

does this mean the bot went up 90% when the market went up 396%?


Yeah the market went up 4x in the test period (see test data folder) which is from November last year until a few weeks ago (which also was about the market top).

The strategy is a simple two moving averages strategy. It will capture less of the return in a very strong market but maybe protect you on the downside.

The results don’t look particular good though.


https://github.com/rodrigo-brito/ninjabot/blob/b9ff23d5c44d4...

I'm not sure this is calculated properly since marketChange is `sum(last-first)/first` (ratio) then avgMarketChange is `ratio/num_samples*100`. That's... average percent change between each sample? Doesn't sound right. (unless I misunderstand what's referenced in candles)


Haha, variable for first candle is `fistCandle` [0].

Pretty mangled code. Weird to have to iterate over `avgPrice` to get pairs. This is calculating the average market change across all pairs for which `avgPrice` is tracked in this PaperWallet, whatever that means.

    type PaperWallet struct {
     sync.Mutex
     ctx          context.Context
     baseCoin     string
     counter      int64
     takerFee     float64
     makerFee     float64
     initialValue float64
     feeder       Feeder
     orders       []model.Order
     assets       map[string]*assetInfo
     avgPrice     map[string]float64
     lastCandle   map[string]model.Candle
     fistCandle   map[string]model.Candle
    }
    
    [...]
    
    func (p *PaperWallet) Summary() {
      var (
        [...]
        marketChange float64
      )
      [...]
      for pair, price := range p.avgPrice {
        [...]
        marketChange += (p.lastCandle[pair].Close - p.fistCandle[pair].Close) / p.fistCandle[pair].Close
        [...]
      }
      avgMarketChange := marketChange / float64(len(p.avgPrice))
      [...]
    }
[0] https://www.google.com/search?q=fist+candle&tbm=isch


Hi, Ninjabot author here. The idea of Market Change is to compare your strategy with the "buy and hold". It means, buys at the start of the period and sell at the and. We also use avg price, because the user can create several buys and a single sell. And the profit is based on the average price in this case.


could be wrong here.. but I think Change means ups AND downs...


Everyone's a genius in a bull market.


Everyone’s a genius in the hacker news comment section


Not everyone.

Now, which one of us is the imposter?


I am—

Wait!


That's an important concept to grasp for newcomers. Making good trades in a trending market is relatively easy. Making money, or at least not losing money, in a ranging market is the hard part.


Can this quickly trade on Elon Musk tweets?

Tweet => Sentiment Analysis => if + { buy } else { sell }

As far as I can tell, Musktweets are the fundamentals driving the cryptocurrency market.


Some days ago a made a joke of that. I should develop a tradingbot that detects Elons positive or negative statements about a coin and buy or sell ;-)


I'm willing to bet multiple such bots have been implemented and are running live. It's just an obvious strategy.


This looks super cool!

I would love to play around with this, but the docs are a little light at the moment (unless I missed them). Would definitely recommend pushing docs and content on how to build custom strats, extend the main framework with custom reporting or new exchanges.

It does Binance but it's unclear to me what product types (I'm assuming spot markets).

Things I recommend exploring: (high latency) arbitrage between derivs and spot (for example cash and carry arbitrage). Or super simple funding arb on coinmargined perps (short 1x into synthetic usd). Pure directional is hard, and besides that there is a ton of alpha in more market neutral stuff.

----

A long while back I created a framework with a lot of overlapping functionality called Gekko (not trying to shill, I haven't maintained it for years). It took what I learned from that experience and build a prop trading firm called Folkvang. Crypto has a sea of opportunities ready to seize and in a bull market like we've seen in the last few months there is plenty of fish for everyone (yes there is a free lunch, even for those without a decade of quant/HFT experience from wall street).

----

play, build and have fun - can easily grow into a career


Yes, for now it supports only spot market. The docs are very poor for now, the project is recent (a couple of weeks), but I will try to create a website for it, soon.

I used Gekko for a long time, it is a great project.!


Where can I learn more about the concepts you mentioned? I find it quite hard to acquire knowledge in that area as I don‘t even get to formulate the right questions.


In typical HN fashion I'll criticize the naming: This seems to be a trading bot on centralized exchanges, so as it stands it doesn't interact with cryptocurrency and it could trade anything (not necessarily cryptocurrency). Hence at least adding "trading [bot]" would be more descriptive.


SOmething that is quite vital but not mentioned anywhere in the readme is the strategy being used. Or how to develop one, for that same matter.

It is a trading engine - in itself quite interesting, but limited in its usefulness by the lack of strategies.

UPDATE: it has one sample strategy implemented, an EMA crosser (9/21) at https://github.com/rodrigo-brito/ninjabot/blob/main/example/...

This said, I would be very much interested in an introduction to different (simple) trading strategies with examples - does anyone know some introductory text to those?


You are sure, it is like a trading engine for spot market. I create some examples, but a better documentation will be great to make it more clear.


I have a completely different question. What make a program, bot? Why isn't this called service or app or utility?

Just curious.


The way I see it it's software that does something that a human is "supposed to do".

Eg chat is for humans but a chat bot will use the chat's interface for automating some tasks. Or bots in a multiplayer game take place of other players etc.

Bot ~ robot ~ humanoid? I guess?


Tried to install it on an RPI4, but failed due to different packages only available for x86.

Any chance to get it to run on ARM64? I got an RPI4 sitting around which I would like to use for papertrading.


Took me some time to realize that this is a trading bot. Seems relavant to specify that.


All the benefits of cryptocurrency plus all the benefits of High-frequency trading?

We're doomed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: