Giter Club home page Giter Club logo

bookmaker's Introduction

Stellar Bookmaker: A tool for correctly setting up an example orderbook in the Stellar network

Bookmaker populates the orderbook for a Stellar asset with the prices, amounts, and buy/sell ordering. Prices, amounts, and the trading pair is framed in the traditional concept of base and counter currencies.

Purpose and origins

This tool is useful for making sure that a trading client displays data properly. It is extremely important that trading clients display the data correctly because if done incorrectly, it could result in the loss of users' money.

This is surprisingly difficult to do since there are about 8 different ways that these orders could be built (2 prices * 2 amounts * 2 buy/sell ordering). This repository is the product of my 15 hours of figuring out how to get the orderbook populated in the correct way.

Full cycle order creation from 1 to 8

The bookmaker does all the necessary steps to get from accounts to having the asset have a valid orderbook with the right prices. The bookmaker does the following:

  1. Generates accounts to test with (can be easily changed)
  2. Funds issuer, buyer, and seller on the test network
  3. Fetches all their sequence numbers
  4. Buyer and seller trusts the issuer
  5. Issuer gives the buyer and seller some of the asset
  6. Deletes the whole orderbook (can be easily commented out)
  7. Creates the offers to buy and sell the asset
  8. Displays the resulting orderbook

Example output

// Trust extended to issuer
// Buyer and seller funded with asset
// Buyer balances:
 [ { balance: '850.0000018',
    limit: '922337203685.4775807',
    asset_type: 'credit_alphanum4',
    asset_code: 'USD',
    asset_issuer: 'GBAMBOOZDWZPVV52RCLJQYMQNXOBLOXWNQAY2IF2FREV2WL46DBCH3BE' },
  { balance: '15987.4364787', asset_type: 'native' } ]
// Seller balances:
 [ { balance: '1349.9999982',
    limit: '922337203685.4775807',
    asset_type: 'credit_alphanum4',
    asset_code: 'USD',
    asset_issuer: 'GBAMBOOZDWZPVV52RCLJQYMQNXOBLOXWNQAY2IF2FREV2WL46DBCH3BE' },
  { balance: '16332.9592383', asset_type: 'native' } ]
// Orderbook contents cleared out
// Offers successfully created
// Resulting orderbook
{ bids: [ { price_r: [Object], price: '0.0023118', amount: '11.5590400' } ],
  asks: [ { price_r: [Object], price: '0.0024561', amount: '4000.0000000' } ],
  base: { asset_type: 'native' },
  counter:
   { asset_type: 'credit_alphanum4',
     asset_code: 'USD',
     asset_issuer: 'GBAMBOOZDWZPVV52RCLJQYMQNXOBLOXWNQAY2IF2FREV2WL46DBCH3BE' } }

Usage

This uses the latest features available in Node.js. It uses async/await which is available as of Node.js and available under a harmony feature flag.

To run the bookmaker:

  1. Install Node.js version 7 or later (Node version manager is recommended for keeping track of your Node versions)
  2. Run npm install --production
  3. Copy keys.sample.js to keys.js and fill in the specified secret keys and network name.
  4. Make sure all the accounts in keys.js are funded
  5. Run npm start

License

Bookmaker is licensed under the Apache-2.0 license. Details can be found in the LICENSE file.

bookmaker's People

Contributors

irisli avatar

Watchers

James Cloos 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.