@opass/perp-exchange

2.0.0 • Public • Published

Welcome to @opass/perp-exchange

Version License: MIT

prerequisites

Only supports ESM import. CommonJS require is not supported.

Install

npm install @opass/perp-exchange

Usage

basic

import PerpExchange from "perp-exchange"
// Initialize PerpExchange with TWD and USD amount
const initailTwd = 10000;
const initialUsd = 1000;
const exchange = new PerpExchange(initailTwd, initialUsd);

const usd = exchange.exchangeUsd(6000);  // Get 375 USD by 6000 TWD 
exchange.getReservedTwd();               // 16000
exchange.getReservedUsd();               // 625

exchange rate should base on previous status

const initialTwd = 10000;
const initialUsd = 1000;
const exchange = new PerpExchange(initialTwd, initialUsd);

const firstTwd = exchange.exchangeTwd(250);   // Get 2000 TWD by 250 USD 
exchange.getReservedTwd();                    // 8000 TWD
exchange.getReservedUsd();                    // 1250 USD

const secondTwd = exchange.exchangeTwd(250);  // Get 1333 TWD by 250 USD 
exchange.getReservedTwd();                    // 6667 TWD
exchange.getReservedUsd();                    // 1500 USD

check test to see more usage

Run tests

# clone repo and move in project directory
npm install
npm run test

Author

👤 opass


This README was generated with ❤️ by readme-md-generator

Readme

Keywords

none

Package Sidebar

Install

npm i @opass/perp-exchange

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

12.4 kB

Total Files

9

Last publish

Collaborators

  • opass