Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

lib/models/ConvertedCandle.ts

179

lib/client.ts

@@ -40,2 +40,4 @@ import {

} from "./models";
import { ConvertedCandlesBySymbol } from "./models/ConvertedCandle";
import { ConvertedCandles } from "./models/ConvertedCandles";
import { fromCamelCaseToSnakeCase, fromSnakeCaseToCamelCase } from "./paramStyleConverter"

@@ -90,2 +92,98 @@

//////////////
// ALIASES //
/////////////
// MARKET DATA
/**
* alias of {@link getTicker}
*/
getTickerBySymbol = this.getTicker;
/**
* alias of {@link getTicker}
*/
getTickerOfSymbol = this.getTicker;
/**
* alias of {@link getTickerLastPrice}
*/
getTickerPriceBySymbol = this.getTickerLastPrice;
/**
* alias of {@link getTickerLastPrice}
*/
getTickerPriceOfSymbol = this.getTickerLastPrice;
/**
* Alias of {@link getTradesBySymbol}
*/
getTradesOfSymbol = this.getTradesBySymbol;
/**
* alias of {@link getOrderBook}
*/
getOrderbookBySymbol = this.getOrderBook;
/**
* alias of {@link getOrderBook}
*/
getOrderbookOfSymbol = this.getOrderBook;
/**
* alias of {@link getOrderBookVolume}
*/
getOrderBookVolumeBySymbol = this.getOrderBookVolume;
/**
* alias of {@link getOrderBookVolume}
*/
getOrderBookVolumeOfSymbol = this.getOrderBookVolume;
/**
* alias of {@link getCandlesBySymbol}
*/
getCandlesOfSymbol = this.getCandlesBySymbol;
/**
* alias of {@link getConvertedCandlesBySymbol}
*/
getConvertedCandlesOfSymbol = this.getConvertedCandlesBySymbol;
// SPOT TRADING
/**
* alias of {@link getSpotTradingBalance}
*/
getSpotTradingBalanceOfCurrency = this.getSpotTradingBalance;
/**
* alias of {@link getSpotTradingBalance}
*/
getSpotTradingBalanceByCurrency = this.getSpotTradingBalance;
/**
* alias of {@link getAllTradingCommissions}
*/
getTradingCommissions = this.getAllTradingCommissions;
/**
* alias of {@link getTradingCommission}
*/
getTradingCommissionOfSymbol = this.getTradingCommission;
/**
* alias of {@link getTradingCommission}
*/
getTradingCommissionBySymbol = this.getTradingCommission;
// WALLET MANAGEMENT
/**
* alias of {@link getWalletBalance}
*/
getWalletBalanceOfCurrency = this.getWalletBalance;
/**
* alias of {@link getWalletBalance}
*/
getWalletBalanceByCurrency = this.getWalletBalance;
/**
* alais of {@link getDepositCryptoAddress}
*/
getDepositCryptoAddressByCurrency = this.getDepositCryptoAddress;
/**
* alias of {@link getDepositCryptoAddress}
*/
getDepositCryptoAddressOfCurrency = this.getDepositCryptoAddress;
//////////////////

@@ -399,5 +497,5 @@ // PUBLIC CALLS //

*
* Candels are used for OHLC representation
* Candles are used for OHLC representation
*
* The result contains candles with non-zero volume only (no trades = no candles).
* The result contains candles with non-zero volume only (no trades = no candles).
*

@@ -432,5 +530,5 @@ * Requires no API key Access Rights.

*
* Candels are used for OHLC representation
* Candles are used for OHLC representation
*
* The result contains candles with non-zero volume only (no trades = no candles).
* The result contains candles with non-zero volume only (no trades = no candles).
*

@@ -466,2 +564,75 @@ * Requires no API key Access Rights.

