coins-pro
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
- Getting Started
- CoinsProAPI Methods
- FAQ
- License
Installation
npm i coins-pro
Getting Started
// Firstly, import the CoinsProAPI class from the library.const CoinsProAPI = ; // Secondly, instantiate the CoinsProAPI class.let agent = ; // 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.agentstart "APIKey": "your_api_key" "secret": "your_secret" "UserId": "your_user_id" { console; // Ping is used to keep the Websocket connection alive. ; // Retrieves list of Positions (Balances). agent; // Send buy (Side: 0) order for BTCPHP (InstrumentId: 6) // amounting to 0.00002000 Bitcoins (Quantity: 0.00002000). agent; // Subscribe to BTC market data. agent;};
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;
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;
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;
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;
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;
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;
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;
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;
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;
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
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
Ping
Used to keep a connection alive.
CoinsProAPI.ping(callback?: Function)
callback | Function to be executed when the server responds to your request |
;
FAQ
How to Get API Key and Secret?
- Login to the Coins Pro website at https://exchange.coins.asia/
- Go to API Key Management. This can also be accessed via the website hamburger menu.
- 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?
- Login to the Coins Pro website at https://exchange.coins.asia/
- Go to API Key Management. This can also be accessed via the website hamburger menu.
- From the API Key Management webpage, your UserId should be displayed.