coins-pro v1.1.2
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
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
agent.getProducts((response) => {
console.log(`===== Get Products =====\n`, response)
});
getInstruments
agent.getInstruments((response) => {
console.log(`===== Get Instruments =====\n`, response)
});
API Keys
getUserAPIKeys
agent.getUserAPIKeys((response) => {
console.log(`===== Get APIKey =====\n`, response);
});
addUserAPIKey
agent.addUserAPIKey(["Deposit", "Withdraw"], (response) => {
console.log(`===== Add APIKey =====\n`, response);
});
removeUserAPIKey
agent.removeUserAPIKey("a841099374d1fb6162553075b1f8065b", (response) => {
console.log(`===== Remove APIKey =====\n`, response);
});
User Account
getUserAccounts
agent.getUserAccounts((response) => {
console.log(`===== User Accounts =====\n`, response);
});
getAccountTransactions
agent.getAccountTransactions({
StartIndex: 0,
Count: 5
}, (response) => {
console.log(`===== Account Transactions =====\n`, response);
});
getAccountPositions
agent.getAccountPositions((response) => {
console.log(`===== Account Positions =====\n`, response);
});
getAccountTrades
agent.getAccountTrades({
StartIndex: 0,
Count: 5
}, (response) => {
console.log(`===== Account Trades =====\n`, response);
});
Orders
sendOrder
agent.sendOrder({
InstrumentId: 6,
Quantity: 0.00002000,
Side: 0
}, (response) => {
console.log(`===== Send Order =====\n`, response);
})
cancelOrder
agent.cancelOrder(17509100, (response) => {
console.log(`===== Cancel Order =====\n`, response);
});
getOrderStatus
agent.getOrderStatus(17509100, (response) => {
console.log(`===== Order Status =====\n`, response);
});
getOrderFee
agent.getOrderFee({
InstrumentId: 6,
ProductId: 7,
Amount: 500,
OrderType: "Market",
MakerTaker: "Maker"
}, (response) => {
console.log(`===== Order Fee =====\n`, response);
});
getOrderHistory
agent.getOrderHistory(30, (response) => {
console.log(`===== Order History =====\n`, response);
});
getOpenOrders
agent.getOpenOrders((response) => {
console.log(`===== Open Orders =====\n`, response);
});
Deposits
getDepositTickets
agent.getDepositTickets({
Limit: 100
}, (response) => {
console.log(`===== Deposit Tickets =====\n`, response);
});
Withdrawals
createWithdrawTicket
agent.createWithdrawTicket({
ProductId: 7,
Amount: 100
}, (response) => {
console.log(`===== Create Withdraw Ticket =====\n`, response);
});
getWithdrawTicket
agent.getWithdrawTicket("aca9f8d2-229f-4234-b032-69f0fd413e04", (response) => {
console.log(`===== Withdraw Ticket =====`, response);
});
getWithdrawTickets
agent.getWithdrawTickets({
Limit: 100,
StartIndex: 0
}, (response) => {
console.log(`===== Withdraw Tickets =====`, response);
});
Market Data
subscribeLevel1
agent.subscribeLevel1(6, (response) => {
console.log(`===== Current Market Data Lv1 [BTC] =====\n`, response);
});
unsubscribeLevel1
agent.unsubscribeLevel1(6, (response) => {
console.log(`===== Unsubscribe Market Data Lv1 [BTC] =====\n`, response);
});
subscribeLevel2
agent.subscribeLevel2({
InstrumentId: 6,
Depth: 2
}, (response) => {
console.log(`===== Current Market Data Lv2 [BTC] =====\n`, response);
});
unsubscribeLevel2
agent.unsubscribeLevel2(6, (response) => {
console.log(`===== Unsubscribe Market Data Lv2 [BTC] =====\n`, response);
});
subscribeTrades
agent.subscribeTrades({
InstrumentId: 6,
IncludeLastCount: 2
}, (response) => {
console.log(`===== Public Trades Market Data [BTC] =====\n`, response);
});
unsubscribeTrades
agent.unsubscribeTrades(6, (response) => {
console.log(`===== Unsubscribe Public Trades =====\n`, response);
});
Account Events
subscribeAccountEvents
agent.subscribeAccountEvents((response) => {
console.log(`===== Account Event ===== \n`, response);
});
Ping
setInterval(() => {
agent.ping((response) => {
console.log(`===== Ping =====\n`, response);
});
}, 40000);
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.