Giter Club home page Giter Club logo

interstellar-algos's Introduction

interstellar-algos

Algorithmic Execution Bot for Perpetual Protocol v1

This is a basic framework for an Algorithmic Execution Bot for Perpetual Protocol v1 and can be easily extended to work on multiple AMM venues depending on the developer's knowledge of blockchain and smart contracts development.

Installation

$ git clone https://github.com/d5shen/interstellar-algos.git
$ cd interstellar-algos
$ npm install
$ cp .env.production.sample .env.production
$ npm run build

If running in Windows Powershell, you need to install git and grep (through Gow or other ports of grep to windows)

Configuration

You will need access to your own xDai node - both WebSocket and http JSON RPC. Check out QuickNode, GetBlock, or Ankr. Provide your private keys in .env.production:

WEB3_ENDPOINT=wss://your-xdai-websocket-endpoint
WEB3_ENDPOINT_RO=https://your-xdai-json-rpc-endpoint
# The private key must start with "0x" - add it if necessary (e.g. from private key exported from Metamask)
ARBITRAGEUR_PK=YOUR_WALLET_PRIVATE_KEY

Note the node endpoint defined in .env.production must point to an xDai node. By default, xDai's official endpoint is used. You can also choose to use Quicknode, or spin up your own node. Ethereum nodes such as Infura or Alchemy will not work.

Edit the basic trading parameters in configs.json:

{
    "ammConfigMap": {
        "SUSHI-USDC": {
            "PERPFI_LEVERAGE": 10,
            "MAX_SLIPPAGE_RATIO": 0.0050
        },
        "FTT-USDC": {
            "PERPFI_LEVERAGE": 10,
            "MAX_SLIPPAGE_RATIO": 0.0050
        },
        "...": {
            "..."
        }
    }
}

Deposit

  • Deposit xUSDC for trading on Perpetual Protocol Exchange - xUSDC can be deposited into your wallet either via perp.exchange, or using the xDai Omni Bridge. xUSDC is the USDC token that has been transfered to xDai.
  • Deposit xDAI in your wallet to pay for gas on xDai (note xDai gas fees are typically 1 Gwei and paid in xDAI, DAI tokens that have been transfered to xDai.)

Running the Algo Execution Bot

You can run interstellar-algos in *nix bash or Windows Powershell.

You will need two consoles - one for the server and one for the Command Line Interface (CLI).

Run in bash

Server in bash (locally)

$ npm run server

or

$ env $(cat .env.production | grep -v '#') npx ts-node --files src/index.ts

Command Line Interface (CLI) in bash

$ npm run cli

Run in Windows

Server in Windows Powershell (locally)

$ ./run.ps1

Command Line Interface (CLI) in Windows Powershell

$ env $(cat .env.production | grep -v '#') npx ts-node --files src/ui/main.ts

Supported Algos

TWAP

The Time-Weighted Average Price (TWAP) Algo executes user's order based on a fixed time period sliced into multiple intervals.

To input a TWAP order in the CLI, the command pattern is:

INPUT> TWAP [Pair] [BUY|SELL] [USDC Notional] [Total Time (mins)] [Interval (mins)]

For example:

INPUT> TWAP SUSHI-USDC BUY 5000 120 10

This will buy 5000 USDC worth of SUSHI-USDC perp over 120 minutes, executing a small trade every 10 minutes

POV

The Percentage-of-Volume (POV) Algo executes user's order based on a percentage of the pair's total volume traded a fixed time period on Perpetual Protocol

To input a POV order in the CLI, the command pattern is:

INPUT> POV [Pair] [BUY|SELL] [USDC Notional] [POV (decimal)] [Interval (mins)] [Max Clip Size (optional)]

For example:

INPUT> POV SUSHI-USDC BUY 10000 0.05 10 2000

This will buy 10000 USDC worth of SUSHI-USDC perp at 5% of the total SUSHI-USDC traded volume on Perpetual Protocol, with at least 10 minutes between each trade, and no more than a clip size of 2000 USDC. This means that if, within a 10 minute interval, 90,000 USDC volume was traded, the user should target 5% of that (4500 USDC) in the next clip but because a max clip size of 2000 USDC was specified, it will only trade 2000 USDC worth of SUSHI-USDC perp.

interstellar-algos's People

Contributors

d5shen avatar liujdream 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.