Welcome to @opass/perp-exchange
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
This README was generated with