Giter Site home page Giter Site logo

shanehampton / stablecoin_stats Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.53 MB

A real time stablecoin tracker built with Elixir + Phoenix + PostgreSQL

Dockerfile 1.91% CSS 11.67% JavaScript 1.41% Elixir 83.13% HTML 1.62% Shell 0.15% Batchfile 0.10%

stablecoin_stats's Introduction

Stablecoin Stats

A real-time dashboard for USD stablecoin market metrics.

Screencap

What is a Stablecoin?

Stablecoins are cryptocurrencies pegged to real-world assets. By design, a stablecoin's price is intended to trade at par with the tracked asset. This app is specifically concerned with coins pegged to the US Dollar (e.g. USDC, USDT, BUSD).

Overview

This app receives price data for major USD-pegged stablecoins from various cryptocurrency exchange WebSocket APIs, and tracks live market metrics. A stablecoin's ability to mirror a pegged asset's price is often taken for granted, but this is not always the case in practice. The Stablecoin Stats dashboard analyzes price movements and shows how "stable" each stablecoin market is at any given point in time.

Technology Stack

  • Elixir
  • Phoenix
  • Ecto
  • LiveView
  • PostgreSQL
  • HTML5
  • CSS3
  • Docker

How It Works

  1. Each exchange WebSocket has a dedicated client to maintain the connection and receive messages. The client processes market updates from the exchange and broadcasts relevant currency pair exchange rates to a Phoenix PubSub rates topic.
  2. The core backend listens for new rates, then stashes them in a PostgreSQL database and a non-perisistent cache. The latter is implemented as a vanilla GenServer process with key-value state. Stablecoin metrics seen on the frontend are derived from these raw exchange rate feeds. Whenever a new rate comes in, the scoring model generates new values and broadcasts them to a Phoenix PubSub stats topic.
  3. When a browser connects, a Phoenix LiveView process is spawned. On mount, it receives initial state from the cache/database and begins to listen for new stats. Fully rendered HTML is served directly from the backend to the browser via Phoenix socket.

Architecture

Architecture

Price Calculation

This app uses a best bid, multi-pair, aggregated pricing model. Below is a brief explanation of what that means.

Best bid: The model is informed by the best bid in the order book. This is not necessarily the same thing as a "price" you might see on a traditional price tracker. Bids represents what buyers in the market are willing to pay right now, and the best bid represents what the highest bidder is willing to pay. The best bid approach focuses on the market's exit route, which builds a liquidity premium into the model. In other words, the model takes a seller's view of the market for the purpose of measuring stability in a more meaningful way. This aspect of the model could be expanded by sampling deeper bids to simulate a range of liquidity scenarios.

Multi-pair: The price of a stablecoin can come from a direct market pair between the stablecoin and the pegged currency. Using USDC as an example, that would be the USDC-USD pair. A direct pair is the most accurate way to evaluate price. However, sometimes direct markets are illiquid or non-existent on certain exchanges, leaving the model with a lack of data. To bridge this gap, the model uses an intermediary market with greater liquidity to interpolate price. Instead of just measuring USDC-USD, it also measures rates like USDC-BTC and BTC-USD. A stablecoin <> BTC <> USD interpolation evaluates the effective rate a market participant can achieve by selling the stablecoin for BTC and subsequently selling that BTC for USD. This gives the model a means to approximate price even when direct market pairs are not active. In the end, the calculated stablecoin prices use a blend of direct and interpolated rates.

Aggregated: The model ingests order book data from multiple exchanges, aggregating them into one price value. This provides a broad view of the stablecoin's price not limited to a singular market.

Stability Metrics

  • Root-Mean-Square Error (RMSE): The square root of the mean squared error between the coin's observed price and the expected $1.00 price. This is a generalized metric to measure residual price breakdown. Lower values mean the price tends to stay closer to the target value.
  • Standard Deviation (STDEV): Dispersion of the price itself; in other words, the observed volatility in price. Lower values mean the price tends to move less drastically.
  • Max Drawdown (MDDN): The maximum observed peak-to-trough price movement. This is a measure of downside risk. Lower values mean the price tends to experience less downward movement by magnitude.

Deployment

  • Fully containerized build process using mix release inside Docker
  • Build (tarball) deployed and run on AWS EC2 instance
  • PostgreSQL database hosted in AWS RDS

stablecoin_stats's People

Contributors

shanehampton avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.