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

buycoins-sdk

v1.0.0

Published

SDK for buycoins graphql API

Downloads

10

Readme

buycoins-sdk

Nodejs SDK for Buycoins GraphQL API

Installation

npm install buycoins-sdk

Documentation

Visit https://developers.buycoins.africa/ for the official buycoins documentation.

Features

Accounts

  • Create Virtual Deposit Account
  • Create Cryptocurrency Address

P2P

  • Post Limit Order
  • Post Market Order
  • Get Orders
  • Get Market Book

Orders

  • get Prices
  • Buy cryptocurrency
  • Send cryptocurrency

Transactions

  • Network Fees
  • Send Cryptocurrency
  • Account Balances

Webhooks

  • Verification
  • Sign Payload

Usage

Every API requests requires authentication. The BuyCoins constructor needs to be instantiated with your buycoins username (Public Key) and password (Secret Key) which can be generated in the dashboard

const {Buycoins} = require("buycoins-sdk");

const buycoins = new BuyCoins({
  username: process.env.BUYCOINS_PUBLIC_KEY,
  password: process.env.BUYCOINS_SECRET_KEY,
});

or using ES Modules

import { BuyCoins } from "buycoins-sdk";

const buycoins = new BuyCoins({
  username: process.env.BUYCOINS_PUBLIC_KEY,
  password: process.env.BUYCOINS_SECRET_KEY,
});

All methods are promised based.

Accounts

// create a virtual bank account
buycoins.accounts
  .createDepositAccount("john doe")
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
  
 // create Cryptocurrency address to receive coins
buycoins.accounts
  .createAddress("bitcoin")
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

P2P

// Place a limit order
buycoins.p2p
  .postLimitOrder({
    coinAmount: 0.01,
    orderSide: "buy",
    priceType: "static",
    staticPrice: 6000000,
  })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
// Place a market order
buycoins.p2p
  .postMarketOrder({
    coinAmount: 0.01,
    orderSide: "buy",
    cryptocurrency: "bitcoin"
  })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// Retrieve all your orders
buycoins.p2p
  .getOrders()
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
// get all your open orders
buycoins.p2p
  .getOrders({status: "open"})
  .then((result) => {
    console.log("RESULT");
    console.log(result);
  })
  .catch((error) => {
    console.log(error);
  });
  
// get all completed orders for litecoin on the buy side
buycoins.p2p
  .getOrders({ status: "completed", cryptocurrency: "litecoin", side: "buy" })
  .then((result) => {
    console.log("RESULT");
    console.log(result);
  })
  .catch((error) => {
    console.log(error);
  });

Orders

// get active active prices
buycoins.orders
  .getPrices()
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// get bitcoin price
buycoins.orders
  .getPrices({ cryptocurrency: "bitcoin" })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
// Buy cryptocurrency
buycoins.orders
  .buy({
    price:
      "QnV5Y29pbnNQcmljZS00ZGEyMWNjYi1hNzRkLTQyYmYtOWU5MC05YjNkZWVlMjdlMWM=",
    coinAmount: 0.01,
    cryptocurrency: "bitcoin",
  })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
 // Sell cryptocurrency
 buycoins.orders
  .sell({
    price:
      "QnV5Y29pbnNQcmljZS00ZGEyMWNjYi1hNzRkLTQyYmYtOWU5MC05YjNkZWVlMjdlMWM=",
    coinAmount: 0.01,
    cryptocurrency: "bitcoin",
  })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

Transactions

// get estimated network fees before sending litecoin
buycoins.transactions
  .getEstimatedNetworkFee({ amount: 100, cryptocurrency: "litecoin" })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
// Check Cryptocurrency account balances
buycoins.transactions
  .getBalances()
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
  
// check bitcoin account balance
buycoins.transactions
  .getBalances("bitcoin")
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// send bitcoin to address
buycoins.transactions
  .send({ amount: 100, address: "1MmyYvSEYLCPm45Ps6vQin1heGBv3UpNbf", cryptocurrency: "bitcoin" })
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

Webhook

// sign events sent to webhook url with webhook token
const hash = buycoins.webhook.sign(event, webhook_token);

//verify that requests to your Webhook URL are coming from BuyCoins
const isValid = buycoins.webhook.verify(event, webhook_token, webhook_signature);

Make a custom request

Sometimes you might need to make a request with your own custom queries and mutation. BuyCoins exposes a makeRequest method for this usecase

const query = `mutation($accountName: String!) {
  createDepositAccount(accountName: $accountName) {
    accountNumber
    accountName
    accountType
    bankName
    accountReference
  }
}
`;

const variables = {
  accountName: "john doe",
};

buycoins
  .makeRequest(query, variables)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

Development

See an issue or something you think can be improved? Open an issue or clone the project and send a pull request with your changes.

Tests

You can run the unit tests by executing npm test

License

Licensed under the MIT license.