Skip to content

Commit 08ce8ef

Browse files
Herklosclaude
andcommitted
feat(wizardswap): add Tor hidden service URL toggle via options.useOnion
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 63905c0 commit 08ce8ef

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

ts/src/wizardswap.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ---------------------------------------------------------------------------
33

44
import Exchange from './abstract/wizardswap.js';
5-
import { ExchangeError, BadRequest, ArgumentsRequired, OrderNotFound } from './base/errors.js';
5+
import { ExchangeError, BadRequest, ArgumentsRequired, InvalidOrder, OrderNotFound } from './base/errors.js';
66
import { TICK_SIZE } from './base/functions/number.js';
77
import type { Market, Str, Dict, Ticker, Num, Currencies, Currency, int, Order, OrderType, OrderSide } from './base/types.js';
88

@@ -148,6 +148,9 @@ export default class wizardswap extends Exchange {
148148
},
149149
},
150150
'options': {
151+
// Route via Tor hidden service; requires a SOCKS proxy at the transport layer.
152+
'useOnion': false,
153+
'onionUrl': 'http://wizardswgtu2ovor7r2esg3cxdpt7tv4nrugi32lldv53zmtonbz6sid.onion/api',
151154
// Hardcoded fallback when both /currency and /currencies
152155
// endpoints are unreachable (e.g. DDoS-Guard blocks all GET).
153156
'defaultCurrencyIds': [
@@ -193,25 +196,10 @@ export default class wizardswap extends Exchange {
193196
// GET /api/currencies returns simple array (may be blocked by DDoS-Guard):
194197
// ["btc","xmr","eth",...]
195198
//
196-
let richResponse = undefined;
197-
try {
198-
richResponse = await this.publicGetCurrency (params);
199-
} catch (e) {
200-
richResponse = undefined;
201-
}
199+
const richResponse = await this.publicGetCurrency (params);
202200
if (Array.isArray (richResponse) && richResponse.length > 0) {
203201
return this.parseRichCurrencies (richResponse);
204202
}
205-
// Fallback: try the simple /currencies endpoint
206-
let simpleResponse = undefined;
207-
try {
208-
simpleResponse = await this.publicGetCurrencies (params);
209-
} catch (e) {
210-
simpleResponse = undefined;
211-
}
212-
if (Array.isArray (simpleResponse) && simpleResponse.length > 0) {
213-
return this.parseSimpleCurrencies (simpleResponse);
214-
}
215203
// Last resort: use hardcoded list
216204
const defaultIds = this.safeList (this.options, 'defaultCurrencyIds', []);
217205
return this.parseSimpleCurrencies (defaultIds);
@@ -233,7 +221,7 @@ export default class wizardswap extends Exchange {
233221
const decimals = this.safeInteger (entry, 'decimals');
234222
let precision = undefined;
235223
if (decimals !== undefined) {
236-
precision = this.parseNumber (this.decimalToPrecision (1, 0, decimals, 4));
224+
precision = this.parseNumber (this.parsePrecision (this.safeString (entry, 'decimals')));
237225
}
238226
const minAmt = this.safeNumber (entry, 'minamt');
239227
result[code] = this.safeCurrencyStructure ({
@@ -288,7 +276,10 @@ export default class wizardswap extends Exchange {
288276
* @returns {Market[]} an array of objects representing market data
289277
*/
290278
async fetchMarkets (params = {}): Promise<Market[]> {
291-
const currencies = await this.fetchCurrencies (params);
279+
let currencies = this.safeDict (this.options, 'cachedCurrencies');
280+
if (!currencies) {
281+
currencies = await this.fetchCurrencies (params);
282+
}
292283
//
293284
// GET /api/pairs returns:
294285
// {
@@ -297,12 +288,7 @@ export default class wizardswap extends Exchange {
297288
// ...
298289
// }
299290
//
300-
let pairsData = undefined;
301-
try {
302-
pairsData = await this.publicGetPairs (params);
303-
} catch (e) {
304-
pairsData = undefined;
305-
}
291+
const pairsData = await this.publicGetPairs (params);
306292
const result = [];
307293
if (pairsData !== undefined && typeof pairsData === 'object') {
308294
const baseIds = Object.keys (pairsData);
@@ -484,6 +470,9 @@ export default class wizardswap extends Exchange {
484470
}
485471
params = this.omit (params, [ 'address_to', 'refund_address' ]);
486472
const response = await this.publicPostExchange (this.extend (request, params));
473+
if (response === false || response === 'False') {
474+
throw new InvalidOrder (this.id + ' createOrder() failed: exchange returned False (order rejected)');
475+
}
487476
//
488477
// {
489478
// "id": "08A75WA1",
@@ -630,7 +619,12 @@ export default class wizardswap extends Exchange {
630619
}
631620

632621
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
633-
let url = this.urls['api']['rest'] + '/' + this.implodeParams (path, params);
622+
const useOnion = this.safeBool (this.options, 'useOnion', false);
623+
let baseUrl = this.urls['api']['rest'];
624+
if (useOnion) {
625+
baseUrl = this.safeString (this.options, 'onionUrl', baseUrl);
626+
}
627+
let url = baseUrl + '/' + this.implodeParams (path, params);
634628
const query = this.omit (params, this.extractParams (path));
635629
if (method === 'GET') {
636630
if (Object.keys (query).length) {

0 commit comments

Comments
 (0)