/**
* Gets candles regarding the last price converted to the target currency for all symbols or for the specified symbols
*
* Candles are used for OHLC representation
*
* The result contains candles with non-zero volume only (no trades = no candles).
*
* Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid or ask price, the last price is returned.
*
* Requires no API key Access Rights.
*
* https://api.exchange.cryptomkt.com/#candles
*
* @param {object} [params]
* @param {string[]} [params.targetCurrency] Target currency for conversion
* @param {string[]} [params.symbols] Optional. A list of symbol ids
* @param {PERIOD} [params.period] Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
* @param {SORT} [params.sort] Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
* @param {string} [params.from] Optional. Initial value of the queried interval. As Datetime
* @param {string} [params.till] Optional. Last value of the queried interval. As Datetime
* @param {number} [params.limit] Optional. Candles per query. Defaul is 10. Min is 1. Max is 1000
*
* @return A class with the targetCurrency and data with a map with a list of candles for each symbol of the query. indexed by symbol.
*/
getConvertedCandles(params?: {
targetCurrency: string;
symbols?: string[];
period?: PERIOD;
sort?: SORT;
from?: string;
till?: string;
limit?: number;
}): Promise<ConvertedCandles> {
return this.get("public/converted/candles", params);
}
/**
* Gets candles regarding the last price converted to the target currency for the specified symbol
*
* Candles are used for OHLC representation
*
* The result contains candles with non-zero volume only (no trades = no candles).
*
* Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid or ask price, the last price is returned.
*
* Requires no API key Access Rights.
*
* https://api.exchange.cryptomkt.com/#candles
*
* @param {string[]} symbol A symbol id
* @param {object} params
* @param {string[]} params.targetCurrency Target currency for conversion
* @param {PERIOD} [params.period] Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
* @param {SORT} [params.sort] Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
* @param {string} [params.from] Optional. Initial value of the queried interval. As Datetime
* @param {string} [params.till] Optional. Last value of the queried interval. As Datetime
* @param {number} [params.limit] Optional. Candles per query. Defaul is 10. Min is 1. Max is 1000
*
* @return An object with the targetCurrency and data with a list of candles for the symbol of the query.
*/
getConvertedCandlesBySymbol(
symbol: string,
params?: {
targetCurrency: string;
period?: PERIOD;
sort?: SORT;
from?: string;
till?: string;
limit?: number;
}): Promise<ConvertedCandlesBySymbol> {
return this.get(`public/converted/candles/${symbol}`, params);
}
/////////////////////////

@@ -468,0 +639,0 @@ // AUTHENTICATED CALLS //

11

lib/paramStyleConverter.ts

