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.4

Published

Sdk for the buycoins GraphQL API

Downloads

12

Readme

github-actions-image codecov-img npm-image license-image

Table of content

Basic Overview

The @buycoins/sdk project provides a simple, fully customisable and elegant way to integrate the Buycoins GraphQL API into your Node.js applications. This project strives to always be in sync with the latest API changes.

Features

  • 100% Fully typed queries, mutations and responses
  • 100% tests coverage
  • Fluent and performant GraphQL query builder
  • Promised based builder pattern and fluent API
  • Zero dependencies. Light-weight and highly performant.

Installation

The installation is in two steps: First: get your API keys, second: install the package into your project.

Get API Keys

Before getting started, you would need to request access to the Buycoins API. You may send an email to their support team, stating the application you would love to build. Shouldn't take more than an hour or two to get acces.

Once you do, visit your Buycoins account settings page to generate your API keys:

buycoins-api-settings-page

Install npm package

You may install the package using npm:

npm install --save @buycoins/sdk

Or yarn:

yarn add @buycoins/sdk

Requirements

At the moment, the SDK has been fully tested on Node.js v12.x and 14.x. Versions above v12.x should work fine too.

Quickstart

To quickly get started, let's make an API call to see the current prices of the cryptocurrencies supported by Buycoins.

First, require the buycoins function:

const { buycoins } = require('@buycoins/sdk')

Next, call this function to get an API instance. You can pass in your public key and secret key as arguments into this function.

const { buycoins } = require('@buycoins/sdk')

const api = buycoins('YOWGe1KNuw', 'ed1wDGUuoVkID7rJ58vv0186z0vZ3TfbNXYiPsiC')

If you omit the public and secret key arguments, the sdk would default to using BUYCOINS_PUBLIC_KEY and BUYCOINS_SECRET_KEY environment variables.

On the api instance, the .prices() method would give you an instance of the Prices query. The .get() method on that query makes the API call and resolves with the data:

const { buycoins } = require('@buycoins/sdk')

const api = buycoins()

api.prices().get().then(({ data, errors }) => {
    console.log(data, errors)
})

Customising query fields

For all queries, all the supported GraphQL fields would be fetched. You may control the fields to be queried using the .fields() function and passing a query builder object. Here's an example of sending crypto and getting back a transfer request:

buycoins()
.send()
.litecoin()
.address('xxxx')
.amount('0.04')
.fields([
  'id',
  'fee',
  'status',
  {
    transaction: [
      'id',
      'confirmed',
      {
          address: ['id', 'cryptocurrency']
      }
  }] 
)
.get()

Peer to Peer Trading

Prices

You may get the buy and sell prices of the supported currencies using the .prices() query. The .buy() and .sell() methods on this query can be used to get the buy prices and the sell prices respectively.

const { data, errors } = await buycoins().prices().sell().get()

Price for a single currency

To get the price for a specific currency, use any of the supported currency methods on the query instance.

const { data, errors } = await buycoins().prices().sell().litecoin().get()

Post limit order

To place a limit order, first you need to get a price. Next, call the .limitOrder() query. You may place an order with static or dynamic pricing using the .static() or .dynamic().

const { data } = await buycoins().limitOrder().litecoin().dynamic('0.03422').buy().post()

Post market order

To place a market order, you may use the .marketOrder() query. You may use the .amount() method to set the amount:

const { data } = await buycoins().marketOrder().amount('0.009').sell()

Get Orders

You can retrieve a list of orders you have placed by calling the .orders() query. You can also specify whether to fetch open or completed orders using the .open() and .completed() methods.

const { data } = await buycoins().orders().ethereum().sell().completed().get()

You may want to specify the fields and variables for this query. Here'an example:

const { data } = await buycoins().orders().ethereum().sell().completed().fields([{
  orders: [
    {
      edges: [
        {
          node: ['id', 'cryptocurrency', 'staticPrice']
        }
      ]
    }
  ]
}]).variables({
  root: {
    orders: {
      after:'QnV5Y29pbnNQcmljZS1hMGNmMmQ4Yi1hY2Q0LTRjMGYtOGZkMC1lMjk4NWMxYmU3ZTU='
    }
  }
}).get()

Get Market book

The marketBook() query may be used to retrive the market book.

const { data } = await buycoins().marketBook().usdCoin().sell().get()

Placing orders

Buy

To place a buy order, first you need to get a price. This is required when buying.

Next, call the .buy() query:

const { data: { getPrices: ethereumPrice } } = await buycoins().prices().ethereum().fields(['id']).get()

const { data } = await buycoins().buy().amount('0.0089').ethereum().price(ethereumPrice[0].id).post()

Sell

To place a sell order, first you need to get a price. This is required when selling.

Next, call the .sell() query:

const { data: { getPrices } } = await buycoins().prices().ethereum().get()

const { data } = await buycoins().sell().ethereum().amount('0.9384').price(getPrices[0].id).post()

Sending

Network fees

The .estimatedNetworkFee() query estimates the network fees.

const { data } = await buycoins().estimatedNetworkFee().litecoin().get()

Send

The .send() query may be used to send cryptocurrency to an external address. You may set the external address using the .address() method.

const { data } = await buycoins().send().usdCoin().address('0xd39B6849d2e1dB20BAb50dd7A4F3e0882c744404').get()

Account balances

The .balances() query may be used to get your portfolio balance for any currencies you hold:

const { data } = await buycoins().balances().usdCoin().get()

Receiving

Create address

To receive cryptocurrency, you will first have to create an address on Buycoins using the .createAddress() mutation:

const { data } = await buycoins().createAddress().litecoin().post()

Supported currency methods

These methods may be used to set or filter some queries or mutations by a specific currency.

  • .bitcoin()
  • .litecoin()
  • .usdTether()
  • .usdCoin()
  • .ethereum()
  • .nairaToken()

Contributing

We would love to have you contribute and make this project better. You can contribute by providing documentation, feedback, code changes or implementing new features and improvements. Please read the contributing guide to get started.