Adding Fear & Greed to Vigilant Crypto Snatch

In my Vigilant Crypto Snatch project I have spent quite some time in improving the architecture of the software such that further changes would be much simpler. At the time I did not have a backlog of new features, so I just tried to add more tests. This then forced me to separate a few things, improving the overal design.

Today somebody has asked whether the Fear and Greed Index could be used as an additional decision element. And given the clean architecture of the software, it certainly is possible! In this article I will show how it easy it was to include.

Before I have added the new feature, the triggers component has looked like this:

There is this TriggeredDelegate interface, which just decides whether the trigger should fire. There are two concrete implementations, one which always returns “yes”, and one which does the drops. All we need to do there is add another one with the fear and greed index.

First we need to have an interface to the index which fetches the current value. I have hidden this behind an interface again, such that I can replace it with a fake/stub implementation.

And then I can use that to implement the new FearAndGreedTriggeredDelegate:

I have changed the way that triggered delegates are used. The BuyTrigger now has multiple such delegates, and all of them have to yield “yes” in order to buy coins. This allows users to combine the trigger strategies like they want, and it doesn't complicate my architecture.

It took me just an hour to research the HTTP API for the index, implement these changes with tests, write documentation and make a release. There were no horrible moments where something didn't work, it was really fun. And that's how software development should be like.