Giter Site home page Giter Site logo

mithraiclabs / psyoptions-market-tracker Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 4.0 654 KB

A server for listening to PsyOptions and Serum, indexing data, and an API to consume the longer term data

TypeScript 86.23% Dockerfile 2.23% JavaScript 1.01% HTML 1.00% CSS 0.80% PLpgSQL 8.73%

psyoptions-market-tracker's Introduction

How to run locally

  1. install direnv (macOS: brew, ubuntu: apt) + hook into shell

  2. run direnv allow && docker-compose up --build. it will probably take a few mins of docker doing its thing before everything is ready

  3. annoying step that won't be necessary soon... copy the contents of mutation.gql, then cd hasura && hasura console. Once the browser console opens, paste the generated mutation in the graphql editor and run it, it should create all the market and associated asset records.

  4. open http://localhost

  5. do a buy or sell trade on devnet BTC-USDC June 2021 options

  6. hopefully it'll show up in the table on http://localhost within a few seconds

Architecture

excalidraw diagram

Deployment

Edit .envrc and run docker-compose up --build -d

psyoptions-market-tracker's People

Contributors

johnrees avatar tomjohn1028 avatar taylor123 avatar

Stargazers

 avatar Azoth Zephyr avatar Shun Kakinoki avatar  avatar illyrian avatar Armani Ferrante avatar

Watchers

James Cloos avatar Evan Pipta avatar  avatar  avatar

psyoptions-market-tracker's Issues

Add autoscaling to Hasura

image

This may (or may not) be an indication that the single Hasura task is hitting the soft 1024 file descriptor limit docs

Remove Serum Vial dependencies

Serum-Vial is overkill for indexing and tracking Serum events and adds unnecessary networking/timing implications.

We should roll our own code to listen to events/updates on necessary Serum market accounts.

  • EventQueue

OpenOrders look up fails on first trade

The first time an account places an order the OpenOrders.load call fails with Error: Open orders account not found. The second time a trade is made on that market, the open_order_account gets stored properly

Make configurable for other projects

Currently there is a fair bit of PsyOptions specific logic intertwined into the Listener and Hasura (e.g. the migrations and table set up) containers.

There are many other projects that would likely use this cloud infrastructure to track data for their projects, so we'll need to make those application specific requirements more configurable and flexible.

Improve Timescale instance for "Too many clients already"

The following error was showing up in some Hasura logs

{"type":"http-log","timestamp":"2021-09-09T01:34:32.766+0000","level":"error","detail":{"operation":{"user_vars":{"x-hasura-role":"admin"},"error":{"internal":"FATAL:  sorry, too many clients already
","path":"$","error":"connection error","code":"postgres-error"},"request_id":"d8de1115-fa19-41ff-b5c9-149a78b9b095","response_size":118,"query":{"variables":{"object":{"order_id":"46891623435369680254532","client_id":"9254101784418634862","serum_market_address":"qDvaLApMYkbp9NTgYJaNy7CDsPhXMbDjEr3g3oqEMaw","account":"Abe39jLaH5BSmLryRbAGu1wMfCgPkXnvkQV7JZDuvDxT","slot":95649683,"account_slot":2,"type":"done","side":"sell","timestamp":"2021-09-09T01:33:51.437Z"}},"query":"
      mutation ($object: serum_events_insert_input!) {
        insert_serum_events_one(object: $object) {
            serum_market_address
        }
      }
      
        "}},"http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"3.70.45.116","method":"POST","content_encoding":null}}}

This seems to coincide with when a new Hasura task is being spun up and the old one is being shut down (see image below for hasura timing).

Screen Shot 2021-09-08 at 11 04 06 PM

And the following for Timescale's last error logs.

Screen Shot 2021-09-08 at 11 05 02 PM

This makes sense as the Hasura connection pool would surpass the postgres max_connections if two were running at the same time and they used the Timescale tuning to determine max connections.

Database username, password, etc security

Currently there is nothing secure about the username, password, and database name in the CloudFormation templates. We'll need to store this information in AWS secrets manager and reference the secrets from the respective resources.

Remove hardcoded parameters

Some of the PsyOptions specific code is hardcoded for ease of development. Many of those hardcoded variables should be environment specific.

Add Authorization to Hasura

Currently the hasura GraphQL endpoint is wide open for anyone to run an insert, update, etc. We should probably put in some sort of authorization (maybe a simple token based authorization) that is only known the to the Listener or other private services that need to actually write to the database.

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.