Coder Social home page Coder Social logo

vansergen / poloniex-node-api Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 6.0 6.17 MB

Node.js library for Poloniex

Home Page: https://vansergen.github.io/poloniex-node-api/

License: MIT License

TypeScript 99.95% Shell 0.05%
poloniex crypto cryptoexchange api cryptocurrency

poloniex-node-api's Introduction

Poloniex Node.js API CI Status npm version Coverage Status Known Vulnerabilities code style: prettier Contributor Covenant semantic-release Conventional Commits NPM license node version npm downloads GitHub top language

Node.js library for Poloniex.

Installation

npm install poloniex-node-api

Usage

See here

import { PublicClient } from "poloniex-node-api";
const client = new PublicClient();
const markets = await client.getMarkets();
const symbol = "ETH_BTC";
const volume = await client.getMarket({ symbol });
const currency = "BNB";
const currency_info = await client.getCurrency({ currency });

or

const includeMultiChainCurrencies = true;
const all = await client.getCurrency({ includeMultiChainCurrencies });
const time = await client.getSystemTime();
const prices = await client.getPrices();
const symbol = "ETH_BTC";
const price = await client.getPrice({ symbol });
const prices = await client.getMarkPrices();
const symbol = "ZEC_USDT";
const price = await client.getMarkPrice({ symbol });
const symbol = "ZEC_USDT";
const prices = await client.getMarkPriceComponents({ symbol });
const symbol = "ETH_BTC";
const limit = 5;
const scale = "0.01";
const book = await client.getOrderBook({ symbol, limit, scale });
const symbol = "ETH_BTC";
const interval = "HOUR_1";
const limit = 2;
const endTime = Date.now();
const startTime = endTime - 1000 * 60 * 60 * 24;
const candles = await client.getOrderBook({
  symbol,
  interval,
  limit,
  startTime,
  endTime,
});
const symbol = "ETH_BTC";
const limit = 2;
const trades = await client.getPublicTrades({ symbol, limit });
const tickers = await client.getTickers();
const symbol = "ETH_BTC";
const ticker = await client.getTicker({ symbol });
const currency = "ETH";
const collateral = await client.getCollateral({ currency });

or

const all = await client.getCollateral();
const symbol = "ETH_BTC";
const ticker = await client.getTicker({ symbol });
import { AuthenticatedClient } from "poloniex-node-api";
const key = "poloniex-api-key";
const secret = "poloniex-api-secret";
const client = new AuthenticatedClient({ key, secret });
const accounts = await client.getAccounts();
const balances = await client.getAccountBalances();
const activity = await client.getAccountActivity();
const currency = "USDT";
const amount = "10.5";
const fromAccount = "SPOT";
const toAccount = "FUTURES";
const { transferId } = await client.transfer({
  currency,
  amout,
  fromAccount,
  toAccount,
});
const transfers = await client.getAccountTransfers();
const fee_info = await client.getFeeInfo();
const wallets = await client.getWallets();
const { deposits, withdrawals } = await client.getWalletsActivity();
const { address } = await client.newAddress();
const { withdrawalRequestsId } = await client.withdraw();
const info = await client.getMargin();
const status = await client.getBorrowStatus();
const size = await client.getMaxSize();
const symbol = "BTC_USDT";
const type = "LIMIT";
const quantity = "100";
const side = "BUY";
const price = "40000.50000";
const timeInForce = "IOC";
const clientOrderId = "1234Abc";
const { id, clientOrderId } = await client.createOrder({
  symbol,
  type,
  quantity,
  side,
  price,
  timeInForce,
  clientOrderId,
});

or

const symbol = "BTC_USDT";
const quantity = "100";
const side = "BUY";
const { id } = await client.createOrder({ symbol, quantity, side });
const orders = [
  { symbol: "BTC_USDT", amount: "100", side: "BUY" },
  {
    symbol: "BTC_USDT",
    type: "LIMIT",
    quantity: "100",
    side: "BUY",
    price: "40000.50000",
    timeInForce: "IOC",
    clientOrderId: "1234Abc",
  },
  { symbol: "ETH_USDT", amount: "1000", side: "BUY" },
  {
    symbol: "TRX_USDT",
    type: "LIMIT",
    quantity: "15000",
    side: "SELL",
    price: "0.0623423423",
    timeInForce: "IOC",
    clientOrderId: "456Xyz",
  },
];
const response = await client.createOrders(orders);
const id = "234235233423";
const price = "18000";
const clientOrderId = "1234";
const response = await client.replaceOrder({ id }, { price, clientOrderId });

