Implementing SPEEDEX price computation engine in Golang as a standalone binary that exchanges can call

speedex-standalone

Implementing SPEEDEX price computation engine in Golang as a standalone binary that exchanges can call.

Notes from Geoff About Tatonnement:

SCS Lab Implementation: https://github.com/scslab/speedex/blob/master/price_computation/

Stellar Implementation: https://github.com/gramseyer/stellar-core/blob/master/src/speedex/TatonnementOracle.cpp

Simple Simplex LP Solver: https://github.com/gramseyer/stellar-core/tree/master/src/simplex

Tatonnement

  1. Collect DB of transactions for a given block 1a) Create one vector for each group <sell A, buy B> (which is a different vector than <sell B, buy A>) as transactions come in 1b) As we are building these vectors, keep each one in sorted order from minimum price. 1c) Also keep track of cumulative amount up to that price.
  2. Start with a price (ideal is integer - maybe 64 bit or less for edge cases and overflow and speed), but MVP can use floating point
  3. Go through these vectors using binary search O(log n) to find how much would be bought/sold for each asset.
  4. Update prices. 4a) New price = Old price * (1 + Old price * asset quantity * (demand - supply) * STEP_SIZE) 4b) Why weight by old price * asset quantity? It's to make sure when things are denominated differently they still take similar size steps. IE 1 dollar vs 100 pennies. 4c) How to set STEP_SIZE? 4ci) Pick a small constant 4cii) Run multiple Tatonnement in parallel with different constants 4ciii) Use a heurtistic (such as L2 Norm or Infinity Norm) of Net Demand Vector (demand - supply) for Old price and New price and see if the norm decreases. If it increases then use a smaller STEP_SIZE.
  5. Stopping criteria 5a) Fixed number of iterations 5b) Net Demand Norm less than some fixed amount.
  6. LP Solver

Notes:

  1. When collecting transactions from multiple threads, create this sorted DB (sell A, buy B, price, cumulative, metadata) per thread. Then do one MergeSort to combine them all together to get the entire transaction set.
  2. Don't want demand to be too cliff-y, so smooth it out using a parameter alpha. 2a) Example: alpha = 0.01. Then if limit price is 99% of current price then sell in full. If limit price is 99.5% of current price sell half of it. If limit price equals current price then sell none. 2b) Will need to have 2 cumulative values in vector: cumulative amount and cumulative amoount * limit price offer

To Do: LP Solver after Tatonnement

Owner
Samuel Wong
Stanford Statistics/Data Science grad, I love Python, Stats, and Machine Learning
Samuel Wong
Similar Resources

Standalone client for proxies of Opera VPN

opera-proxy Standalone Opera VPN client. Younger brother of hola-proxy. Just run it and it'll start a plain HTTP proxy server forwarding traffic throu

Jan 9, 2023

Standalone client for proxies of Windscribe browser extension

windscribe-proxy Standalone Windscribe proxy client. Younger brother of opera-proxy. Just run it and it'll start a plain HTTP proxy server forwarding

Dec 29, 2022

A standalone ipfs gateway

rainbow Because ipfs should just work like unicorns and rainbows Building go build Running rainbow Configuration NAME: rainbow - a standalone ipf

Nov 9, 2022

A standalone Web Server developed with the standard http library, suport reverse proxy & flexible configuration

A standalone Web Server developed with the standard http library, suport reverse proxy & flexible configuration

paddy 简介 paddy是一款单进程的独立运行的web server,基于golang的标准库net/http实现。 paddy提供以下功能: 直接配置http响应 目录文件服务器 proxy_pass代理 http反向代理 支持请求和响应插件 部署 编译 $ go build ./main/p

Oct 18, 2022

PinGo is a standalone and feature-rich tool for common IP-based reachability checking tasks. Ping or Trace and Observe in real-time the statistics.

pingo As a network champion from designing and implementing to troubleshooting large scale networks - I know that is usually not easy for administrato

Sep 26, 2022

Scout is a standalone open source software solution for DIY video security.

Scout is a standalone open source software solution for DIY video security.

scout Scout is a standalone open source software solution for DIY video security. https://www.jonoton-innovation.com Features No monthly fees! Easy In

Oct 25, 2022

Simple tool to handle hosts file black lists that can remove comments, remove duplicates, compress to 9 domains per line, add IPv6 entries, as well as can convert black lists to multiple other black list formats compatible with other software.

Hosts-BL Simple tool to handle hosts file black lists that can remove comments, remove duplicates, compress to 9 domains per line, add IPv6 entries, a

Sep 23, 2022

CoAP Client/Server implementing RFC 7252 for the Go Language

Canopus Canopus is a client/server implementation of the Constrained Application Protocol (CoAP) Updates 25.11.2016 I've added basic dTLS Support base

Nov 18, 2022

A pure Unix shell script implementing ACME client protocol

An ACME Shell script: acme.sh An ACME protocol client written purely in Shell (Unix shell) language. Full ACME protocol implementation. Support ACME v

Jan 2, 2023
Comments
  • link to another simplex solver

    link to another simplex solver

    A link to another solver for the same LP, along with checking feasibility of the LP if lower bounds are imposed (i.e. offers less than (1-alpha) have to trade in full).

    The main difference is a sparse internal representation of the constraint matrix. Doesn't change the external interface, but the non-sparse representation doesn't seem to scale past 10 or so assets (whereas the sparse rep will go to ~80 or 100)

Carbyne Stack serverless compute service for secure multiparty computation

Carbyne Stack Ephemeral Service Ephemeral is a serverless compute service for secure multiparty computation based on Knative, Istio and Kubernetes. DI

Dec 7, 2022
Node of the decentralized oracle network, bridging on and off-chain computation

Chainlink is middleware to simplify communication with blockchains. Here you'll find the Chainlink Golang node, currently in alpha. This initial imple

Dec 31, 2022
A simple calculator to return the final price with the input included percentage or vice versa

ccl A simple calculator in Golang and Cobra to return the final price with the i

Oct 10, 2022
Simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run.

Simple Proxy This is a simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run. Code b

Jan 7, 2023
Experimental system call tracer for Linux x86-64, written in Go

gtrace A system call tracer for Linux x86-64. DISCLAIMER: This software is experimental and not considered stable. Do not use it in mission-critical e

Nov 29, 2022
A yet to be voice call application in terminal. with the power of go and webRTC (pion).

Kenny I'm just trying to make a cli operated voice call chat application using go with help of webRTC and PortAudio. It might stay a Work In Progress

Dec 2, 2022
requestgen generates the cascade call for your request object

requestgen requestgen generates the cascade call for your request object Installation go get github.com/c9s/requestgen Usage requestgen scans all the

Nov 30, 2022
easyRpc - Sync && Async Call supported

easyRpc - Sync && Async Call supported

Feb 16, 2022
Go library for writing standalone Map/Reduce jobs or for use with Hadoop's streaming protocol

dmrgo is a Go library for writing map/reduce jobs. It can be used with Hadoop's streaming protocol, but also includes a standalone map/reduce impleme

Nov 27, 2022
httpstream provides HTTP handlers for simultaneous streaming uploads and downloads of objects, as well as persistence and a standalone server.

httpfstream httpfstream provides HTTP handlers for simultaneous streaming uploads and downloads of files, as well as persistence and a standalone serv

May 1, 2021