1.2.9 • Published 1 year ago

@fl0wo/wallet-simulator v1.2.9

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Wallet Simulator

A class to simulate a cryptocurrency wallet in Node.js

Can Integrate with CCTX to Import/Export information from real world crypto exchanges.

Installation

npm install wallet-simulator

Usage

import { WalletSimulator } from 'wallet-simulator';

const wallet = new WalletSimulator(1000)
    .addTrade({ ticker: 'BTC', price: 10, quantity: 1, type: TradeMove.BUY })
    .addTrade({ ticker: 'ETH', price: 100, quantity: 2, type: TradeMove.BUY })
    .updatePrice('BTC', 12)
    .updatePrice('ETH', 110);

console.log(wallet.getPositionValue('BTC')); // 12
console.log(wallet.getPositionValue('ETH')); // 220
console.log(wallet.getTotalValue()); // 1232

console.log(wallet.getPositionAverageCost('BTC')); // 10
console.log(wallet.getEstimatedLiquidationPrice('BTC')); // 10
console.log(wallet.getEstimatedUnrealizedProfitLoss('BTC')); // 2

Todo

  • Price update method on particular asset
  • Add new trades balancing current balance
  • P&L and cost basis for each asset
  • Donut information on % of owned assets
  • Trend snapshots graph of balance at "every day"
  • Trend snapshots graph of balance if just buy & hold at day 0
  • Fee % on addTrade operations
  • Export Wallet as JSON
  • Import Wallet from JSON
  • Reverse-Engineering data from Real Exchanges Trades
  • Filter on Max Buy Power allowed and list of allowed-desired assets to open orders

Methods

CommandDescription
addTradeUpdate balance and holdings based on trade
updatePriceSet price for a particular asset
getPositionValueReturn the value owned on this wallet of a particular asset
getTotalValueReturn the sum of all funds in this wallet
getPositionAverageCostReturn the average cost of a particular asset
getEstimatedLiquidationPriceReturn the estimated liquidation price of a particular asset
getPriceGet latest known price for an asset
getPositionAverageCostAverage spent position costs for a particular asset
getDonutAssetInformationReturn a donut type chart with all assets owned in %
getTrendBalanceSnapshotsTrend balance graph snapshots of daily gaps
exportToTextReturn the estimated unrealized profit or loss of a particular asset
exportToJsonReturns a stringified verson of the WalletSimulator object
importFromJsonStringReverse operation of exportToJson

Properties

FieldDescription
balanceCurrent available balance in the base currency (EUR,USD,Bananas,Apples,etc...)
holdingsMap with quantities owned of each asset
pricesMap with the last known price for each asset
costBasisCurrent sum of costs paid for an asset
tradesAll trades
daySnapshotsDate separated values of Wallet Snapshot in the history

Test

npm run test

Authors

License

This project is licensed under the Apache License - see the LICENSE file for details.

Contributions

Want to contribute to this project? Great! We welcome contributions and are always looking for ways to improve this package. Please take a look at the CONTRIBUTING file for more information on how to get started.

Support

If you have any questions or issues with this package, please open an issue on the Github repository or contact us at sabaniflorian@gmail.com

You can also find me on Twitter

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.9

1 year ago

1.2.4

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.5

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago