-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
88 lines (74 loc) · 2.62 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var expect = require('expect.js')
, MtGox = require('./index')
, config = require('konfu')
, mtgox = new MtGox({
key: config.mtgox_key,
secret: config.mtgox_secret
})
describe('MtGox', function() {
this.timeout(10e3)
describe('market', function() {
it('returns stats for BTCUSD', function(done) {
mtgox.market('BTCUSD', function(err, market) {
if (err) return done(err)
expect(market.last).to.be.a('string')
expect(market.bid).to.be.a('string')
expect(market.ask).to.be.a('string')
expect(market.high).to.be.a('string')
expect(market.low).to.be.a('string')
expect(market.volume).to.be.a('string')
expect(market.average).to.be.a('string')
expect(market.timestamp).to.be.a('number')
done()
})
})
})
describe('depth', function() {
it('returns depth for BTCUSD', function(done) {
mtgox.depth('BTCUSD', function(err, depth) {
if (err) return done(err)
var bid = depth.bids[0]
expect(bid.price).to.be.a('string')
expect(bid.volume).to.be.a('string')
var ask = depth.asks[0]
expect(ask.price).to.be.a('string')
expect(ask.volume).to.be.a('string')
done()
})
})
})
describe('order/orders/cancel', function() {
var id
after(function(done) {
if (!id) return done()
mtgox.cancel(id, done)
})
it('can create and cancel an order', function(done) {
if (!config.mtgox_secret) {
console.log('Skipping test (API secret needed)')
return done()
}
mtgox.order({
side: 'ask',
price: '10000',
volume: '0.01',
market: 'BTCUSD'
}, function(err, i) {
id = i
if (err) return done(err)
expect(id).to.be.a('string')
mtgox.orders(function(err, orders) {
if (err) return done(err)
var order = orders.filter(function(o) {
return o.id === id
})[0]
expect(order.price).to.be('10000')
expect(order.volume).to.be('0.01')
expect(order.side).to.be('ask')
expect(order.market).to.be('BTCUSD')
done()
})
})
})
})
})