or

const clientOrderId = "1234Abc";
const price = "18000";
const quantity = "20";
const response = await client.replaceOrder(
  { clientOrderId },
  { price, quantity },
);
const symbol = "ELON_USDC";
const side = "SELL";
const direction = "PRE";
const limit = 10;
const orders = await client.getOpenOrders({ symbol, side, direction, limit });

or

const orders = await client.getOpenOrders();
const id = "21934611974062080";
const order = await client.getOrder({ id });

or by clientOrderId

const clientOrderId = "123";
const order = await client.getOrder({ clientOrderId });
const id = "21934611974062080";
const order = await client.cancelOrder({ id });

or by clientOrderId

const clientOrderId = "123";
const order = await client.cancelOrder({ clientOrderId });
const orders = [{ id: "12345" }, { clientOrderId: "myId-1" }];
const results = await client.cancelOrders(orders);
const symbols = ["BTC_USDT", "ETH_USDT"];
const accountTypes = ["SPOT"];
const results = await client.cancelAllOrders({ symbols, accountTypes });

or (to cancel all orders)

const results = await client.cancelAllOrders();
const timeout = 60;
const status = await client.killSwitch({ timeout });
const status = await client.getKillSwitch();
const symbol = "BTC_USDT";
const side = "BUY";
const type = "STOP_LIMIT";
const quantity = "100";
const price = "60100.00";
const timeInForce = "FOK";
const stopPrice = "60000.00";
const clientOrderId = "999999910";
const { id, clientOrderId } = await client.createSmartOrder({
  symbol,
  side,
  type,
  quantity,
  price,
  timeInForce,
  stopPrice,
  clientOrderId,
});
const id = "234235233423";
const stopPrice = "18000";
const clientOrderId = "1234Abc";
const response = await client.replaceOrder(
  { id },
  { stopPrice, clientOrderId },
);

or by clientOrderId

const clientOrderId = "1234Abc";
const price = "18000";
const quantity = "20";
const response = await client.replaceOrder(
  { clientOrderId },
  { stopPrice, quantity },
);
const limit = 10;
const orders = await client.getOpenSmartOrders({ limit });

or

const orders = await client.getOpenSmartOrders();
const id = "14368195657859072";
const order = await client.getSmartOrder({ id });

or by clientOrderId

const clientOrderId = "18113";
const order = await client.getSmartOrder({ clientOrderId });
const id = "9876543";
const order = await client.cancelSmartOrder({ id });

or by clientOrderId

const clientOrderId = "88888";
const order = await client.cancelSmartOrder({ clientOrderId });
const orders = [{ id: "12345" }, { clientOrderId: "myId-1" }];
const results = await client.cancelSmartOrders(orders);
const symbols = ["BTC_USDT", "ETH_USDT"];
const accountTypes = ["SPOT"];
const results = await client.cancelAllSmartOrders({ symbols, accountTypes });

or (to cancel all orders)

const results = await client.cancelAllSmartOrders();
const type = ["MARKET", "LIMIT"];
const side = "BUY";
const symbol = "TRX_USDC";
const states = ["FILLED", "PARTIALLY_CANCELED"];
const limit = 10;
const hideCancel = true;
const startTime = 1649106321040;
const endTime = 1649427963598;
const orders = await client.getOrders({
  type,
  side,
  symbol,
  states,
  limit,
  hideCancel,
  startTime,
  endTime,
});
const limit = 10;
const endTime = 1648635115535;
const startTime = endTime - 1000 * 60 * 60;
const direction = "PRE";
const symbols = ["BTC_USDT", "ETH_USDT"];
const trades = await client.getTrades({
  limit,
  startTime,
  endTime,
  direction,
  symbols,
});
const id = "30249408733945856";
const trades = await client.getOrderTrades({ id });
const key = "<POLONIEX API KEY>";
const secret = "<POLONIEX API SECRET>";
const client = new WebSocketClient({ key, secret })
  .on("message", (msg) => {
    console.log("Message:\t", msg);
  })
  .on("error", (error) => {
    console.log("Error:\t", error);
  });
