1.0.2 • Published 3 years ago

cryptocom v1.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
3 years ago

Cryptocom

A wrapper for the Crypto.com REST API. Uses promises. For more information on the API and parameters for requests visit https://exchange-docs.crypto.com

Usage/Example

Installing:

npm i cryptocom

Initialisation

const cryptocom = require("cryptocom");

const cdc = new cryptocom(API_KEY, API_SECRET); //const cdc = new cryptocom(); for only public 

Public Endpoints

get_instruments()

Provides information on all supported symbols (e.g. BTC_USDT)
cdc.get_instruments().then().catch();

get_book(symbol, depth)

Fetches the public order book for a particular symbol and depth
ParamTypeRequiredDescription
symbolstringYe.g. BTC_USDT, ETH_CRO, etc.
depthnumberNNumber of bids and asks to return (up to 150)
cdc.get_book("BTC_USDT", 10).then().catch();

get_ticker(symbol)

Fetches the public tickers for an symbol (e.g. BTC_USDT).
symbol can be omitted to show tickers for all symbol
ParamTypeRequiredDescription
symbolstringNe.g. BTC_USDT, ETH_CRO, etc.
cdc.get_ticker("BTC_USDT").then().catch();

get_candlestick(interval, symbol)

Retrieves candlesticks (k-line data history) over a given period for an instrument (e.g. BTC_USDT)
ParamTypeRequiredDescription
intervalstringYSee below*
symbolstringYe.g. BTC_USDT, ETH_CRO, etc.
*Period can be:

1m : one minute 5m : five minutes 15m : 15 minutes 30m: 30 minutes 1h : one hour 4h : 4 hours 6h : 6 hours 12h : 12 hours 1D : one day 7D : one week 14D : two weeks 1M : one month

cdc.get_candlestick("5m", "BTC_USDT").then().catch();

get_trades(symbol)

Fetches the public trades for a particular symbol
symbol can be omitted to show tickers for all symbol
ParamTypeRequiredDescription
symbolstringNe.g. BTC_USDT, ETH_CRO, etc.
cdc.get_trades("BTC_USDT").then().catch();

create_withdrawal(currency, amount, address, options)

Creates a withdrawal request. Withdrawal setting must be enabled for your API Key
If you do not see the option when viewing your API Key, this feature is not yet available for you.
ParamTypeRequiredDescription
currencystringYe.g. BTC, CRO
amountdecimalYamount to withdraw
addressstringYwithdrawal address
optionsobjectNsee table below

Withdrawal addresses must first be whitelisted in your account’s Withdrawal Whitelist page. Withdrawal fees and minimum withdrawal amount can be found on the Fees & Limits page on the Exchange website.

Options:
ParamTypeRequiredDescription
client_widstringNClient withdrawal ID
address_tagstringNSecondary address identifier for coins like XRP, XLM etc. Also known as memo or tags.
let options = {
    client_wid: "my_withdrawal_002",
    address_tag: "1234567"
}
cdc.create_withdrawal("XRP", 10, "0x23...", options).then().catch();

get_withdrawal_history(options)

Fetches withdrawal history. Withdrawal setting must be enabled for your API Key
If you do not see the option when viewing your API Key, this feature is not yet available for you.
ParamTypeRequiredDescription
optionsobjectNsee table below

Withdrawal addresses must first be whitelisted in your account’s Withdrawal Whitelist page. Withdrawal fees and minimum withdrawal amount can be found on the Fees & Limits page on the Exchange website.

Options:
ParamTypeRequiredDescription
currencystringNE.g. BTC, CRO
start_tslongNtimestamp is in milliseconds. Default is 90 days from current timestamp
end_tsstringNtimestamp is in milliseconds. Default is current timestamp
page_sizeintNPage size (Default: 20, Max: 200)
pageintNPage number (0-based)
statusstringNe.g. "0" (see below*)
*Available Statuses:

0 - Pending 1 - Processing 2 - Rejected 3 - Payment In-progress 4 - Payment Failed 5 - Completed 6 - Cancelled

let options = {
    currency: "CRO",
    page: "3",
    status: "5"
}
cdc.get_withdrawal_history(options).then().catch();

Private Endpoints

Spot Trading

account(currency)

Returns the account balance of a user for a particular token
ParamTypeRequiredDescription
currencystringNSpecific currency, e.g. CRO. Omit for 'all'
cdc.account("CRO").then().catch();

limit_buy(symbol, price, quantity, options) and limit_sell(symbol, price, quantity, options)

Create Limit buy and sell orders

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
pricenumberYUnit price
quantitynumberYOrder Quantity to buy
optionsobjectNsee table below
Options:
ParamTypeRequiredDescription
client_oidstringNClient order ID
time_in_forcestringNGOOD_TILL_CANCEL (Default)/ FILL_OR_KILL / IMMEDIATE_OR_CANCEL
exec_inststringNPOST_ONLY / leave empty
let options = {
    client_oid: "my_order_01"
}
cdc.limit_buy("CRO_USDT", "0.06466", 5000, options).then().catch(); // Will buy 5000 CRO IF price reaches 0.06466 USDT

let options_2 = {
    client_oid: "my_order_02",
    time_in_force: "FILL_OR_KILL"
}

cdc.limit_sell("CRO_USDT", "0.06766", 5000, options_2).then().catch(); // Will sell 5000 CRO IF price reaches 0.06766 USDT

market_buy(symbol, notional, options)

Create market buy order

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
notionalnumberYAmount to spend
client_oidstringNClient order ID
cdc.market_buy("CRO_USDT", 20, "my_order").then().catch(); // Buys CRO for 20 USDT at current market price

market_sell(symbol, quantity, options)

