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

crypto-portfolio-restruct

v0.2.5

Published

Sync your portofolio automatically

Downloads

13

Readme

Binance Asset Allocation Tool

Get an overview of your current crypto portfolio and to calculate trades to reallocate your assets.

const { PortfolioManager } = require('binance-portfolioo-restruct');

(async () => {
    const myManager = new PortfolioManager();
    await myManager.init({
        binanceSecret: process.env.BINANCE_SECRET,
        binanceKey: process.env.BINANCE_KEY
    });

    console.log(myManager.getPortfolio());
})();

Would print something like:

{
  sum: { asset: 'BNB', amount: 100 },
  portfolio: [
    { asset: 'ETH', ratio: 18.6, string: 'ETH: 18.60%' },
    { asset: 'XRP', ratio: 18.6, string: 'XRP: 18.60%' },
    { asset: 'BTC', ratio: 18.6, string: 'BTC: 18.60%' },
    { asset: 'BNB', ratio: 18.6, string: 'BNB: 18.60%' },
    { asset: 'LTC', ratio: 18.6, string: 'LTC: 18.60%' },
    { asset: 'BCH', ratio: 7, string: 'BCH: 7.00%' }
}

Features

Documentation

First, you need to create an instance of the PortfolioManager.

const myManager = new PortfolioManager();

Methods to access data from accounts

init

Enter the account key before the portfolio manager can access personal APIs.

await myManager.init({
    binanceSecret: process.env.BINANCE_SECRET,
    binanceKey: process.env.BINANCE_KEY,
    baseCurrency: "EUR"
});

or

await myManager.init({
    krakenKey: process.env.BINANCE_SECRET,
    krakenSecret: process.env.BINANCE_KEY,
    baseCurrency: "EUR"
});

Parameters:

  • binanceKey: The Binance API key
  • binanceSecret: The Binance API secret
  • krakenKey: The Binance API key
  • krakenSecret: The Binance API secret
  • baseCurrency: The portfolio manager will calculate the portfolio sum in this asset.

For testing purposes, you can add test: true to the config and pass in prices and balances as well.

getPortfolio

Use this function to calculate the value of the user' portfolio:

myManager.getPortfolio()

setGoalState

Set the desired distribution of the assets in your portfolio.

myManager.setGoalState([{
        asset: "ETH",
        name: "Ethereum",
        ratio: 0.145
    }, {
        asset: "XRP",
        name: "Ripple",
        ratio: 0.116
    }, {

Parameters:

  • asset: Specify the currency symbol
  • ratio: The percentage of the desired state (0.7 = 70%)
  • ? name: Name of the curreny

getOrders

Need to set the goal state first. Will return the orders that are required to restructure the portfolio.

myManager.getOrders()

sendOrders

Same as getOrders but actually sends to orders to the Binance API interface.

myManager.sendOrders()

testOrders

Same as sendOrders but it will only send the orders to the DEMO endpoint of the Binance API interface. This can be used to test if the trade parameters are valid.

myManager.testOrders()

Methods to access data from accounts

initPublicClient

Use this init function if you only want to access public data

  await myManager.initPublicClient({
    client: "binance",
    baseCurrency: "EUR"
  });

Parameters:

  • client: Currently only "binance" is supported
  • baseCurrency: The portfolio manager will calculate the portfolio sum in this asset.

calcPortfolio

Use this function to calculate the value of a given portfolio

myManager.calcPortfolio([{
    asset: "ETH",
    free: "1"
  }, {
    asset: "BTC",
    free: "0.07"
  }, {
    asset: "LTC",
    free: "10"
  }, {
    asset: "BNB",
    free: "6"
  }, {
    asset: "XMR",
    free: "7"
  }, {
    asset: "DASH",
    free: "9"
  }])

Known Issues

  • Temporarily removed the trading feature
  • Sometimes the sendOrders method needs to be called multiple times (needs to be fixed)
  • Trades are only possible via the "baseCurrency".
  • Cannot send orders to Kraken exchange
  • Currently only works with Binance and Kraken exchange
  • A lot of room for improvement :)

How to obtain support - Contributing

Feel free to open an issue, leave a comment, or even open a pull request.