forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
211 lines (166 loc) · 6.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"use strict";
const ccxt = require ('./ccxt')
const countries = require ('./countries')
const asTable = require ('as-table')
const util = require ('util')
let markets = {}
let verbose = false
try {
markets = require ('./config')
} catch (e) {
markets = {}
}
// console.log (ccxt)
ccxt.markets.forEach (id => {
markets[id] = new (ccxt)[id] ({ 'verbose': verbose, apiKey: '', secret: '', })
})
console.log (Object.values (ccxt).length)
var countryName = function (code) {
return ((typeof countries[code] !== 'undefined') ? countries[code] : code)
}
let sleep = async ms => await new Promise (resolve => setTimeout (resolve, ms))
let testMarket = market => new Promise (async resolve => {
let delay = market.rateLimit
let products = await market.loadProducts ()
let keys = Object.keys (products)
console.log (market.id , keys.length, 'symbols', keys.join (', '))
// Object.values (market.products).map (x => console.log (market.id, x.id))
// console.log (market.id, 'products', market.products)
// console.log (market.id, Object.keys (market.products).length, 'symbols', Object.keys (market.products).join (', '))
// sleep (delay)
// let orderbook = await market.fetchOrderBook (Object.keys (market.products)[0])
// console.log (market.id, orderbook)
// sleep (delay)
// let symbol = keys[0]
// let symbols = [
// 'BTC/USD',
// 'BTC/CNY',
// 'BTC/ETH',
// 'ETH/BTC',
// 'BTC/JPY',
// 'LTC/BTC',
// ]
// for (let s in symbols) {
// if (symbols[s] in keys) {
// symbol = symbols[s]
// break
// }
// }
for (let s in keys) {
let symbol = keys[s]
if (symbol.indexOf ('.d') < 0) {
await sleep (delay)
let ticker = await market.fetchTicker (symbol)
console.log (market.id, symbol, 'ticker',
ticker['datetime'],
'high: ' + ticker['high'],
'low: ' + ticker['low'],
'bid: ' + ticker['bid'],
'ask: ' + ticker['ask'],
'volume: ' + ticker['quoteVolume'])
await sleep (delay)
let orderbook = await market.fetchOrderBook (symbol)
console.log (market.id, symbol, 'order book',
orderbook['datetime'],
'bid: ' + ((orderbook.bids.length > 0) ? orderbook.bids[0][0] : 'N/A'),
'bidVolume: ' + ((orderbook.bids.length > 0) ? orderbook.bids[0][1] : 'N/A'),
'ask: ' + ((orderbook.asks.length > 0) ? orderbook.asks[0][0] : 'N/A'),
'askVolume: ' + ((orderbook.asks.length > 0) ? orderbook.asks[0][1] : 'N/A'))
let bids = orderbook.bids
if (bids.length > 1) {
let first = 0
let last = bids.length - 1
if (bids[first][0] < bids[last][0])
console.log (market.id, symbol, 'bids reversed')
else if (bids[first][0] > bids[last][0])
console.log (market.id, symbol, 'bids ok')
}
let asks = orderbook.asks
if (asks.length > 1) {
let first = 0
let last = asks.length - 1
if (asks[first][0] > asks[last][0])
console.log (market.id, symbol, 'asks reversed', asks[first][0], asks[last][0])
else if (asks[first][0] < asks[last][0])
console.log (market.id, symbol, 'asks ok')
}
}
}
// let trades = await market.fetchTrades (Object.keys (market.products)[0])
// console.log (market.id, trades)
if (!market.apiKey || (market.apiKey.length < 1))
return true
sleep (delay)
let balance = await market.fetchBalance ()
console.log (market.id, 'balance', balance)
// sleep (delay)
// try {
// let marketSellOrder = await market.createMarketSellOrder (Object.keys (market.products)[0], 1)
// console.log (market.id, 'ok', marketSellOrder)
// } catch (e) {
// console.log (market.id, 'error', 'market sell', e)
// }
// sleep (delay)
// try {
// let marketBuyOrder = await market.createMarketBuyOrder (Object.keys (market.products)[0], 1)
// console.log (market.id, 'ok', marketBuyOrder)
// } catch (e) {
// console.log (market.id, 'error', 'market buy', e)
// }
// sleep (delay)
// try {
// let limitSellOrder = await market.createLimitSellOrder (Object.keys (market.products)[0], 1, 3000)
// console.log (market.id, 'ok', limitSellOrder)
// } catch (e) {
// console.log (market.id, 'error', 'limit sell', e)
// }
// sleep (delay)
// try {
// let limitBuyOrder = await market.createLimitBuyOrder (Object.keys (market.products)[0], 1, 3000)
// console.log (market.id, 'ok', limitBuyOrder)
// } catch (e) {
// console.log (market.id, 'error', 'limit buy', e)
// }
})
//-----------------------------------------------------------------------------
var test = async function () {
//-------------------------------------------------------------------------
// list all supported exchanges
console.log (asTable.configure ({ delimiter: ' | ' }) (Object.values (markets).map (market => {
let website = Array.isArray (market.urls.www) ? market.urls.www[0] : market.urls.www
let countries = Array.isArray (market.countries) ? market.countries.map (countryName).join (', ') : countryName (market.countries)
let doc = Array.isArray (market.urls.doc) ? market.urls.doc[0] : market.urls.doc
return {
' ': '',
'id': market.id,
'name': '[' + market.name + '](' + website + ')',
'docs': '[API](' + doc + ')',
'countries': countries,
// 'notes': 'Full support',
' ': '',
}
})))
if (process.argv.length > 2) {
let id = process.argv[2]
if (markets[id]) {
let market = markets[id]
try {
await testMarket (market)
} catch (e) {
console.log (market.id, e)
process.exit ()
}
}
} else {
Object.keys (markets).forEach (async id => {
var market = markets[id]
try {
await testMarket (market)
} catch (e) {
console.log (market.id, e)
process.exit ()
}
sleep (1000)
})
}
} ()