forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
217 lines (180 loc) · 6.49 KB
/
test.ts
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
212
213
214
215
216
217
import fs from 'fs';
import log from 'ololog';
import { dirname } from 'path';
import HttpsProxyAgent from 'https-proxy-agent';
import { Agent } from 'https';
import { fileURLToPath, pathToFileURL } from 'url';
import ccxt from '../../../ccxt.js';
//
const __dirname = fileURLToPath (new URL ('.', import.meta.url));
log.handleNodeErrors ();
const [ processPath, , exchangeId, exchangeSymbol ] = process.argv.filter ((x) => !x.startsWith ('--'));
const verbose = process.argv.includes ('--verbose') || false;
const ext = import.meta.url.split ('.')[1];
// ----------------------------------------------------------------------------
if (!exchangeId) {
console.log ('Exchange id not specified');
process.exit (0);
}
if (verbose) {
log.bright.yellow ('Running in verbose mode');
}
const exchangeSymbols = JSON.parse (fs.readFileSync ('./pro-tests.json', "utf8"));
const symbol = exchangeSymbol || exchangeSymbols[exchangeId] || 'BTC/USDT';
log.bright ('\nTESTING', { exchangeId, symbol }, '\n');
// ----------------------------------------------------------------------------
const enableRateLimit = true;
const ecdhCurve = 'auto';
const agent = new Agent ({ ecdhCurve });
const timeout = 20000;
const print = function printToFile (... args) {
args = args.map ((x) => {
if (typeof x === 'string') {
return x;
} else if (x instanceof Date) {
return x.toISOString ();
} else {
return JSON.stringify (x);
}
});
fs.appendFileSync ('js.' + exchangeId + '.log', args.join (' ') + "\n");
};
const exchangeOptions = {
agent,
// verbose,
enableRateLimit,
timeout,
// print,
};
const exchange = new (ccxt.pro)[exchangeId] (exchangeOptions);
// exchange.urls.api = exchange.urls.test
// ----------------------------------------------------------------------------
const tests = {};
// eslint-disable-next-line no-path-concat
const pathToExchangeTests = __dirname + '/Exchange/';
const filteredFiles = fs.readdirSync (pathToExchangeTests)
.filter ((file) => file.match (/test.[a-zA-Z0-9_-]+.(ts|js)$/))
.map ((file) => file.slice (0, -3)); // remove extensions
// eslint-disable-next-line no-restricted-syntax
for (const file of filteredFiles) {
const key = file.slice (5);
tests[key] = (await import (pathToFileURL (pathToExchangeTests + (file as string) + '.js').toString ()) as any)['default'];
}
//-----------------------------------------------------------------------------
const rootDir = __dirname + '/../../../../';
const keysGlobal = rootDir + 'keys.json'
, keysLocal = rootDir + 'keys.local.json'
, keysFile = fs.existsSync (keysLocal) ? keysLocal : keysGlobal;
const settingsFile = fs.readFileSync (keysFile, 'utf8');
let settings = JSON.parse (settingsFile as any);
settings = exchange.safeValue (settings, exchangeId, {});
const skipSettingsFile = fs.readFileSync (rootDir + 'skip-tests.json', 'utf8');
const skipSettings = JSON.parse (skipSettingsFile as any);
const skippedSettingsForExchange = exchange.safeValue (skipSettings, exchangeId, {});
if (settings) {
// eslint-disable-next-line no-restricted-syntax
for (const [ key, val ] of Object.entries (settings)) {
if (settings[key]) {
settings[key] = ccxt.deepExtend (exchange[key] || {}, val);
}
}
}
Object.assign (exchange, settings);
if (skippedSettingsForExchange && (skippedSettingsForExchange.skip || skippedSettingsForExchange.skipWs)) {
log.error.bright ('[Skipped] exchange', exchangeId);
process.exit (0);
}
//-----------------------------------------------------------------------------
if (settings && settings.httpProxy) {
const agent = HttpsProxyAgent (settings.httpProxy);
exchange.agent = agent;
}
//-----------------------------------------------------------------------------
async function testPublic (exchange, symbol) {
await tests['watchOrderBook'] (exchange, symbol);
await tests['watchTicker'] (exchange, symbol);
await tests['watchTrades'] (exchange, symbol);
await tests['watchOHLCV'] (exchange, symbol);
// await tests['watchStatus'] (exchange)
// await tests['watchHeartbeat'] (exchange)
// await tests['watchL2OrderBook'] (exchange, symbol)
// await tests['watchOrderBooks'] (exchange, symbol)
// await tests['watchTickers'] (exchange, [ symbol ])
}
async function testPrivate (exchange, symbol, code) {
if (exchange.checkRequiredCredentials (false)) {
await tests['watchBalance'] (exchange);
// await tests['watchOrders'] (exchange, symbol)
// await tests['watchOpenOrders'] (exchange, symbol)
// await tests['watchClosedOrders'] (exchange, symbol)
await tests['watchMyTrades'] (exchange, symbol);
await tests['watchPosition'] (exchange, symbol);
await tests['watchPositions'] (exchange, symbol);
// const code = exchange.markets[symbol]['quote']
// await tests['watchLedger'] (exchange, code)
// await tests['watchTransactions'] (exchange, code)
// await tests['watchDeposits'] (exchange, code)
// await tests['watchWithdrawals'] (exchange, code)
}
}
//-----------------------------------------------------------------------------
async function testExchange (exchange) {
const codes = [
'BTC',
'ETH',
'XRP',
'LTC',
'BCH',
'EOS',
'BNB',
'BSV',
'USDT',
'ATOM',
'BAT',
'BTG',
'DASH',
'DOGE',
'ETC',
'IOTA',
'LSK',
'MKR',
'NEO',
'PAX',
'QTUM',
'TRX',
'TUSD',
'USD',
'USDC',
'WAVES',
'XEM',
'XMR',
'ZEC',
'ZRX',
];
let code = codes[0];
for (let i = 0; i < codes.length; i++) {
if (codes[i] in exchange.currencies) {
code = codes[i];
break;
}
}
log.green ('CODE:', code);
log.green ('SYMBOL:', symbol);
if ((symbol.indexOf ('.d') < 0)) {
await testPublic (exchange, symbol);
await testPrivate (exchange, symbol, code);
}
}
//-----------------------------------------------------------------------------
async function test () {
if (exchange.alias) {
console.log ('Skipped alias');
process.exit (0);
}
await exchange.loadMarkets ();
exchange.verbose = verbose;
await testExchange (exchange);
console.log (new Date (), 'Done.');
process.exit (0);
}
test ();