coins-pro

1.1.2 • Public • Published

coins-pro

Version npm

coins-pro is an API wrapper for Coins Pro https://exchange.coins.asia written in NodeJS

API Documentation: https://exchange.coins.asia/assets/docs/Coins-Pro-API.pdf

Table of Contents

Installation

npm i coins-pro

Getting Started

 
// Firstly, import the CoinsProAPI class from the library.
const CoinsProAPI = require("coins-pro");
 
// Secondly, instantiate the CoinsProAPI class.
let agent = new CoinsProAPI();
 
// Thirdly, invoke the method start and pass an object which contains
// your APIKey, secret, and UserId for the first parameter.
// The second second parameter accepts a callback function which will
// execute after you are successfully authenticated and
// connected to the Coins Pro websocket server.
agent.start({
  "APIKey": "your_api_key",
  "secret": "your_secret",
  "UserId": "your_user_id"
}, (response) => {
  console.log(`===== Client Authenticated =====\n`, response);
 
  // Ping is used to keep the Websocket connection alive.
  setInterval(() => {
      agent.ping((response) => {
          console.log(`===== PING =====\n`, response);
      });
  }, 40000);
 
  // Retrieves list of Positions (Balances).
  agent.getAccountPositions((response) => {
      console.log(`===== Account Positions =====\n`, response)
  });
 
  // Send buy (Side: 0) order for BTCPHP (InstrumentId: 6) 
  // amounting to 0.00002000 Bitcoins (Quantity: 0.00002000).
  agent.sendOrder({
      InstrumentId: 6,
      Quantity: 0.00002000,
      Side: 0 // 0 (buy) or 1 (sell)
  }, (response) => {
      console.log(`===== Send Order =====\n`, response);
  });
 
  // Subscribe to BTC market data.
  agent.subscribeLevel1(6, (response) => { 
      console.log(`===== Current Market Data Lv1 [BTC] =====\n`, response) 
  });
});

CoinsProAPI Methods

After successfully authenticating & connecting to the Coins Pro websocket by using the method start as described in the Getting Started section, you can now send messages to the websocket server (take note some methods do not require authentication such as getProducts and getInstruments).

All of the methods accepts various arguments depending on what data is required in sending the websocket message, but all of them accepts a callback function which has 1 parameter. This parameter contains the message that Coins Pro has sent in response to your message pertaining to the specific method which was invoked to send the websocket message. So for example, if you invoke getProducts, Coins Pro will send you the list of Products available and this data will be accessible through the aforementioned parameter of the callback function.

Unauthenticated Endpoints

getProducts

Requests a list of available Products from the API.

