Skip to content

Commit 562c5e1

Browse files
authored
Merge pull request #25 from cryptomkt/develop
API v3
2 parents 9f5d06f + 1b60139 commit 562c5e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+7312
-4843
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

README.md

Lines changed: 116 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,196 @@
11
# CryptoMarket-javascript
2-
[main page](https://www.cryptomkt.com/)
32

3+
[main page](https://www.cryptomkt.com/)
44

55
[sign up in CryptoMarket](https://www.cryptomkt.com/account/register).
66

77
# Installation
8+
89
To install Cryptomarket use npm
10+
911
```
1012
npm install cryptomarket
1113
```
14+
1215
# Documentation
1316

14-
This sdk makes use of the [api version 2](https://api.exchange.cryptomkt.com/v2) of cryptomarket.
17+
This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com) of cryptomarket.
1518

1619
# Quick Start
1720

1821
## rest client
22+
1923
```javascript
20-
const { Client } = require('cryptomarket')
24+
const { Client } = require("cryptomarket");
2125

2226
// instance a client
23-
let apiKey='AB32B3201'
24-
let api_secret='21b12401'
25-
let client = new Client(apiKey, api_secret)
27+
let apiKey = "AB32B3201";
28+
let apiSecret = "21b12401";
29+
let client = new Client(apiKey, apiSecret);
2630

2731
// get currencies
28-
let currencies = await client.getCurrencies()
32+
let currencies = await client.getCurrencies();
2933

3034
// get order books
31-
let orderBook = await client.getOrderBook('EOSETH')
35+
let orderBook = await client.getOrderBook("EOSETH");
3236

3337
// get your account balances
34-
let accountBalance = await client.getAccountBalance()
38+
let accountBalances = await client.getWalletBalances();
3539

3640
// get your trading balances
37-
let tradingBalance = await client.getTradingBalance()
41+
let tradingBalances = await client.getSpotTradingBalances();
3842

39-
// move balance from account to trading
40-
let result = await client.transferMoneyFromAccountBalanceToTradingBalance('ETH', '3.2')
43+
// move balance from wallet to spot trading
44+
let result = await client.transferBetweenWalletAndExchange({
45+
currency: "EOS",
46+
amount: "3.2",
47+
source: Account.Wallet,
48+
destination: Account.Spot,
49+
});
4150

4251
// get your active orders
43-
let orders = await client.getActiveOrders('EOSETH')
52+
let orders = await client.getAllActiveSpotOrders("EOSETH");
4453

4554
// create a new order
46-
let newOrder = await client.createOrder({'symbol':'EOSETH', 'side':'buy', 'quantity':'10', 'price':'10'})
55+
let newOrder = await client.createOrder({
56+
symbol: "EOSETH",
57+
side: "buy",
58+
quantity: "10",
59+
price: "10",
60+
});
4761
```
4862

4963
## websocket client
50-
There are three websocket clients, one for public request (WSPublicClient), one for trading request (WSTradingClient) and one for the account requests (WSAccountClient).
5164

52-
Clients work with promises
65+
There are three websocket clients, the market data client, the spot trading client and the wallet client.
66+
The market data client requires no authentication, while the spot trading client and the wallet client do require it.
5367

54-
Clients must be connected before any request. Authentication for WSTradingClient and WSAccountClient is automatic.
68+
All websocket methods return promises. Subscriptions also take in a function of two parameters, the notification data, and the notification type. The notification type is of type NOTIFICATION_TYPE, and is either SNAPSHOT, NOTIFICATION or DATA.
5569

56-
```javascript
57-
const { WSPublicClient, WSTradingClient, WSAccountClient} = require('cryptomarket')
70+
The documentation of a specific subscriptions explains with of this types of
71+
notification uses.
5872

59-
let publicClient = new WSPublicClient()
60-
await publicClient.connect()
73+
### MarketDataClient
6174

62-
// get currencies
63-
await publicClient.getCurrencies()
75+
Example of use of the market data client
6476

65-
let apiKey='AB32B3201'
66-
let apiSecret='21b12401'
67-
let tradingClient = new WSTradingClient(apiKey, apiSecret)
77+
```typescript
78+
// instantiate a market data client
79+
const wsclient = new WSMarketDataClient();
6880

69-
await tradingClient.connect()
81+
// make a partial orderbook subscription
7082

71-
// get your trading balance
72-
let balance = await tradingClient.getTradingBalance()
83+
// make subscription
84+
await marketDataClient.subscribeToPartialOrderBook(
85+
callback:(notification, type) => {
86+
if (type === NOTIFICATION_TYPE.DATA) {
87+
System.out.println("this subscription only recieves data notifications");
88+
}
89+
for (const symbol in notification) {
90+
console.log(symbol);
91+
const orderbook = notification[symbol];
92+
console.log(orderbook);
93+
}
94+
},
95+
params: {
96+
speed: ORDER_BOOK_SPEED._100_MS,
97+
depth: DEPTH._5,
98+
symbols: ["EOSETH", "ETHBTC"],
99+
}
100+
);
73101

74-
// get your active orders
75-
let activeOrders = await tradingClient.getActiveOrders()
76102

77-
await tradingClient.createOrder({
78-
clientOrderId:"qqwe123qwe",
79-
symbol:'EOSETH',
80-
side:'buy',
81-
quantity:'10',
82-
price:'10'
83-
})
103+
```
84104

85-
let accountClient = new WSAccountClient(apiKey, apiSecret)
86-
await accountClient.connect()
105+
### SpotTradingClient
87106

88-
// get your account balance
89-
let accBalance = await accountCilent.getAccountBalance()
90-
```
91-
### subscriptions
107+
Example of use of the spot trading client
92108

93-
all subscriptions take a callback argument to call with each feed of the subscription
109+
```typescript
110+
const apiKey = "AB32B3201";
111+
const apiSecret= "21b12401";
94112

95-
```javascript
113+
// instantiate a spot trading websocket client with a window of 10 seconds
114+
const wsclient = new WSTradingClient(apiKey, apiSecret, 10_000);
96115

97-
// callback is for the subscription feed
98-
function callback(feed) {
99-
// handle feed
100-
console.log(feed)
116+
// connect the client (and authenticate it automatically)
117+
await wsclient.connect();
118+
119+
// get all the spot trading balances
120+
const balanceList = await tradingClient.getSpotTradingBalances()
121+
console.log(balanceList);
122+
123+
124+
let clientOrderID = Math.floor(Date.now() / 1000).toString();
125+
// make a spot order
126+
const report = await tradingClient.createSpotOrder({
127+
clientOrderId: clientOrderID,
128+
symbol: "EOSETH",
129+
side: "sell",
130+
quantity: "0.01",
131+
price: "1000",
101132
}
133+
console.log(report);
134+
```
135+
136+
### WalletClient
137+
138+
Example of use of the wallet client
102139
103-
await publicClient.subscribeToOrderBook('EOSETH', callabck)
140+
```typescript
141+
// instantiate a wallet websocket client with a default window of 10 seconds
142+
const wsclient = new WSWalletClient(keys.apiKey, keys.apiSecret);
104143

144+
// get a list of transactions
145+
const transactionList = await walletClient.getTransactions({
146+
currencies: ["EOS"],
147+
limit: 3,
148+
});
149+
console.log(transactionList);
105150

106-
await accountClient.subscribeToTransactions(callback)
151+
// subscribe to a feed of transactions
152+
await walletClient.subscribeToTransactions((notification, type) => {
153+
if (type === NOTIFICATION_TYPE.UPDATE) {
154+
console.log("this subscription only recieves update notifications");
155+
}
156+
console.log(notification);
157+
});
107158
```
108159
109160
## error handling
110161
111-
```javascript
162+
```typescript
112163

113-
{ CryptomarketSDKException, Client, WSPublicClient } = require('cryptomarket')
164+
{ CryptomarketSDKException, Client, WSMarketDataClient } = require('cryptomarket')
114165
// exceptions derive from the CryptomarketSDKException class.
115166

116-
client = new Client()
167+
const client = new Client()
117168
// catch a failed transaction
118169
try {
119-
order = client.createOrder({
170+
const order = await client.createOrder({
120171
'symbol':'EOSETHH', // non existant symbol
121172
'side':'sell',
122-
'quantity':'10',
173+
'quantity':'10',
123174
'price':'10'})
124175
} catch (error) {
125176
console.log(error)
126177
}
127178

128-
wsclient = new WSPublicClient()
129-
await wsclient.connect()
179+
const wsclient = new WSMarketDataClient()
180+
await wsclient.connect();
130181

131-
// catch a missing argument
182+
// catch missing arguments
132183
try {
133-
await wsclient.subscribeToOrderbook('ETHBTC') // needs a callback
184+
await wsclient.subscribeToMiniTickers()
134185
} catch (error) {
135186
console.log(error)
136187
}
137-
138-
// also catches forwarded errors from the cryptomarket exchange server
139-
try {
140-
let trades = await wsclient.getTrades("abcde", myCallback) // not a real symbol
141-
} catch (err) {
142-
console.log(err)
143-
}
144188
```
145189
190+
# Constants
191+
192+
All constants used for calls are in the `constants` module.
193+
146194
# Checkout our other SDKs
147195
148196
[python sdk](https://github.com/cryptomkt/cryptomkt-python)

0 commit comments

Comments
 (0)