Create market sell order

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
quantitynumberYQuantity to be Sold
client_oidstringNClient order ID
cdc.market_sell("CRO_USDT", 5000, "my_order").then().catch(); // Sells 5000 CRO at current market price

stop_loss_buy(symbol, notional, trigger_price, client_oid)

Create stop-loss market buy order

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
notionalnumberYAmount to spend
trigger_pricenumberYDictates when order will be triggered
client_oidstringNClient order ID
cdc.stop_loss_buy("CRO_USDT", 20, "0.00009", "my_order").then().catch(); // Buys CRO usding 20 USDT at current market price IF CRO price reaches 0.00009 USDT

stop_loss_sell(symbol, quantity, trigger_price, client_oid)

Create stop-loss market sell order

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
quantitynumberYQuantity to be Sold
trigger_pricenumberYDictates when order will be triggered
client_oidstringNClient order ID
cdc.stop_loss_buy("CRO_USDT", 5000, "0.00009", "my_order").then().catch(); // Sells 5000 CRO at current market price IF CRO price reaches 0.00009 USDT

stop_limit_buy(symbol, price, quantity, trigger_price, options) and stop_limit_sell(symbol, price, quantity, trigger_price, options)

Create stop-loss limit buy or sell order

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
pricenumberYUnit price
quantitynumberYQuantity to Buy
trigger_pricenumberYDictates when order will be triggered
optionsobjectNsee table below
Options:
ParamTypeRequiredDescription
client_oidstringNClient order ID
time_in_forcestringNGOOD_TILL_CANCEL (Default)/ FILL_OR_KILL / IMMEDIATE_OR_CANCEL
exec_inststringNPOST_ONLY / leave empty
let options = {
    client_oid: "my_order_02",
    time_in_force: "FILL_OR_KILL"
}

cdc.stop_limit_buy("CRO_USDT", "0.06579", 5000, "0.06579", options).then().catch(); // Buys 5000 CRO at 0.06579 or cheaper price IF CRO price is greater or equal to 0.06579 USDT

let options_2 = {
    client_oid: "my_order_02",
    time_in_force: "FILL_OR_KILL"
}

cdc.stop_limit_sell("CRO_USDT", "0.06579", 5000, "0.06579", options_2).then().catch(); // Sells 5000 CRO at 0.06579 or higher price IF CRO price is smaller or equal to 0.06579 USDT

cancel_order(symbol, order_id)

Cancels an existing order on the Exchange (asynchronous)

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
order_idstringYID of order to be cancelled
cdc.cancel_order("CRO_USDT", "1164074220874569090").then().catch();

cancel_all_orders(symbol)

Cancels all orders for a particular instrument/pair (asynchronous)

*This call is asynchronous, so the response is simply a confirmation of the request.

ParamTypeRequiredDescription
symbolstringYe.g., ETH_CRO, BTC_USDT
cdc.cancel_all_orders("CRO_USDT").then().catch();

get_order_history(options)

Gets the order history for a particular instrument
ParamTypeRequiredDescription
optionsobjectNsee table below
Options:
ParamTypeRequiredDescription
instrument_namestringNe.g. ETH_CRO, BTC_USDT. Omit for 'all'
start_tslongNStart timestamp (milliseconds since the Unix epoch) - defaults to 24 hours ago
end_tslongNEnd timestamp (milliseconds since the Unix epoch) - defaults to 'now'
page_sizeintNPage size (Default: 20, max: 200)
pageintNPage number (0-based)
cdc.get_order_history().then().catch();//with defaults

let options = {
    instrument_name: "CRO_USDT",
    start_ts: "1612529644978",
    page: 2
}
cdc.get_order_history(options).then().catch(); //with options

*The maximum duration between start_ts and end_ts is 24 hours. You will receive an INVALID_DATE_RANGE error if the difference exceeds the maximum duration. For users looking to pull longer historical order data, users can create a loop to make a request for each 24-period from the desired start to end time.

get_open_orders(options)

Gets all open orders for a particular instrument
ParamTypeRequiredDescription
optionsobjectNsee table below
Options:
ParamTypeRequiredDescription
instrument_namestringNe.g. ETH_CRO, BTC_USDT. Omit for 'all'
page_sizeintNPage size (Default: 20, max: 200)
pageintNPage number (0-based)
cdc.get_open_orders().then().catch();//get all oopen orders

let options = {
    instrument_name: "CRO_USDT",
}
cdc.get_order_history(options).then().catch(); //get open orders for CRO_USDT pair

get_order_details(order_id)

Gets details on a particular order ID
ParamTypeRequiredDescription
order_idstringYOrder ID
cdc.get_order_details("1164074220874569090").then().catch();

get_trades(options)

Gets all executed trades for a particular instrument.
ParamTypeRequiredDescription
optionsobjectNsee table below
Options:
ParamTypeRequiredDescription
instrument_namestringNe.g. ETH_CRO, BTC_USDT. Omit for 'all'
start_tslongNStart timestamp (milliseconds since the Unix epoch) - defaults to 24 hours ago
end_tslongNEnd timestamp (milliseconds since the Unix epoch) - defaults to 'now'
page_sizeintNPage size (Default: 20, max: 200)
pageintNPage number (0-based)
cdc.get_trades().then().catch();//with defaults

let options = {
    instrument_name: "CRO_USDT",
    page: 3
}
cdc.get_trades(options).then().catch(); //get excuted trades for CRO_USDT pair

*The maximum duration between start_ts and end_ts is 24 hours. You will receive an INVALID_DATE_RANGE error if the difference exceeds the maximum duration. For users looking to pull longer historical trade data, users can create a loop to make a request for each 24-period from the desired start to end time.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.1

4 years ago