await client.connectPublicWS();
await client.connectPrivateWS();
await client.disconnectPublicWS();
await client.disconnectPrivateWS();
await client.auth();
const ac = new AbortController();
setTimeout(() => {
  ac.abort();
}, 10000).unref();
await client.pingPublic({ signal: ac.signal });
await client.pingPrivate();
await client.unsubscribePublic();
await client.unsubscribePrivate();
const { subscriptions } = await client.getPublicSubscriptions();
const { subscriptions } = await client.getPrivateSubscriptions();
const payload = {
  event: "subscribe",
  channel: ["candles_minute_1", "ticker"],
  symbols: ["BTC_USDT", "ETH_USDT"],
};
await client.send(payload, "public");

or

const payload = {
  event: "subscribe",
  channel: ["orders", "balances"],
  symbols: ["all"],
};
await client.send(payload, "private");
  • subscribeCandles
await client.subscribeCandles();
  • unsubscribeCandles
await client.unsubscribeCandles();
  • candles
const channel = "candles_day_1";
for await (const candle of client.candles()) {
  console.log(candle);
}
  • subscribeTrades
const symbols = ["BTC_USDT", "ETH_USDT"];
await client.subscribeTrades({ symbols });
  • unsubscribeTrades
const symbols = ["BTC_USDT"];
await client.unsubscribeTrades({ symbols });
  • trades
for await (const trade of client.trades()) {
  console.log(trade);
}
  • subscribeTicker
const symbols = "all";
await client.subscribeTicker({ symbols });
  • unsubscribeTicker
const symbols = "all";
await client.unsubscribeTicker({ symbols });
  • tickers
for await (const ticker of client.tickers()) {
  console.log(ticker);
}
  • subscribeBook
await client.subscribeBook();
  • unsubscribeBook
const symbols = "all";
await client.unsubscribeBook({ symbols });
  • books
const depth = 10;
for await (const book of client.books({ depth })) {
  console.log(book);
}
  • subscribeLv2Book
const symbols = ["BTC_USDT"];
await client.subscribeLv2Book({ symbols });
  • unsubscribeLv2Book
const symbols = "all";
await client.unsubscribeLv2Book({ symbols });
  • booksLv2
for await (const book of client.booksLv2()) {
  console.log(book);
}
  • subscribeOrders
const symbols = "all";
await client.subscribeOrders({ symbols });
  • unsubscribeOrders
const symbols = "all";
await client.unsubscribeOrders({ symbols });
  • orders
for await (const order of client.orders()) {
  console.log(order);
}
  • subscribeBalances
await client.subscribeBalances();
  • unsubscribeBalances
await client.unsubscribeBalances();
  • balances
for await (const balance of client.balances()) {
  console.log(balance);
}

Test

npm test

Coverage

npm run coverage

poloniex-node-api's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar semantic-release-bot avatar snyk-bot avatar vansergen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

poloniex-node-api's Issues

An in-range update of @typescript-eslint/eslint-plugin is breaking the build 🚨

The devDependency @typescript-eslint/eslint-plugin was updated from 2.18.0 to 2.19.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/eslint-plugin is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: node-13: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-10: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-11: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-12: Your tests failed on CircleCI (Details).

Release Notes for v2.19.0

2.19.0 (2020-02-03)