@@ -42,10 +42,9 @@ export const fromCamelCaseToSnakeCase = (obj: any): any => {

const camelCaseToSnakeCase = (camelCase: string) => {
return camelCase.replace(/([A-Z])/g, letter => `_${letter.toLowerCase()}`);
}
const camelCaseToSnakeCase = (camelCase: string) => camelCase
.replace(/([A-Z])/g, letter => `_${letter.toLowerCase()}`)
const snakeCaseToCamelCase = (value: string) =>
value.replace(/([_][a-z])/g, _letter => _letter.replace('_', '').toUpperCase()
);
const snakeCaseToCamelCase = (value: string) => value
.replace(/([_][a-z])/g, _letter => _letter.replace('_', '').toUpperCase());
const isObject = (value: any) => {

@@ -52,0 +51,0 @@ return typeof (value) == "object";

@@ -112,2 +112,3 @@ import { EventEmitter } from "events";

}
protected requestList({ method, params: paramsRaw = {}, responseCount = 1 }: { method: any; params?: {}; responseCount?: number; }): Promise<unknown> {

@@ -114,0 +115,0 @@ const params = fromCamelCaseToSnakeCase(paramsRaw)

@@ -77,3 +77,3 @@ //@ts-ignore

if ("error" in response) {
reject(new CryptomarketAPIException(response));
reject(new CryptomarketAPIException(response.error));
return;

@@ -163,3 +163,3 @@ }

*
* subscription is for all symbols or for the specified symbols
* subscription is for the specified symbols
*

@@ -176,5 +176,5 @@ * normal subscriptions have one update message per symbol

* @param {function} callback a function that recieves notifications as a dict of candles indexed by symbol, and the type of notification (either SNAPSHOT or UPDATE)
* @param {PERIOD} [params.period] Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
* @param {string[]} [params.symbols] Optional. A list of symbol ids
* @param {number} params.limit Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0
* @param {PERIOD} params.period A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month).
* @param {string[]} params.symbols A list of symbol ids
* @param {number} [params.limit] Optional. Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0
* @return A promise that resolves when subscribed with a list of the successfully subscribed symbols

@@ -200,2 +200,37 @@ */

/**
* subscribes to a feed of candles regarding the last price converted to the target currency * for the specified symbols
*
* subscription is only for the specified symbols
*
* normal subscriptions have one update message per symbol
*
* Requires no API key Access Rights
*
* https://api.exchange.cryptomkt.com/#subscribe-to-converted-candles
*
* @param {function} callback a function that recieves notifications as a dict of candles indexed by symbol, and the type of notification (either SNAPSHOT or UPDATE)
* @param {function} params.targetCurrency Target currency for conversion
* @param {PERIOD} params.period A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month).
* @param {string[]} params.symbols A list of symbol ids
* @param {number} [params.limit] Optional. Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0
* @return A promise that resolves when subscribed with a list of the successfully subscribed symbols
*/
subscribeToConvertedCandles({
callback,
params: { period, ...params },
}: {
callback: (
notification: { [x: string]: WSCandle[] },
type: NOTIFICATION_TYPE
) => any;
params: { targetCurrency: string, period: PERIOD; symbols: string[]; limit?: number };
}): Promise<string[]> {
return this.makeSubscription({
channel: `converted/candles/${period}`,
callback: parseMapListInterceptor(callback, parseWSCandle),
params,
});
}
/**
* subscribe to a feed of mini tickers

@@ -202,0 +237,0 @@ *

@@ -233,2 +233,7 @@ import {

/**
* alias of {@link getSpotTradingBalance}
*/
getSpotTradingBalanceOfCurrency = this.getSpotTradingBalance;
/**
* Get the personal trading fee rates for all symbols

@@ -258,2 +263,11 @@ *

/**
* alias of {@link getSpotFee}
*/
getSpotFeeOfSymbol = this.getSpotFee;
/**
* alias of {@link getSpotFee}
*/
getSpotFeeBySymbol = this.getSpotFee;
///////////////////

@@ -260,0 +274,0 @@ // subscriptions //

@@ -70,2 +70,11 @@ import { AuthClient } from "./authClient";

/**
* alias of {@link getWalletBalance}
*/
getWalletBalanceOfCurrency = this.getWalletBalance;
/**
* alias of {@link getWalletBalance}
*/
getWalletBalanceByCurrency = this.getWalletBalance;
/**
* Get the transaction history of the account

@@ -72,0 +81,0 @@ *

{
"name": "cryptomarket",
"version": "3.0.0",
"version": "3.1.0",
"description": "The CryptoMarket for Node.js",

@@ -5,0 +5,0 @@ "homepage": "https://www.cryptomkt.com",

@@ -23,24 +23,24 @@ # CryptoMarket-javascript

```javascript
```typescript
const { Client } = require("cryptomarket");
// instance a client
let apiKey = "AB32B3201";
let apiSecret = "21b12401";
let client = new Client(apiKey, apiSecret);
const apiKey = "AB32B3201";
const apiSecret = "21b12401";
const client = new Client(apiKey, apiSecret);
// get currencies
let currencies = await client.getCurrencies();
const currencies = await client.getCurrencies();
// get order books
let orderBook = await client.getOrderBook("EOSETH");
const orderBook = await client.getOrderBook("EOSETH");
// get your account balances
let accountBalances = await client.getWalletBalances();
const accountBalances = await client.getWalletBalances();
// get your trading balances
let tradingBalances = await client.getSpotTradingBalances();
const tradingBalances = await client.getSpotTradingBalances();
// move balance from wallet to spot trading
let result = await client.transferBetweenWalletAndExchange({
const result = await client.transferBetweenWalletAndExchange({
currency: "EOS",

@@ -53,6 +53,6 @@ amount: "3.2",

// get your active orders
let orders = await client.getAllActiveSpotOrders("EOSETH");
const activeOrders = await client.getAllActiveSpotOrders("EOSETH");
// create a new order
let newOrder = await client.createOrder({
const newOrder = await client.createOrder({
symbol: "EOSETH",

@@ -59,0 +59,0 @@ side: "buy",

@@ -254,2 +254,40 @@ import assert from "assert";

});
describe("Get Converted candles", () => {
it("for all symbols", async function () {
this.timeout(0);
let candles = await client.getConvertedCandles({ targetCurrency: "ETH" });
assert(!emptyDict(candles), "empty list of candles");
assert(
goodDict((candleList) => goodList(goodCandle, candleList), candles.data),
"not good candles"
);
});
it("for 2 symbols", async function () {
this.timeout(0);
let candles = await client.getConvertedCandles({
targetCurrency: "ETH",
symbols: ["EOSETH", "PAXGBTC"],
period: PERIOD._1_HOUR,
limit: 2,
});
assert(dictSize(candles, 2), "wrong number of symbols");
assert(
goodDict((candleList) => goodList(goodCandle, candleList), candles.data),
"not good candles"
);
});
});
describe("Get converted candles Of Symbol", () => {
it("with period and limit", async function () {
this.timeout(0);
let candles = await client.getConvertedCandlesBySymbol("ADAETH", {
targetCurrency: "BTC",
period: PERIOD._30_MINUTES,
limit: 2,
});
assert(listSize(candles.data, 2), "wrong number of candles");
assert(goodList(goodCandle, candles.data), "not good candles");
});
});
});

@@ -16,3 +16,3 @@ import assert from "assert";

} from "../testHelpers";
const keys = require("../../keys.json");
const keys = require("../../../../keys.json");

@@ -19,0 +19,0 @@ describe("spot trading", () => {

import assert from "assert";
import { Client } from "../../lib";
import { goodList, goodOrder, goodTrade } from "../testHelpers";
const keys = require("../../keys.json");
const keys = require("../../../../keys.json");
import "mocha";

@@ -7,0 +6,0 @@

@@ -15,3 +15,3 @@ import assert from "assert";

import { Address } from "../../lib/models";
const keys = require("../../keys.json");
const keys = require("../../../../keys.json");

@@ -18,0 +18,0 @@ describe("wallet management", () => {

@@ -42,3 +42,2 @@ import { expect } from "chai";

it("gets a feed of candles", async function () {
// TODO: unknown state
this.timeout(0);

@@ -58,2 +57,20 @@ await wsclient.connect();

describe("subscribe to converted candles", function () {
it("gets a feed of candles", async function () {
this.timeout(0);
await wsclient.connect();
await wsclient.subscribeToConvertedCandles({
callback: checkGoodMapListValues(goodWSCandle),
params: {
period: PERIOD._1_MINUTE,
targetCurrency: "BTC",
symbols: ["EOSETH", "ETHBTC"],
limit: 3,
},
});
await timeout(3 * SECOND);
});
});
describe("subscribe to mini ticker", function () {

@@ -60,0 +77,0 @@ it("gets a feed of mini tickers (with are candles)", async function () {

@@ -1,2 +0,3 @@

const keys = require("../../keys.json");
const keys = require("../../../../keys.json");
import { expect } from "chai";

@@ -3,0 +4,0 @@ import "mocha";

@@ -1,2 +0,3 @@

const keys = require("../../keys.json");
const keys = require("../../../../keys.json");
import { expect } from "chai";

@@ -3,0 +4,0 @@ import { WSTradingClient } from "../../lib";

@@ -1,2 +0,3 @@

const keys = require("../../keys.json");
const keys = require("../../../../keys.json");
import { expect } from "chai";

@@ -3,0 +4,0 @@ import "mocha";

@@ -5,4 +5,5 @@ import { expect } from "chai";

import { SECOND, goodBalance, goodTransaction, timeout } from "../testHelpers";
const keys = require("../../keys.json");
const keys = require("../../../../keys.json");
describe("wallet transactions", function () {

@@ -9,0 +10,0 @@ let wsclient: WSWalletClient;

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