Skip to content

Commit 65eb35c

Browse files
committed
Merge branch 'develop'
2 parents f5e2eaf + 10c2f69 commit 65eb35c

File tree

5 files changed

+90
-50
lines changed

5 files changed

+90
-50
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ typings/
6464

6565
# End of https://www.gitignore.io/api/node
6666
test.js
67+
68+
.idea

README.md

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ example();
6060
```
6161
***Expected output***
6262
```javascript
63-
//Any of the 3 ways to call the function should return an output like this
63+
// Any of the 3 ways to call the function should return an output like this:
64+
6465
response: {
6566
status: 'success',
6667
data: [
@@ -83,9 +84,7 @@ var client = new Client({'apiKey': mykey, 'apiSecret': mysecret});
8384
client.getMarkets()
8485
.then((obj) => {
8586
const data = obj.data;
86-
data.forEach((market) => {
87-
console.log(data);
88-
});
87+
console.log(data);
8988
}).catch((err) => {
9089
console.error(err);
9190
})
@@ -106,8 +105,10 @@ client.getMarkets()
106105

107106
**Obtain Book**
108107
```javascript
109-
//receives a Js object. "market" and "side" are mandatory (ex: {"market": "XLMCLP","side":"sell"}).
110-
client.getBook(dictionary, (err, output) => {
108+
// Receives a Js object. "market" and "side" are mandatory.
109+
// Example: {"market": "XLMCLP", "side": "sell"}
110+
111+
client.getBook(object, (err, output) => {
111112
if(err){
112113
console.log('error');
113114
}
@@ -144,12 +145,15 @@ client.getBook(dictionary, (err, output) => {
144145
timestamp: '2020-02-21T04:32:26.686000'
145146
}
146147
...
147-
]
148+
]
148149
```
150+
149151
**Obtain ticker info**
150152
```javascript
151-
//receives a Js object that contains the market. (ex: {"market":"XLMARS"})
152-
client.getTicker(market, (err, output) => {
153+
// Receives a Js object that contains the market.
154+
// Example: {"market": "XLMARS"}
155+
156+
client.getTicker(object, (err, output) => {
153157
if(err){
154158
console.log('error');
155159
}
@@ -224,10 +228,16 @@ client.getAccount()
224228
]
225229
}
226230
```
231+
227232
**Create an order**
228233
```javascript
229-
//receives a Js object. "market","type","side" and "amount" are mandatory. (ex: {"amount": 1, "market": "XLMCLP", "price": 50.5, "type": "limit", "side": "sell"}).
230-
client.createOrder(order, (err, output) => {
234+
// Receives a Js object. "market", "type", "side" and "amount" are mandatory.
235+
// (Example: {"amount": 1, "market": "XLMCLP", "price": 50.5, "type": "limit", "side": "sell"}
236+
// Note that "side" can be either "sell" or "buy", also "type" can be "limit", "stop-limit" or "market".
237+
// If you want to execute an "stop-limit" order you need to specify the "limit" amount.
238+
// Example: {"amount": 1, "market": "XLMCLP", "price": 50.5, "type": "stop-limit", "limit": 50, "side": "sell"}
239+
240+
client.createOrder(object, (err, output) => {
231241
if(err){
232242
console.log('error');
233243
}
@@ -258,8 +268,10 @@ response: {
258268

259269
**Create multiple orders**
260270
```javascript
261-
//receives object array that contains multiple orders. "market","type","side" and "amount" are mandatory. (ex: [{"amount": 1, "market": "XLMCLP", "price": 50.5, "type": "limit", "side": "sell"},{Order2},...]).
262-
client.createMultiOrders(orders, (err, output) => {
271+
// Receives object array that contains multiple orders. "market", "type", "side" and "amount" are mandatory.
272+
// Example: [{"amount": 1, "market": "XLMCLP", "price": 50.5, "type": "limit", "side": "sell"}, {Order2},...]
273+
274+
client.createMultiOrders(object, (err, output) => {
263275
if(err){
264276
console.log('error');
265277
}
@@ -269,18 +281,20 @@ client.createMultiOrders(orders, (err, output) => {
269281
***Expected output***
270282
```javascript
271283
response: {
272-
status: 'success',
273-
data: {
274-
created: [{Order1},{Order2},...],
275-
not_created: []
284+
status: 'success',
285+
data: {
286+
created: [{Order1},{Order2},...],
287+
not_created: []
276288
}
277289
}
278290
```
279291

280292
**Obtain active orders**
281293
```javascript
282-
//receives a Js object that contains the market (ex: {"market":"XLMCLP"})
283-
client.getActiveOrders(market, (err, output) => {
294+
// Receives a Js object that contains the market
295+
// Example: {"market":"XLMCLP"}
296+
297+
client.getActiveOrders(object, (err, output) => {
284298
if(err){
285299
console.log('error');
286300
}
@@ -330,8 +344,10 @@ client.getActiveOrders(market, (err, output) => {
330344

331345
**Cancel an order**
332346
```javascript
333-
//receives object that contains the order's ID (ex: {"id":"O000004"}).
334-
client.cancelOrder(order, (err, output) => {
347+
// Receives object that contains the order's ID.
348+
// Example: {"id":"O000004"}
349+
350+
client.cancelOrder(object, (err, output) => {
335351
if(err){
336352
console.log('error');
337353
}
@@ -358,10 +374,13 @@ response: {
358374
}
359375
}
360376
```
377+
361378
**Cancel multiple orders**
362379
```javascript
363-
//receives object array that contains multiple order's IDs (ex: [{"id":"O000001"},{"id":"O000002"},...]).
364-
client.cancelMultiOrders(orders, (err, output) => {
380+
// Receives object array that contains multiple order's IDs.
381+
// Example: [{"id":"O000001"},{"id":"O000002"},...]
382+
383+
client.cancelMultiOrders(object, (err, output) => {
365384
if(err){
366385
console.log('error');
367386
}
@@ -372,18 +391,21 @@ client.cancelMultiOrders(orders, (err, output) => {
372391
```javascript
373392
response: {
374393
status: 'success',
375-
data: { canceled: [{Order1},{Order2},...], not_canceled: [] } }
394+
data: { canceled: [{Order1},{Order2},...], not_canceled: [] }
395+
}
376396
```
397+
377398
**Make a transfer**
378399
```javascript
379-
//receives a Js object. "currency", "address", and "amount" are mandatory. (ex: {"currency":'ETH',"address":'0xf2ec...',"amount":0.02}).
380-
client.transfer(transfer, (err, output) => {
400+
// Receives a Js object. "currency", "address", and "amount" are mandatory.
401+
// Example: {"currency": "ETH", "address": "0xf2ec...", "amount": 0.02}
402+
403+
client.transfer(object, (err, output) => {
381404
if(err){
382405
console.log('error');
383406
}
384407
console.log(output);
385408
});
386-
387409
```
388410
***Expected output***
389411
```javascript
@@ -392,8 +414,10 @@ client.transfer(transfer, (err, output) => {
392414

393415
**Obtain executed orders**
394416
```javascript
395-
//receives a Js object that contains the market (ex: {"market":"XLMCLP"})
396-
client.getExecutedOrders(market, (err, output) => {
417+
// Receives a Js object that contains the market.
418+
// Example: {"market":"XLMCLP"}
419+
420+
client.getExecutedOrders(object, (err, output) => {
397421
if(err){
398422
console.log('error');
399423
}
@@ -434,8 +458,10 @@ client.getExecutedOrders(market, (err, output) => {
434458

435459
**Obtain order status**
436460
```javascript
437-
//receives a Js object that contains the ID (ex: {"id":"O000005"})
438-
client.getOrderStatus(id, (err, output) => {
461+
// Receives a Js object that contains the ID.
462+
// Example: {"id":"O000005"}
463+
464+
client.getOrderStatus(object, (err, output) => {
439465
if(err){
440466
console.log('error');
441467
}
@@ -474,7 +500,6 @@ client.getBalance((err, output) => {
474500
console.log(output);
475501
});
476502
```
477-
478503
***Expected Output***
479504
```javascript
480505
{
@@ -498,13 +523,16 @@ client.getBalance((err, output) => {
498523

499524
## Using socket
500525

526+
Cryptomarket's API v2 integrates Socket.IO! You can now receive real-time events connecting to the sockets.
527+
501528
### Get socket instance
502529
503530
```javascript
504531
var { Client } = require('cryptomarket');
505532
var client = new Client({'apiKey': mykey, 'apiSecret': mysecret});
506533
507534
var socket;
535+
508536
client.socket.connect()
509537
.then((skt) => {
510538
socket = skt
@@ -514,7 +542,7 @@ client.socket.connect()
514542
515543
//or
516544
517-
var socket= await client.socket.connect();
545+
var socket = await client.socket.connect();
518546
```
519547
520548
### Receive socket events
@@ -531,7 +559,8 @@ socket.unsubscribe('ETHCLP');
531559
532560
**Receive open book info**
533561
```javascript
534-
// Subscription required*
562+
// Subscription required.
563+
535564
socket.on('open-book', (data) => {
536565
console.log('open-book', data);
537566
});
@@ -552,7 +581,8 @@ open-book {
552581
553582
**Receive Historical book info**
554583
```javascript
555-
// Subscription required*
584+
// Subscription required.
585+
556586
socket.on('historical-book', (data) => {
557587
console.log('historical-book', data);
558588
});
@@ -601,7 +631,8 @@ socket.on('historical-book', (data) => {
601631
602632
**Receive candles info**
603633
```javascript
604-
// Subscription required*
634+
// Subscription required.
635+
605636
socket.on('candles', (data) => {
606637
console.log('candles', data);
607638
});
@@ -673,7 +704,7 @@ ticker {
673704
}
674705
```
675706
676-
**Receive balance info**
707+
**Receive Your Balance info**
677708
```javascript
678709
socket.on('balance', (data) => {
679710
console.log('balance', data);
@@ -698,7 +729,7 @@ balance {
698729
```
699730
700731
701-
**Receive user orders info**
732+
**Receive Your Orders info**
702733
```javascript
703734
socket.on('open-orders', (data) => {
704735
console.log('open-orders', data);
@@ -727,13 +758,12 @@ open-orders [
727758
]
728759
```
729760
730-
**Receive historical user orders info**
761+
**Receive Your Historical orders info**
731762
```javascript
732763
socket.on('historical-orders', (data) => {
733764
console.log('historical-orders', data);
734765
});
735766
```
736-
737767
***Expected Output***
738768
```javascript
739769
historical-orders [
@@ -774,8 +804,7 @@ historical-orders [
774804
]
775805
```
776806
777-
778-
**Receive User´s operated volume**
807+
**Receive Your operated volume**
779808
```javascript
780809
socket.on('operated', (data) => {
781810
console.log('operated', data);

lib/Socket.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Socket {
2323
this.historicalBookData = {};
2424
this.candlesData = {};
2525
this.boardData = {};
26+
this.transports = ['websocket', 'polling'];
2627
}
2728

2829
_deepClone(data) {
@@ -45,6 +46,7 @@ class Socket {
4546
reconnectionAttempts: 1,
4647
reconnectionDelay: 1000,
4748
reconnectionDelayMax: 15000,
49+
transports: this.transports,
4850
});
4951
}
5052

@@ -434,19 +436,26 @@ class Socket {
434436
});
435437
}
436438

437-
connect() {
439+
connect(...transports) {
440+
if (!_.isEmpty(transports)) {
441+
this.transports = transports.filter(
442+
(transport) => transport === 'polling' || transport === 'websocket',
443+
);
444+
if (_.isEmpty(this.transports)) {
445+
return Promise.reject(new Error('Invalid transports'));
446+
}
447+
}
438448
this.socketClient = socket(this.urlWorker, {
439449
forceNew: false,
440450
reconnectionAttempts: 1,
441451
reconnectionDelay: 1000,
442452
reconnectionDelayMax: 15000,
453+
transports: this.transports,
443454
});
444455

445456
this._setupGeneralEvents();
446457
this._setupWorkerEvents();
447458

448-
// GENERAL METHODS
449-
// ===============================================================================
450459
return new Promise((resolve, reject) => {
451460
// Fired upon a connection including a successful reconnection.
452461
this.socketClient.on('connect', () => {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cryptomarket",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "The CryptoMarket for Node.js",
55
"homepage": "https://www.cryptomkt.com",
66
"main": "./index.js",

0 commit comments

Comments
 (0)