CoinsProAPI.getProducts(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getProducts((response) => { 
  console.log(`===== Get Products =====\n`, response) 
});

getInstruments

Requests a list of available instruments from the API.

CoinsProAPI.getInstruments(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getInstruments((response) => { 
  console.log(`===== Get Instruments =====\n`, response) 
});

API Keys

getUserAPIKeys

The endpoint will return existing APIKeys with assigned permissions. APISecret field will not be returned.

CoinsProAPI.getUserAPIKeys(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getUserAPIKeys((response) => {
  console.log(`===== Get APIKey =====\n`, response);
});

addUserAPIKey

In order to authenticate using an API key, you will need to create an ApiKey and ApiSecret using this endpoint. Your UserId will be needed along with the permissions you wish to enable in payload.

The endpoint will return a UserAPIKey class type json string containing the APIKey and APISecret.

Note: Please save the APIKey and APISecret values returned in a secure location. Both of these values are needed for authentication and signature generation.

CoinsProAPI.addUserAPIKey(permissions: string[], callback?: Function)

permissions Possible values for permissions: ["Deposit", "Withdraw", "Trading"]
callback Function to be executed when the server responds to your request
agent.addUserAPIKey(["Deposit", "Withdraw"], (response) => {
  console.log(`===== Add APIKey =====\n`, response);
});

removeUserAPIKey

Removes API Key from the user's account.

CoinsProAPI.removeUserAPIKey(ApiKey: string, callback?: Function)

ApiKey API Key to be removed from the account
callback Function to be executed when the server responds to your request
agent.removeUserAPIKey("a841099374d1fb6162553075b1f8065b", (response) => {
  console.log(`===== Remove APIKey =====\n`, response);
});

User Account

getUserAccounts

Retrieves a list of account IDs for the current user. The Request should have an empty string as the payload. Typically, each user is assigned one account

CoinsProAPI.getUserAccounts(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getUserAccounts((response) => {
  console.log(`===== User Accounts =====\n`, response);
});

getAccountTransactions

Retrieves a list of recent transactions from your account.

CoinsProAPI.getAccountTransactions({ StartIndex, Count }: {
  StartIndex: number;
  Count: number;
}, callback?: Function)

StartIndex Index of when to start counting from
Count Number of transactions API should retrieve with StartIndex as the starting index
callback Function to be executed when the server responds to your request
agent.getAccountTransactions({
  StartIndex: 0,
  Count: 5
}, (response) => {
  console.log(`===== Account Transactions =====\n`, response);
});

getAccountPositions

Retrieves a list of Positions(Balances) on a specific account.

CoinsProAPI.getAccountPositions(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getAccountPositions((response) => {
  console.log(`===== Account Positions =====\n`, response);
});

getAccountTrades

Retrieves Trade History for a specific account.

CoinsProAPI.getAccountTrades({ StartIndex, Count }: {
  StartIndex: number;
  Count: number;
}, callback?: Function)

StartIndex Index of when to start counting from
Count Number of trades the API should retrieve with StartIndex as the starting index
callback Function to be executed when the server responds to your request
agent.getAccountTrades({
  StartIndex: 0,
  Count: 5
}, (response) => {
  console.log(`===== Account Trades =====\n`, response);
});

Orders

sendOrder

Sends a new order through the API. It is important that you are subscribed to Account Actions (SubscribeAccountEvents) in order to receive updated status events for entered orders. Alternatively, you can also call GetOpenOrders and/or GetOrderHistory to check order status.

CoinsProAPI.sendOrder(obj?: {
  InstrumentId: number;
  Quantity: number;
  Side: number;
  OrderType: number;
  ClientOrderId: number;
  DisplayQuantity: number;
  UseDisplayQuantity: boolean;
  TimeInForce: number;
  LimitPrice: number;
  LimitOffset: number;
  OrderIdOCO: number;
  PegPriceType: number;
  TrailingAmount: number;
  StopPrice: number;
}, callback?: Function)

InstrumentId For example InstrumentId 6 is BTCPHP which means buy/sell X Quantity of BTC in exchange for PHP
Quantity amount to buy/sell. for example, as of this writing: 10 pesos = 0.00001740 BTC. Therefore, if you wanted to buy/sell 10 pesos worth of BTC, pass 0.00001740 as Quantity
Side 0 (Buy) or 1 (Sell)
OrderType The type of order. 1 (Market) or 2 (Limit) or 3 (StopMarket)
ClientOrderId Set this to your own id if you wish to use one. It will be useful for recognizing future order states related to this call. [64 bit Integer]
DisplayQuantity Quantity of an order to display publicly on the order book. If you have an order for 1,000 and you want the order book to reflect a quantity of only 100 at any one time, set this to 100. This functionality can only be used for limit orders. Set to 0 to display all. [Decimal]
UseDisplayQuantity [Boolean] If you enter a Limit order with a reserve, you must set UseDisplayQuantity to true.
TimeInForce 1 (Good until Canceled) or 3 (Immediate or Cancel) or 4 (Fill or Kill)
LimitPrice The limit price for this order. [Decimal]
LimitOffset When entering a Trailing Limit order, this specifies the distance from activation price to your limit order price. [Decimal]
OrderIdOCO If you would like to have this order cancel another on execution, set this field to the other order's server order id. Omit or set to 0 if no OCO is required. [64 Bit Integer]
PegPriceType When entering a Stop/Trailing order, set this to the type of price you would like to peg the Stop to. [Integer] 1 (Last) or 2 (Bid) or 3 (Ask)
TrailingAmount When entering a Trailing order, set this to the quantity required, which the trigger price will trail the market by. [Decimal]
StopPrice The Stop Price for this order, if it is a stop order. Otherwise you may omit this field. [Decimal]
callback Function to be executed when the server responds to your request
agent.sendOrder({
  InstrumentId: 6,
  Quantity: 0.00002000,
  Side: 0
}, (response) => {
  console.log(`===== Send Order =====\n`, response);
})

cancelOrder

Cancels an open order, by either specifying the OrderId returned when the order was created, or by specifying both the ClientOrderId and AccountId of the order. If AccountId is not specified, the default user account will be used.

CoinsProAPI.cancelOrder(OrderId: any, callback?: Function)

OrderId Order ID of the order to be cancelled
callback Function to be executed when the server responds to your request
agent.cancelOrder(17509100, (response) => {
  console.log(`===== Cancel Order =====\n`, response);
});

getOrderStatus

Gets the current operating status of an order submitted to the Order Management System.

CoinsProAPI.getOrderStatus(OrderId: any, callback?: Function)

OrderId Order ID of the order to be cancelled
callback Function to be executed when the server responds to your request
agent.getOrderStatus(17509100, (response) => {
  console.log(`===== Order Status =====\n`, response);
});

getOrderFee

Returns an estimate of the fee for a specific order and order type.

CoinsProAPI.getOrderFee({ InstrumentId, ProductId, Amount, OrderType, MakerTaker }: {
  InstrumentId: number;
  ProductId: number;
  Amount: number;
  OrderType: string
  MakerTaker: string;
}, callback?: Function)

InstrumentId Instrument's Identifier
ProductId Product's Identifier
Amount amount to order in decimal
OrderType "Market", "Limit", or "StopMarket"
MakerTaker Whether the order is expected to execute instantly against existing orders in the order book ("Taker") or rest in the order book as an open order ("Maker")
callback Function to be executed when the server responds to your request
agent.getOrderFee({
  InstrumentId: 6,
  ProductId: 7,
  Amount: 500,
  OrderType: "Market",
  MakerTaker: "Maker"
}, (response) => {
  console.log(`===== Order Fee =====\n`, response);
});

getOrderHistory

Retrieves a list of the last n=Depth orders placed on your account.

CoinsProAPI.getOrderHistory(Depth: number, callback?: Function)

Depth indicate how many records are to be returned
callback Function to be executed when the server responds to your request
agent.getOrderHistory(30, (response) => {
  console.log(`===== Order History =====\n`, response);
});

getOpenOrders

Retrieves the Open Orders for a specified account of the current user. Keep in mind that if your order is no longer in a working state, you will not find it using GetOpenOrders.

CoinsProAPI.getOpenOrders(callback?: Function)

callback Function to be executed when the server responds to your request
agent.getOpenOrders((response) => {
  console.log(`===== Open Orders =====\n`, response);
});

Deposits

getDepositTickets

Get a list of deposits for an account.

CoinsProAPI.getDepositTickets({ Limit, OperatorId, StartIndex }?: {
  Limit: any;
  OperatorId?: number;
  StartIndex?: number;
}, callback?: Function)

Limit Number of last deposits to fetch [Integer]
OperatorId Always 1
StartIndex Offset in deposits list [Integer]
callback Function to be executed when the server responds to your request
agent.getDepositTickets({
  Limit: 100
}, (response) => {
  console.log(`===== Deposit Tickets =====\n`, response);
});

Withdrawals

createWithdrawTicket

Creates a withdrawal ticket to send funds from Coins Pro to the user’s Coins.ph wallet

CoinsProAPI.createWithdrawTicket({ ProductId, Amount }: {
  ProductId: any;
  Amount: any;
}, callback?: Function)

ProductId ID of the product which will be withdrawn [Integer]
Amount Amount for withdrawal [Decimal]
callback Function to be executed when the server responds to your request
agent.createWithdrawTicket({
  ProductId: 7,
  Amount: 100
}, (response) => {
  console.log(`===== Create Withdraw Ticket =====\n`, response);
});

getWithdrawTicket

Gets the current operating status of a Withdraw Ticket.

CoinsProAPI.getWithdrawTicket(RequestCode: any, callback?: Function)

RequestCode Request code of withdrawal, this ID is a common reference between Coins.ph and Coins Pro APIs and can be used to track transactions between the two systems [String]
callback Function to be executed when the server responds to your request
agent.getWithdrawTicket("aca9f8d2-229f-4234-b032-69f0fd413e04", (response) => {
  console.log(`===== Withdraw Ticket =====`, response);
});

getWithdrawTickets

Get a list of withdrawals for an account.

CoinsProAPI.getWithdrawTickets({ Limit, StartIndex, OperatorId }?:
  Limit: any;
  StartIndex?: number;
  OperatorId?: number;
}, callback?: Function)

Limit Number of last deposits to fetch [Integer]
StartIndex Offset in withdrawals list [Integer]
OperatorId Always 1
callback Function to be executed when the server responds to your request
agent.getWithdrawTickets({
  Limit: 100,
  StartIndex: 0
}, (response) => {
  console.log(`===== Withdraw Tickets =====`, response);
});

Market Data

subscribeLevel1

Retrieves the latest Level 1 Ticker information and Subscribes the user to Level 1 Market Data updates for the specified Instrument. After subscribing, the user will receive periodic Level1UpdateEvent event information until they call UnsubscribeLevel1.

CoinsProAPI.subscribeLevel1(InstrumentId: any, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
callback Function to be executed when the server responds to your request
agent.subscribeLevel1(6, (response) => {
  console.log(`===== Current Market Data Lv1 [BTC] =====\n`, response);
});

unsubscribeLevel1

Unsubscribes the user from receiving Level 1 Market Data updates for the specified Instrument.

CoinsProAPI.unsubscribeLevel1(InstrumentId: any, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
callback Function to be executed when the server responds to your request
agent.unsubscribeLevel1(6, (response) => {
  console.log(`===== Unsubscribe Market Data Lv1 [BTC] =====\n`, response);
});

subscribeLevel2

Retrieves the latest Level 2 Snapshot and Subscribes user to Level 2 Market Data updates for the specified Instrument.

CoinsProAPI.subscribeLevel2({ InstrumentId, Depth }: {
  InstrumentId: number;
  Depth: number;
}, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
Depth The Depth of the book to subscribe to updates for. In this example, you would receive 10 price levels on each side of the market. [Integer]
callback Function to be executed when the server responds to your request
agent.subscribeLevel2({
  InstrumentId: 6,
  Depth: 2
}, (response) => {
  console.log(`===== Current Market Data Lv2 [BTC] =====\n`, response);
});

unsubscribeLevel2

Unsubscribes from Level 2 Market Data updates for the specified Instrument.

CoinsProAPI.unsubscribeLevel2(InstrumentId: any, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
callback Function to be executed when the server responds to your request
agent.unsubscribeLevel2(6, (response) => {
  console.log(`===== Unsubscribe Market Data Lv2 [BTC] =====\n`, response);
});

subscribeTrades

Retrieves the latest public market trades and Subscribes User to Trade updates for the specified Instrument.

CoinsProAPI.subscribeTrades({ InstrumentId, IncludeLastCount }: {
  InstrumentId: number;
  IncludeLastCount: number;
}, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
IncludeLastCount Specifies the number of previous trades to retrieve in the immediate snapshot. Default is 100. [Integer]
callback Function to be executed when the server responds to your request
agent.subscribeTrades({
  InstrumentId: 6,
  IncludeLastCount: 2
}, (response) => {
  console.log(`===== Public Trades Market Data [BTC] =====\n`, response);
});

unsubscribeTrades

Unsubscribes the user from Trades Market Data Feed.

CoinsProAPI.unsubscribeTrades(InstrumentId: any, callback?: Function)

InstrumentId Instrument's Identifier [Integer]
callback Function to be executed when the server responds to your request
agent.unsubscribeTrades(6, (response) => {
  console.log(`===== Unsubscribe Public Trades =====\n`, response);
});

Account Events

subscribeAccountEvents

Subscribe to account-level events, such as orders, trades, deposits and withdraws.Coins Pro recommends that you use this subscription to track your order states.

CoinsProAPI.subscribeAccountEvents(callback?: Function)

callback Function to be executed when the server responds to your request
agent.subscribeAccountEvents((response) => {
  console.log(`===== Account Event ===== \n`, response);
});

Ping

Used to keep a connection alive.

CoinsProAPI.ping(callback?: Function)

callback Function to be executed when the server responds to your request
setInterval(() => {
  agent.ping((response) => {
    console.log(`===== Ping =====\n`, response);
  });
}, 40000);

FAQ

How to Get API Key and Secret?

  1. Login to the Coins Pro website at https://exchange.coins.asia/
  2. Go to API Key Management. This can also be accessed via the website hamburger menu.
  3. From the API Key Management, you can create new API Keys which will generate your API Key & Secret. This webpage also displays your existing API Keys.

How to Get UserId?

  1. Login to the Coins Pro website at https://exchange.coins.asia/
  2. Go to API Key Management. This can also be accessed via the website hamburger menu.
  3. From the API Key Management webpage, your UserId should be displayed.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i coins-pro

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

58.4 kB

Total Files

4

Last publish

Collaborators

  • json-g