UNPKG

8.82 kBJavaScriptView Raw
1var assert = require('assert');
2var bittrex = require('../node.bittrex.api.js');
3
4describe('Bittrex public API', function() {
5
6 it('sendCustomRequest should error if the url doesnt exist', function(done) {
7 this.timeout(5000);
8 setTimeout(function() {
9 var url = 'http://fake.bittrex.com/api/v1.1/public/getticker?market=USDT-BTCXXX';
10 bittrex.sendCustomRequest( url, function( data, err ) {
11 assert.equal(data, null);
12 assert.ok(err.success == false);
13 assert.ok(err.message.length > 0);
14 done();
15 });
16 }, 500);
17 });
18
19 it('sendCustomRequest should error if the url doesnt exist', function(done) {
20 this.timeout(5000);
21 setTimeout(function() {
22 var url = 'http://bittrex.com/api/v1.1/public/getfakeendpoint';
23 bittrex.sendCustomRequest( url, function( data, err ) {
24 assert.equal(data, null);
25 assert.ok(err.success == false);
26 assert.ok(err.message.length > 0);
27 assert.ok(err.result.statusCode == 404);
28 done();
29 });
30 }, 500);
31 });
32
33 it('should respond with markets data', function(done) {
34 this.timeout(5000);
35 setTimeout(function() {
36 bittrex.getmarkets(function(data, err) {
37 assert.equal(err, null);
38 assert.ok(data.success == true);
39 assert.ok(data.result.length > 0);
40 done();
41 });
42 }, 500); //delay the tests so we do not trigger any Bittrex rate limits
43 });
44
45 it('should respond with currencies data', function(done) {
46 this.timeout(5000);
47 setTimeout(function() {
48 bittrex.getcurrencies(function(data, err) {
49 assert.equal(err, null);
50 assert.ok(data.success == true);
51 assert.ok(data.result.length > 0);
52 done();
53 });
54 }, 500);
55 });
56
57 it('should respond with an error for ticker request without a market', function(done) {
58 this.timeout(5000);
59 setTimeout(function() {
60 bittrex.getticker({}, function(data, err) {
61 assert.equal(data, null);
62 assert.ok(err.success == false);
63 assert.ok(err.message.length > 0);
64 done();
65 });
66 }, 500);
67 });
68
69 it('should respond with an error for ticker request for market that doesnt exist', function(done) {
70 this.timeout(5000);
71 setTimeout(function() {
72 bittrex.getticker({ market: 'USDT-XTESTX' }, function(data, err) {
73 assert.equal(data, null);
74 assert.ok(err.success == false);
75 assert.ok(err.message.length > 0);
76 done();
77 });
78 }, 500);
79 });
80
81 it('should respond with ticker data for BTC/USDT', function(done) {
82 this.timeout(5000);
83 setTimeout(function() {
84 bittrex.getticker({ market: 'USDT-BTC' }, function(data, err) {
85 assert.equal(err, null);
86 assert.ok(data.success == true);
87 assert.notEqual(typeof(data.result.Bid), 'undefined');
88 done();
89 });
90 }, 500);
91 });
92
93 it('should respond with all market summaries data', function(done) {
94 this.timeout(5000);
95 setTimeout(function() {
96 bittrex.getmarketsummaries(function(data, err) {
97 assert.equal(err, null);
98 assert.ok(data.success == true);
99 assert.ok(data.result.length > 0);
100 done();
101 });
102 }, 500);
103 });
104
105 it('should respond with market summary for BTC/USDT', function(done) {
106 this.timeout(5000);
107 setTimeout(function() {
108 bittrex.getmarketsummary({ market: 'USDT-BTC' }, function(data, err) {
109 assert.equal(err, null);
110 assert.ok(data.success == true);
111 assert.ok(data.result.length == 1);
112 assert.notEqual(typeof(data.result[0].Bid), 'undefined');
113 done();
114 });
115 }, 500);
116 });
117
118 it('should error for a market summary that doesnt exist', function(done) {
119 this.timeout(5000);
120 setTimeout(function() {
121 bittrex.getmarketsummary({ market: 'USDT-XTESTX' }, function(data, err) {
122 assert.equal(data, null);
123 assert.ok(err.success == false);
124 assert.ok(err.message.length > 0);
125 done();
126 });
127 }, 500);
128 });
129
130 it('should error for a market summary without a market', function(done) {
131 this.timeout(5000);
132 setTimeout(function() {
133 bittrex.getmarketsummary({}, function(data, err) {
134 assert.equal(data, null);
135 assert.ok(err.success == false);
136 assert.ok(err.message.length > 0);
137 done();
138 });
139 }, 500);
140 });
141
142 it('should respond with order book for BTC/USDT', function(done) {
143 this.timeout(5000);
144 setTimeout(function() {
145 bittrex.getorderbook({ market: 'USDT-BTC', type: 'both', depth: 10 }, function(data, err) {
146 assert.equal(err, null);
147 assert.ok(data.success == true);
148 assert.notEqual(typeof(data.result.buy), 'undefined');
149 assert.notEqual(typeof(data.result.sell), 'undefined');
150 done();
151 });
152 }, 500);
153 });
154
155 it('should error for a order book that doesnt exist', function(done) {
156 this.timeout(5000);
157 setTimeout(function() {
158 bittrex.getorderbook({ market: 'USDT-XTESTX', type: 'both', depth: 10 }, function(data, err) {
159 assert.equal(data, null);
160 assert.ok(err.success == false);
161 assert.ok(err.message.length > 0);
162 done();
163 });
164 }, 500);
165 });
166
167 it('should error for a order book without a market', function(done) {
168 this.timeout(5000);
169 setTimeout(function() {
170 bittrex.getorderbook({ type: 'both', depth: 10 }, function(data, err) {
171 assert.equal(data, null);
172 assert.ok(err.success == false);
173 assert.ok(err.message.length > 0);
174 done();
175 });
176 }, 500);
177 });
178
179 it('should respond with market history for BTC/USDT', function(done) {
180 this.timeout(5000);
181 setTimeout(function() {
182 bittrex.getmarkethistory({ market: 'USDT-BTC' }, function(data, err) {
183 assert.equal(err, null);
184 assert.ok(data.success == true);
185 assert.ok(data.result.length > 0);
186 done();
187 });
188 }, 500);
189 });
190
191 it('should error for a market history that doesnt exist', function(done) {
192 this.timeout(5000);
193 setTimeout(function() {
194 bittrex.getmarkethistory({ market: 'USDT-XTESTX' }, function(data, err) {
195 assert.equal(data, null);
196 assert.ok(err.success == false);
197 assert.ok(err.message.length > 0);
198 done();
199 });
200 }, 500);
201 });
202
203 it('should error for a market history without a market', function(done) {
204 this.timeout(5000);
205 setTimeout(function() {
206 bittrex.getmarkethistory({ }, function(data, err) {
207 assert.equal(data, null);
208 assert.ok(err.success == false);
209 assert.ok(err.message.length > 0);
210 done();
211 });
212 }, 500);
213 });
214
215 it('should respond with candles for BTC/USDT', function(done) {
216 this.timeout(5000);
217 setTimeout(function() {
218 bittrex.getcandles({
219 marketName: 'USDT-BTC',
220 tickInterval: 'fiveMin', // intervals are keywords
221 _: ((new Date()).getTime()/1000)-(300*5) // start timestamp
222 }, function(data, err) {
223 assert.equal(err, null);
224 assert.ok(data.success == true);
225 assert.ok(data.result.length > 0);
226 done();
227 });
228 }, 500);
229 });
230
231 it('should error for a candles that doesnt exist', function(done) {
232 this.timeout(5000);
233 setTimeout(function() {
234 bittrex.getcandles({ marketName: 'USDT-XTESTX', tickInterval: 300 }, function(data, err) {
235 assert.equal(data, null);
236 assert.ok(err.success == false);
237 assert.ok(err.message.length > 0);
238 done();
239 });
240 }, 500);
241 });
242
243 it('should error for a candles without a market', function(done) {
244 this.timeout(5000);
245 setTimeout(function() {
246 bittrex.getcandles({ }, function(data, err) {
247 assert.equal(data, null);
248 assert.ok(err.success == false);
249 assert.ok(err.message.length > 0);
250 done();
251 });
252 }, 500);
253 });
254
255 it('should get ticker data via sendCustomRequest', function(done) {
256 this.timeout(5000);
257 setTimeout(function() {
258 var url = 'https://bittrex.com/api/v1.1/public/getticker?market=USDT-BTC';
259 bittrex.sendCustomRequest( url, function( data, err ) {
260 assert.equal(err, null);
261 assert.ok(data.success == true);
262 assert.notEqual(typeof(data.result.Bid), 'undefined');
263 done();
264 });
265 }, 500);
266 });
267
268 it('should error with request for ticker data that doesnt exist via sendCustomRequest', function(done) {
269 this.timeout(5000);
270 setTimeout(function() {
271 var url = 'https://bittrex.com/api/v1.1/public/getticker?market=USDT-BTCXXX';
272 bittrex.sendCustomRequest( url, function( data, err ) {
273 assert.equal(data, null);
274 assert.ok(err.success == false);
275 assert.ok(err.message.length > 0);
276 done();
277 });
278 }, 500);
279 });
280
281});
\No newline at end of file