Bug Fixes

  • eslint-plugin: [embt] fix allowTypedFunctionExpressions (#1553) (9e7d161)
  • eslint-plugin: [require-await] improve performance (#1536) (45ae0b9)
  • typescript-estree: fix regression introduced in #1525 (#1543) (bec4572)
  • typescript-estree: persisted parse and module none (#1516) (7c70323)

Features

  • eslint-plugin: [no-extra-non-null-assert] add fixer (#1468) (54201ab)
  • eslint-plugin: [no-float-prom] fixer + msg for ignoreVoid (#1473) (159b16e)
  • eslint-plugin: [unbound-method] support bound builtins (#1526) (0a110eb)
  • eslint-plugin: add extension [no-dupe-class-members] (#1492) (b22424e)
  • eslint-plugin: add no-unnecessary-boolean-literal-compare (#242) (6bebb1d)
  • eslint-plugin: add switch-exhaustiveness-check rule (#972) (9e0f6dd)
  • eslint-plugin: support negative matches for filter (#1517) (b24fbe8)
Commits

The new version differs by 17 commits.

  • bec59ff chore: publish v2.19.0
  • 0a110eb feat(eslint-plugin): [unbound-method] support bound builtins (#1526)
  • 9e0f6dd feat(eslint-plugin): add switch-exhaustiveness-check rule (#972)
  • 7c70323 fix(typescript-estree): persisted parse and module none (#1516)
  • 159b16e feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid (#1473)
  • b22424e feat(eslint-plugin): add extension [no-dupe-class-members] (#1492)
  • 9e7d161 fix(eslint-plugin): [embt] fix allowTypedFunctionExpressions (#1553)
  • 45ae0b9 fix(eslint-plugin): [require-await] improve performance (#1536)
  • 39929b2 test(typescript-estree): fix issue in jest config (#1559)
  • 95174d5 docs(eslint-plugin): corrected typo unbounded-method (#1558)
  • 8643d56 chore(eslint-plugin): remove redundant code and update tests (#1557)
  • 569259e test: enable isolatedModules for tests (#1546)
  • b24fbe8 feat(eslint-plugin): support negative matches for filter (#1517)
  • 6613fad test: update jest and babel dependencies (#1530)
  • 54201ab feat(eslint-plugin): [no-extra-non-null-assert] add fixer (#1468)

There are 17 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of lint-staged is breaking the build 🚨

The devDependency lint-staged was updated from 10.0.2 to 10.0.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lint-staged is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: node-13: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-12: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-10: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-8: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-9: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-11: Your tests failed on CircleCI (Details).

Release Notes for v10.0.3

10.0.3 (2020-01-27)

Bug Fixes

  • correctly restore untracked files after running (#780) (4010db0)
Commits

The new version differs by 1 commits.

  • 4010db0 fix: correctly restore untracked files after running (#780)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rpc-request is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency rpc-request was updated from 4.0.7 to 4.0.8.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rpc-request is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ ci/circleci: node-11: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-12: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-13: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-10: Your tests failed on CircleCI (Details).

Release Notes for v4.0.8

Changes

  • Update dependencies #25
Commits

The new version differs by 18 commits.

  • b5447f4 Merge pull request #25 from vansergen/dependencies
  • f835b57 metadata: bump version to 4.0.8
  • 6a664d1 chore: add .npmignore
  • 3f9f9d4 chore: update tsconfig
  • 1472ac4 chore: add build folder to gitignore
  • d1a0fa6 ci: trigger ci on push
  • dff5373 dependencies: update request to v2.88.2
  • eb10583 devDependencies: update @typescript-eslint/eslint-plugin to v2.24.0
  • c3f146b devDependencies: update @typescript-eslint/parser to v2.24.0
  • d95afe6 devDependencies: update @types/mocha to v7.0.2
  • 4079e7e devDependencies: update coveralls to v3.0.11
  • bbe780c devDependencies: update husky to v4.2.3
  • 17a779f devDependencies: update lint-staged to v10.0.8
  • e0c427c devDependencies: update mocha to v7.1.1
  • bba1e01 devDependencies: update ts-node to v8.7.0

There are 18 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @typescript-eslint/parser is breaking the build 🚨

The devDependency @typescript-eslint/parser was updated from 2.19.0 to 2.19.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: node-13: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-12: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-10: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-11: Your tests failed on CircleCI (Details).

Release Notes for v2.19.1

2.19.1 (2020-02-10)

Bug Fixes

  • eslint-plugin: [unbound-method] blacklist a few unbound natives (#1562) (4670aab)
  • typescript-estree: ts returning wrong file with project references (#1575) (4c12dac)
Commits

The new version differs by 5 commits.

  • 1c8f0df chore: publish v2.19.1
  • 4c12dac fix(typescript-estree): ts returning wrong file with project references (#1575)
  • e9cf734 docs(eslint-plugin): fix typo in readme
  • 10d86b1 docs(eslint-plugin): [no-dupe-class-members] fix typo (#1566)
  • 4670aab fix(eslint-plugin): [unbound-method] blacklist a few unbound natives (#1562)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.