Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cryptomarket

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cryptomarket

The CryptoMarket for Node.js

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-28.12%
Maintainers
1
Weekly downloads
 
Created
Source

CryptoMarket-javascript

main page

sign up in CryptoMarket.

Installation

To install Cryptomarket use npm

npm install cryptomarket

Documentation

This sdk makes use of the api version 3 of cryptomarket.

Quick Start

rest client

const { Client } = require("cryptomarket");

// instance a client
let apiKey = "AB32B3201";
let apiSecret = "21b12401";
let client = new Client(apiKey, apiSecret);

// get currencies
let currencies = await client.getCurrencies();

// get order books
let orderBook = await client.getOrderBook("EOSETH");

// get your account balances
let accountBalances = await client.getWalletBalances();

// get your trading balances
let tradingBalances = await client.getSpotTradingBalances();

// move balance from wallet to spot trading
let result = await client.transferBetweenWalletAndExchange({
  currency: "EOS",
  amount: "3.2",
  source: Account.Wallet,
  destination: Account.Spot,
});

// get your active orders
let orders = await client.getAllActiveSpotOrders("EOSETH");

// create a new order
let newOrder = await client.createOrder({
  symbol: "EOSETH",
  side: "buy",
  quantity: "10",
  price: "10",
});

websocket client

There are three websocket clients, the market data client, the spot trading client and the wallet client. The market data client requires no authentication, while the spot trading client and the wallet client do require it.

All websocket methods return promises. Subscriptions also take in a function of two parameters, the notification data, and the notification type. The notification type is of type NOTIFICATION_TYPE, and is either SNAPSHOT, NOTIFICATION or DATA.

The documentation of a specific subscriptions explains with of this types of notification uses.

MarketDataClient

Example of use of the market data client

// instantiate a market data client
const wsclient = new WSMarketDataClient();

// make a partial orderbook subscription

//    make subscription
await marketDataClient.subscribeToPartialOrderBook(
  callback:(notification, type) => {
    if (type === NOTIFICATION_TYPE.DATA) {
      System.out.println("this subscription only recieves data notifications");
    }
    for (const symbol in notification) {
      console.log(symbol);
      const orderbook = notification[symbol];
      console.log(orderbook);
    }
  },
  params: {
    speed: ORDER_BOOK_SPEED._100_MS,
    depth: DEPTH._5,
    symbols: ["EOSETH", "ETHBTC"],
  }
);


SpotTradingClient

Example of use of the spot trading client

const apiKey = "AB32B3201";
const apiSecret= "21b12401";

// instantiate a spot trading websocket client with a window of 10 seconds
const wsclient = new WSTradingClient(apiKey, apiSecret, 10_000);

// connect the client (and authenticate it automatically)
await wsclient.connect();

// get all the spot trading balances
const balanceList = await tradingClient.getSpotTradingBalances()
console.log(balanceList);


let clientOrderID = Math.floor(Date.now() / 1000).toString();
// make a spot order
const report = await tradingClient.createSpotOrder({
  clientOrderId: clientOrderID,
  symbol: "EOSETH",
  side: "sell",
  quantity: "0.01",
  price: "1000",
}
console.log(report);

WalletClient

Example of use of the wallet client

// instantiate a wallet websocket client with a default window of 10 seconds
const wsclient = new WSWalletClient(keys.apiKey, keys.apiSecret);

// get a list of transactions
const transactionList = await walletClient.getTransactions({
  currencies: ["EOS"],
  limit: 3,
});
console.log(transactionList);

// subscribe to a feed of transactions
await walletClient.subscribeToTransactions((notification, type) => {
  if (type === NOTIFICATION_TYPE.UPDATE) {
    console.log("this subscription only recieves update notifications");
  }
  console.log(notification);
});

error handling


{ CryptomarketSDKException, Client, WSMarketDataClient } = require('cryptomarket')
// exceptions derive from the CryptomarketSDKException class.

const client = new Client()
// catch a failed transaction
try {
    const order = await client.createOrder({
        'symbol':'EOSETHH',  // non existant symbol
        'side':'sell',
        'quantity':'10',
        'price':'10'})
} catch (error) {
    console.log(error)
}

const wsclient = new WSMarketDataClient()
await wsclient.connect();

// catch missing arguments
try {
    await wsclient.subscribeToMiniTickers()
} catch (error) {
    console.log(error)
}

Constants

All constants used for calls are in the constants module.

Checkout our other SDKs

python sdk

java sdk

go sdk

ruby sdk

Keywords

FAQs

Package last updated on 13 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc