npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fl0wo/wallet-simulator

v1.2.9

Published

Tool for tracking and simulating trades, work as well with cryptocurrency transactions.

Downloads

34

Readme

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

  • [x] Price update method on particular asset
  • [x] Add new trades balancing current balance
  • [x] P&L and cost basis for each asset
  • [x] Donut information on % of owned assets
  • [x] Trend snapshots graph of balance at "every day"
  • [x] Trend snapshots graph of balance if just buy & hold at day 0
  • [x] Fee % on addTrade operations
  • [x] Export Wallet as JSON
  • [x] 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

| Command | Description | |------------------------------|----------------------------------------------------------------------| | addTrade | Update balance and holdings based on trade | | updatePrice | Set price for a particular asset | | getPositionValue | Return the value owned on this wallet of a particular asset | | getTotalValue | Return the sum of all funds in this wallet | | getPositionAverageCost | Return the average cost of a particular asset | | getEstimatedLiquidationPrice | Return the estimated liquidation price of a particular asset | | getPrice | Get latest known price for an asset | | getPositionAverageCost | Average spent position costs for a particular asset | | getDonutAssetInformation | Return a donut type chart with all assets owned in % | | getTrendBalanceSnapshots | Trend balance graph snapshots of daily gaps | | exportToText | Return the estimated unrealized profit or loss of a particular asset | | exportToJson | Returns a stringified verson of the WalletSimulator object | | importFromJsonString | Reverse operation of exportToJson |

Properties

| Field | Description | |--------------|--------------------------------------------------------------------------------| | balance | Current available balance in the base currency (EUR,USD,Bananas,Apples,etc...) | | holdings | Map with quantities owned of each asset | | prices | Map with the last known price for each asset | | costBasis | Current sum of costs paid for an asset | | trades | All trades | | daySnapshots | Date 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 [email protected]

You can also find me on Twitter