marianogappa / crypto-predictions

State machine-based engine for tracking crypto-related predictions across social media posts.
https://marianogappa.github.io/software/2023/06/17/building-crypto-predictions/
2 stars 0 forks source link
binance-api cryptocurrency golang twitter-api

crypto-predictions

Blogpost: Building Crypto Predictions Tracker: architecture and challenges

Crypto Predictions is a state machine-based engine for tracking crypto-related predictions across social media posts.

https://user-images.githubusercontent.com/1078546/158062428-09e54090-a627-4a3b-9948-41411f1b7191.mp4

Architecture

Crypto Predictions Diagram

The engine maintains a database of "predictions", which are state machines that track crypto-related predictions like "Bitcoin will hit 100k this year" against historical and live market data from crypto exchanges like Binance and others.

It is shipped as a single binary (Back Office static assets are embedded) which runs all components by default, but can be configured via flags to run individual components separately.

Getting started

Notes

Configuration

Crypto Predictions is configured via enviroment variables. Because this can become troublesome, alternatively a config.json file can be added at the same path as the binary, which contains a JSON map, having keys as env names, and string values.

The following variables are supported:

Social network API credentials

These credentials allow retrieving metadata from posts on Twitter & Youtube

And these optional credentials allow posting to Twitter (but to obtain them you need to authorize Oauth1 for your Twitter Application on behalf of a Twitter handle:

If you provide the path to a Chrome binary, it will be used to produce images to be added onto Twitter posts (this process will also temporarily write images to the filesystem at the cwd, so make sure it is writable):

Database configuration

Security configuration

All non-public endpoints (i.e. all except /pages/prediction at this point) are behind BasicAuth.

Components configuration

Market cache configuration

Market candlestick requests are cached, because most predictions ask the same candlesticks to the same exchanges over and over again.

There are separate caches for separate candlestick intervals.

Each cache entry stores up to 500 subsequent candlesticks of a given metric.

The following configurations specify how many cache entries exist per metric per candlestick interval. Entry eviction strategy is LRU.

If memory is not a problem, the higher the better!

Tweeting configuration

By default, the system does not Tweet anything. By setting the first env, it will post tweets as the configured account. By setting both envs, it will attempt to reply to prediction tweets rather than just posting.