ccxt
Version:
968 lines (966 loc) • 89.8 kB
JavaScript
// ----------------------------------------------------------------------------
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
// ---------------------------------------------------------------------------
import nadoRest from '../nado.js';
import { ArgumentsRequired, ExchangeError, InvalidNonce, NotSupported } from '../base/errors.js';
import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
import { Precise } from '../base/Precise.js';
import { keccak_256 as keccak } from '@noble/hashes/sha3.js';
// ---------------------------------------------------------------------------
export default class nado extends nadoRest {
describe() {
return this.deepExtend(super.describe(), {
'has': {
'ws': true,
'cancelAllOrdersWs': true,
'cancelOrderWs': true,
'cancelOrdersWs': true,
'createOrderWs': true,
'editOrderWs': true,
'watchBalance': false,
'watchBidsAsks': true,
'watchFundingRate': false,
'watchFundingRates': false,
'watchLiquidations': false,
'watchLiquidationsForSymbols': false,
'watchMyTrades': true,
'unWatchBidsAsks': true,
'unWatchMyTrades': true,
'unWatchOHLCV': true,
'unWatchOHLCVForSymbols': true,
'unWatchOrderBook': true,
'unWatchOrderBookForSymbols': true,
'unWatchOrders': true,
'unWatchPositions': true,
'unWatchTicker': true,
'unWatchTickers': true,
'unWatchTrades': true,
'unWatchTradesForSymbols': true,
'watchOHLCV': true,
'watchOHLCVForSymbols': true,
'watchOrderBook': true,
'watchOrderBookForSymbols': true,
'watchOrders': true,
'watchPositions': true,
'watchTicker': true,
'watchTickers': true,
'watchTrades': true,
'watchTradesForSymbols': true,
},
'streaming': {
'ping': this.ping,
'keepAlive': 30000,
},
'options': {
'tradesLimit': 1000,
'requestId': 0,
},
'urls': {
'api': {
'ws': {
'gateway': 'wss://gateway.prod.nado.xyz/ws/v2',
'subscriptions': 'wss://gateway.prod.nado.xyz/v1/subscribe',
},
},
'test': {
'ws': {
'gateway': 'wss://gateway.test.nado.xyz/ws/v2',
'subscriptions': 'wss://gateway.test.nado.xyz/v1/subscribe',
},
},
},
});
}
requestId() {
const requestId = this.sum(this.safeInteger(this.options, 'requestId', 0), 1);
this.options['requestId'] = requestId;
return requestId;
}
/**
* @method
* @name nado#watchTrades
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches information on multiple trades made in a market
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
*/
async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
const market = this.market(symbol);
const messageHash = 'trade:' + market['symbol'];
const trades = await this.watchPublic('trade', market, messageHash, params);
if (this.newUpdates) {
limit = trades.getLimit(market['symbol'], limit);
}
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
}
/**
* @method
* @name nado#unWatchTrades
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on multiple trades made in a market
* @param {string} symbol unified symbol of the market to unwatch trades for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchTrades(symbol, params = {}) {
await this.loadMarkets();
return await this.unWatchTradesForSymbols([symbol], params);
}
/**
* @method
* @name nado#watchTradesForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description get the list of most recent trades for a list of symbols
* @param {string[]} symbols unified symbols of the markets to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
*/
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
const symbolsLength = symbols.length;
if (symbolsLength === 0) {
throw new ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
}
symbols = this.marketSymbols(symbols, undefined, false, true, true);
const markets = [];
const messageHashes = [];
for (let i = 0; i < symbols.length; i++) {
const market = this.market(symbols[i]);
markets.push(market);
messageHashes.push('trade:' + market['symbol']);
}
const trades = await this.watchPublicMultiple('trade', markets, messageHashes, params);
if (this.newUpdates) {
const first = this.safeDict(trades, 0);
const tradeSymbol = this.safeString(first, 'symbol');
limit = trades.getLimit(tradeSymbol, limit);
}
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
}
/**
* @method
* @name nado#unWatchTradesForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on multiple trades made in a list of markets
* @param {string[]} symbols unified symbols of the markets to unwatch trades for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchTradesForSymbols(symbols, params = {}) {
await this.loadMarkets();
const symbolsLength = symbols.length;
if (symbolsLength === 0) {
throw new ArgumentsRequired(this.id + ' unWatchTradesForSymbols() requires a non-empty array of symbols');
}
symbols = this.marketSymbols(symbols, undefined, false, true, true);
const markets = [];
const messageHashes = [];
for (let i = 0; i < symbols.length; i++) {
const market = this.market(symbols[i]);
markets.push(market);
messageHashes.push('trade:' + market['symbol']);
}
return await this.unWatchPublicMultiple('trade', markets, messageHashes, params);
}
/**
* @method
* @name nado#watchOrderBook
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {OrderBook} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
async watchOrderBook(symbol, limit = undefined, params = {}) {
await this.loadMarkets();
const market = this.market(symbol);
const messageHash = 'orderbook:' + market['symbol'];
if (!(market['symbol'] in this.orderbooks)) {
const snapshot = await this.fetchOrderBook(symbol, limit);
this.orderbooks[market['symbol']] = this.orderBook(snapshot, limit);
}
const orderbook = await this.watchPublic('book_depth', market, messageHash, params);
return orderbook.limit();
}
/**
* @method
* @name nado#unWatchOrderBook
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @param {string} symbol unified symbol of the market to unwatch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchOrderBook(symbol, params = {}) {
await this.loadMarkets();
return await this.unWatchOrderBookForSymbols([symbol], params);
}
/**
* @method
* @name nado#watchOrderBookForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data for a list of symbols
* @param {string[]} symbols unified symbols of the markets to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {OrderBook} an [order book structure]{@link https://docs.ccxt.com/#/?id=order-book-structure}
*/
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
await this.loadMarkets();
const symbolsLength = symbols.length;
if (symbolsLength === 0) {
throw new ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a non-empty array of symbols');
}
symbols = this.marketSymbols(symbols, undefined, false, true, true);
const markets = [];
const messageHashes = [];
for (let i = 0; i < symbols.length; i++) {
const symbol = symbols[i];
const market = this.market(symbol);
const messageHash = 'orderbook:' + market['symbol'];
markets.push(market);
messageHashes.push(messageHash);
if (!(market['symbol'] in this.orderbooks)) {
const snapshot = await this.fetchOrderBook(symbol, limit);
this.orderbooks[market['symbol']] = this.orderBook(snapshot, limit);
}
}
const orderbook = await this.watchPublicMultiple('book_depth', markets, messageHashes, params);
return orderbook.limit();
}
/**
* @method
* @name nado#unWatchOrderBookForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data for a list of symbols
* @param {string[]} symbols unified symbols of the markets to unwatch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchOrderBookForSymbols(symbols, params = {}) {
await this.loadMarkets();
const symbolsLength = symbols.length;
if (symbolsLength === 0) {
throw new ArgumentsRequired(this.id + ' unWatchOrderBookForSymbols() requires a non-empty array of symbols');
}
symbols = this.marketSymbols(symbols, undefined, false, true, true);
const markets = [];
const messageHashes = [];
for (let i = 0; i < symbols.length; i++) {
const market = this.market(symbols[i]);
markets.push(market);
messageHashes.push('orderbook:' + market['symbol']);
}
return await this.unWatchPublicMultiple('book_depth', markets, messageHashes, params);
}
/**
* @method
* @name nado#watchOHLCV
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
const market = this.market(symbol);
const messageHash = 'ohlcv:' + timeframe + ':' + market['symbol'];
const request = {
'granularity': this.safeInteger(this.timeframes, timeframe, this.parseTimeframe(timeframe)),
};
const result = await this.watchPublic('latest_candlestick', market, messageHash, this.extend(request, params));
const stored = result[2];
if (this.newUpdates) {
limit = stored.getLimit(market['symbol'], limit);
}
return this.filterBySinceLimit(stored, since, limit, 0, true);
}
/**
* @method
* @name nado#watchOHLCVForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of multiple markets
* @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to watch OHLCV data for, example [['BTC/USDT0:USDT0', '1m'], ['ETH/USDT0:USDT0', '5m']]
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} A dictionary of {@link https://docs.ccxt.com/#/?id=ohlcv-structure OHLCV} structures indexed by market symbols
*/
async watchOHLCVForSymbols(symbolsAndTimeframes, since = undefined, limit = undefined, params = {}) {
const symbolsLength = symbolsAndTimeframes.length;
if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
throw new ArgumentsRequired(this.id + " watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT0:USDT0', '1m'], ['ETH/USDT0:USDT0', '5m']]");
}
await this.loadMarkets();
const markets = [];
const messageHashes = [];
const subscriptionParams = [];
for (let i = 0; i < symbolsAndTimeframes.length; i++) {
const symbolAndTimeframe = symbolsAndTimeframes[i];
const marketSymbol = this.safeString(symbolAndTimeframe, 0);
const timeframe = this.safeString(symbolAndTimeframe, 1, '1m');
const market = this.market(marketSymbol);
markets.push(market);
messageHashes.push('ohlcv:' + timeframe + ':' + market['symbol']);
subscriptionParams.push(this.extend({
'granularity': this.safeInteger(this.timeframes, timeframe, this.parseTimeframe(timeframe)),
}, params));
}
const [resultSymbol, resultTimeframe, stored] = await this.watchPublicMultiple('latest_candlestick', markets, messageHashes, params, subscriptionParams);
if (this.newUpdates) {
limit = stored.getLimit(resultSymbol, limit);
}
const filtered = this.filterBySinceLimit(stored, since, limit, 0, true);
return this.createOHLCVObject(resultSymbol, resultTimeframe, filtered);
}
/**
* @method
* @name nado#unWatchOHLCV
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @param {string} symbol unified symbol of the market to unwatch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
await this.loadMarkets();
return await this.unWatchOHLCVForSymbols([[symbol, timeframe]], params);
}
/**
* @method
* @name nado#unWatchOHLCVForSymbols
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of multiple markets
* @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to unwatch OHLCV data for, example [['BTC/USDT0:USDT0', '1m'], ['ETH/USDT0:USDT0', '5m']]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchOHLCVForSymbols(symbolsAndTimeframes, params = {}) {
const symbolsLength = symbolsAndTimeframes.length;
if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
throw new ArgumentsRequired(this.id + " unWatchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT0:USDT0', '1m'], ['ETH/USDT0:USDT0', '5m']]");
}
await this.loadMarkets();
const markets = [];
const messageHashes = [];
const subscriptionParams = [];
for (let i = 0; i < symbolsAndTimeframes.length; i++) {
const symbolAndTimeframe = symbolsAndTimeframes[i];
const marketSymbol = this.safeString(symbolAndTimeframe, 0);
const timeframe = this.safeString(symbolAndTimeframe, 1, '1m');
const market = this.market(marketSymbol);
markets.push(market);
messageHashes.push('ohlcv:' + timeframe + ':' + market['symbol']);
subscriptionParams.push(this.extend({
'granularity': this.safeInteger(this.timeframes, timeframe, this.parseTimeframe(timeframe)),
}, params));
}
return await this.unWatchPublicMultiple('latest_candlestick', markets, messageHashes, params, subscriptionParams);
}
/**
* @method
* @name nado#watchTicker
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches a price ticker with the best bid and ask for a specific market
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
async watchTicker(symbol, params = {}) {
await this.loadMarkets();
symbol = this.symbol(symbol);
const tickers = await this.watchTickers([symbol], params);
return tickers[symbol];
}
/**
* @method
* @name nado#unWatchTicker
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches a price ticker with the best bid and ask for a specific market
* @param {string} symbol unified symbol of the market to unwatch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchTicker(symbol, params = {}) {
await this.loadMarkets();
return await this.unWatchTickers([symbol], params);
}
/**
* @method
* @name nado#watchTickers
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches price tickers with the best bid and ask for all markets of a specific list
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
async watchTickers(symbols = undefined, params = {}) {
await this.loadMarkets();
symbols = this.marketSymbols(symbols, undefined, true, true, true);
let market = undefined;
let messageHash = 'ticker';
let streamType = 'all_bbo';
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
market = this.market(symbols[0]);
messageHash = 'ticker:' + market['symbol'];
streamType = 'best_bid_offer';
}
}
const ticker = await this.watchPublic(streamType, market, messageHash, params);
if (this.newUpdates) {
if (messageHash === 'ticker') {
return this.filterByArray(ticker, 'symbol', symbols);
}
const tickers = {};
tickers[ticker['symbol']] = ticker;
return tickers;
}
return this.filterByArray(this.tickers, 'symbol', symbols);
}
/**
* @method
* @name nado#unWatchTickers
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches price tickers with the best bid and ask for all markets of a specific list
* @param {string[]} [symbols] unified symbols of the markets to unwatch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchTickers(symbols = undefined, params = {}) {
await this.loadMarkets();
symbols = this.marketSymbols(symbols, undefined, true, true, true);
let market = undefined;
let messageHash = 'ticker';
let streamType = 'all_bbo';
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
market = this.market(symbols[0]);
messageHash = 'ticker:' + market['symbol'];
streamType = 'best_bid_offer';
}
}
return await this.unWatchPublic(streamType, market, messageHash, params);
}
/**
* @method
* @name nado#watchBidsAsks
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description watches best bid & ask for symbols
* @param {string[]} symbols unified symbols of the markets to fetch the bids and asks for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
async watchBidsAsks(symbols = undefined, params = {}) {
await this.loadMarkets();
symbols = this.marketSymbols(symbols, undefined, true, true, true);
let market = undefined;
let messageHash = 'bidask';
let streamType = 'all_bbo';
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
market = this.market(symbols[0]);
messageHash = 'bidask:' + market['symbol'];
streamType = 'best_bid_offer';
}
}
const ticker = await this.watchPublic(streamType, market, messageHash, params);
if (this.newUpdates) {
if (messageHash === 'bidask') {
return this.filterByArray(ticker, 'symbol', symbols);
}
const tickers = {};
tickers[ticker['symbol']] = ticker;
return tickers;
}
return this.filterByArray(this.bidsasks, 'symbol', symbols);
}
/**
* @method
* @name nado#unWatchBidsAsks
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches best bid & ask for symbols
* @param {string[]} symbols unified symbols of the markets to unwatch the bids and asks for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchBidsAsks(symbols = undefined, params = {}) {
await this.loadMarkets();
symbols = this.marketSymbols(symbols, undefined, true, true, true);
let market = undefined;
let messageHash = 'bidask';
let streamType = 'all_bbo';
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
market = this.market(symbols[0]);
messageHash = 'bidask:' + market['symbol'];
streamType = 'best_bid_offer';
}
}
return await this.unWatchPublic(streamType, market, messageHash, params);
}
/**
* @method
* @name nado#watchOrders
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/events
* @description watches information on multiple orders made by the user
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
let market = undefined;
let messageHash = 'orders';
let productId = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
symbol = market['symbol'];
messageHash += ':' + symbol;
productId = this.parseToInt(market['id']);
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'watchOrders', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'order_update',
'subaccount': sender,
'product_id': productId,
};
const orders = await this.watchPrivate('order_update', stream, messageHash, params);
if (this.newUpdates) {
limit = orders.getLimit(symbol, limit);
}
return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
}
/**
* @method
* @name nado#unWatchOrders
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on multiple orders made by the user
* @param {string} symbol unified market symbol of the market orders were made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchOrders(symbol = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
let market = undefined;
let messageHash = 'orders';
let productId = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
symbol = market['symbol'];
messageHash += ':' + symbol;
productId = this.parseToInt(market['id']);
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'unWatchOrders', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'order_update',
'subaccount': sender,
'product_id': productId,
};
return await this.unWatchPrivate(stream, messageHash, params);
}
/**
* @method
* @name nado#watchMyTrades
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/events
* @description watches information on multiple trades made by the user
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
let market = undefined;
let messageHash = 'myTrades';
let productId = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
symbol = market['symbol'];
messageHash += ':' + symbol;
productId = this.parseToInt(market['id']);
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'fill',
'subaccount': sender,
'product_id': productId,
};
const trades = await this.watchPrivate('fill', stream, messageHash, params);
if (this.newUpdates) {
limit = trades.getLimit(symbol, limit);
}
return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
}
/**
* @method
* @name nado#unWatchMyTrades
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on multiple trades made by the user
* @param {string} symbol unified market symbol of the market orders were made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchMyTrades(symbol = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
let market = undefined;
let messageHash = 'myTrades';
let productId = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
symbol = market['symbol'];
messageHash += ':' + symbol;
productId = this.parseToInt(market['id']);
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'unWatchMyTrades', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'fill',
'subaccount': sender,
'product_id': productId,
};
return await this.unWatchPrivate(stream, messageHash, params);
}
/**
* @method
* @name nado#watchPositions
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/events
* @description watches information on user positions
* @param {string[]} [symbols] unified market symbols
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum number of position structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
*/
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
symbols = this.marketSymbols(symbols, undefined, false, true, true);
let messageHash = 'positions';
let productId = undefined;
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
const market = this.market(symbols[0]);
messageHash += ':' + market['symbol'];
productId = this.parseToInt(market['id']);
}
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'watchPositions', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'position_change',
'subaccount': sender,
'product_id': productId,
};
const positions = await this.watchPrivate('position_change', stream, messageHash, params);
if (this.newUpdates) {
return positions;
}
return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
}
/**
* @method
* @name nado#unWatchPositions
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/authentication
* @see https://docs.nado.xyz/developer-resources/api/subscriptions/streams
* @description unWatches information on user positions
* @param {string[]} [symbols] unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the exchange response
*/
async unWatchPositions(symbols = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
await this.authenticate(this.extend({}, params));
symbols = this.marketSymbols(symbols, undefined, false, true, true);
let messageHash = 'positions';
let productId = undefined;
if (symbols !== undefined) {
const symbolsLength = symbols.length;
if (symbolsLength === 1) {
const market = this.market(symbols[0]);
messageHash += ':' + market['symbol'];
productId = this.parseToInt(market['id']);
}
}
let subaccount = undefined;
[subaccount, params] = this.handleOptionAndParams(params, 'unWatchPositions', 'subaccount', 'default');
const sender = this.createSubaccount(this.walletAddress, subaccount);
const stream = {
'type': 'position_change',
'subaccount': sender,
'product_id': productId,
};
return await this.unWatchPrivate(stream, messageHash, params);
}
/**
* @method
* @name nado#createOrderWs
* @description create a trade order over the v2 gateway WebSocket
* @see https://docs.nado.xyz/developer-resources/api/gateway/websocket-v2
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/place-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string|int} [params.expiration] order expiration timestamp in seconds, defaults to 4294967295
* @param {string|int} [params.appendix] pre-encoded order appendix
* @param {boolean} [params.reduceOnly] true if the order should only reduce position
* @param {boolean} [params.postOnly] true to create a post-only order
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', or 'PO'
* @param {boolean} [params.spotLeverage] whether leverage should be used for spot, defaults to true, exchange-specific alias params.spot_leverage
* @param {int} [params.id] client-provided request id used to correlate the out-of-order v2 response, autogenerated when omitted
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
const market = this.market(symbol);
params = this.extend({ 'id': this.requestId() }, params);
const requestIdString = this.safeString(params, 'id');
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' ws execute requires params.id');
}
const request = await this.createOrderRequest(symbol, type, side, amount, price, params);
const placeOrder = this.safeDict(request, 'place_order', {});
if ('trigger' in placeOrder) {
throw new NotSupported(this.id + ' createOrderWs() does not support trigger orders, use createOrder() instead');
}
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' requires params.id');
}
const response = await this.watchExecuteRequest(requestIdString, request);
//
// {
// "status": "success",
// "signature": "0x...",
// "data": {
// "digest": "0x..."
// },
// "request_type": "execute_place_order",
// "id": 100
// }
//
return this.parseOrder(this.extend({ 'place_order': placeOrder }, response), market);
}
/**
* @method
* @name nado#editOrderWs
* @description edit a trade order over the v2 gateway WebSocket
* @see https://docs.nado.xyz/developer-resources/api/gateway/websocket-v2
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-and-place
* @param {string} id order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string|int} [params.expiration] order expiration timestamp in seconds, defaults to 4294967295
* @param {string|int} [params.appendix] pre-encoded order appendix
* @param {boolean} [params.reduceOnly] true if the order should only reduce position
* @param {boolean} [params.postOnly] true to create a post-only order
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', or 'PO'
* @param {boolean} [params.spotLeverage] whether leverage should be used for spot, defaults to true, exchange-specific alias params.spot_leverage
* @param {boolean} [params.placeRequiresUnfilled] when true, aborts the new order if the canceled order had partial fills or the cancel failed, exchange-specific alias params.place_requires_unfilled, defaults to true
* @param {int} [params.id] client-provided request id used to correlate the out-of-order v2 response, autogenerated when omitted
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
async editOrderWs(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
const market = this.market(symbol);
// for cancel_and_place the request id is echoed from the nested place_order object
params = this.extend({ 'id': this.requestId() }, params);
const requestIdString = this.safeString(params, 'id');
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' ws execute requires params.id');
}
const request = await this.editOrderRequest(id, symbol, type, side, amount, price, params);
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' requires params.id');
}
const response = await this.watchExecuteRequest(requestIdString, request);
//
// {
// "status": "success",
// "signature": "0x...",
// "data": {
// "digest": "0x..."
// },
// "request_type": "execute_cancel_and_place",
// "id": 100
// }
//
const cancelAndPlace = this.safeDict(request, 'cancel_and_place', {});
const placeOrder = this.safeDict(cancelAndPlace, 'place_order', {});
return this.parseOrder(this.extend({ 'place_order': placeOrder }, response), market);
}
/**
* @method
* @name nado#cancelOrderWs
* @description cancels an open order over the v2 gateway WebSocket
* @see https://docs.nado.xyz/developer-resources/api/gateway/websocket-v2
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-orders
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string} [params.requiredUnfilledAmount] cancel only if the order's absolute remaining unfilled amount matches this amount, exchange-specific raw x18 alias params.required_unfilled_amount
* @param {int} [params.id] client-provided request id used to correlate the out-of-order v2 response, autogenerated when omitted
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
async cancelOrderWs(id, symbol = undefined, params = {}) {
const orders = await this.cancelOrdersWs([id], symbol, params);
return this.safeDict(orders, 0);
}
/**
* @method
* @name nado#cancelOrdersWs
* @description cancel multiple orders over the v2 gateway WebSocket
* @see https://docs.nado.xyz/developer-resources/api/gateway/websocket-v2
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-orders
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string} [params.requiredUnfilledAmount] cancel only if the order's absolute remaining unfilled amount matches this amount, exchange-specific raw x18 alias params.required_unfilled_amount
* @param {int} [params.id] client-provided request id used to correlate the out-of-order v2 response, autogenerated when omitted
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
async cancelOrdersWs(ids, symbol = undefined, params = {}) {
this.checkRequiredCredentials();
if (symbol === undefined) {
throw new ArgumentsRequired(this.id + ' cancelOrdersWs() requires a symbol argument');
}
await this.loadMarkets();
const market = this.market(symbol);
const trigger = this.safeBool2(params, 'stop', 'trigger');
if (trigger) {
throw new NotSupported(this.id + ' cancelOrdersWs() does not support trigger orders, use cancelOrders() instead');
}
params = this.extend({ 'id': this.requestId() }, params);
const requestIdString = this.safeString(params, 'id');
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' ws execute requires params.id');
}
const request = await this.cancelOrdersRequest(ids, symbol, params);
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' requires params.id');
}
const response = await this.watchExecuteRequest(requestIdString, request);
//
// {
// "status": "success",
// "signature": "0x...",
// "data": {
// "cancelled_orders": []
// },
// "request_type": "execute_cancel_orders",
// "id": 100
// }
//
const data = this.safeDict(response, 'data', {});
const cancelledOrders = this.safeList(data, 'cancelled_orders', []);
const result = [];
for (let i = 0; i < cancelledOrders.length; i++) {
result.push(this.parseOrder(this.extend({ 'status': 'canceled' }, cancelledOrders[i]), market));
}
return result;
}
/**
* @method
* @name nado#cancelAllOrdersWs
* @description cancel all open orders over the v2 gateway WebSocket
* @see https://docs.nado.xyz/developer-resources/api/gateway/websocket-v2
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-product-orders
* @param {string} [symbol] unified market symbol, when undefined all orders for all products are canceled
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.id] client-provided request id used to correlate the out-of-order v2 response, autogenerated when omitted
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
async cancelAllOrdersWs(symbol = undefined, params = {}) {
this.checkRequiredCredentials();
await this.loadMarkets();
let market = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
}
const trigger = this.safeBool2(params, 'stop', 'trigger');
if (trigger) {
throw new NotSupported(this.id + ' cancelAllOrdersWs() does not support trigger orders, use cancelAllOrders() instead');
}
params = this.extend({ 'id': this.requestId() }, params);
const requestIdString = this.safeString(params, 'id');
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' ws execute requires params.id');
}
const request = await this.cancelAllOrdersRequest(symbol, params);
if (requestIdString === undefined) {
throw new ArgumentsRequired(this.id + ' requires params.id');
}
const response = await this.watchExecuteRequest(requestIdString, request);
const data = this.safeDict(response, 'data', {});
const cancelledOrders = this.safeList(data, 'cancelled_orders', []);
const result = [];
for (let i = 0; i < cancelledOrders.length; i++) {
result.push(this.parseOrder(this.extend({ 'status': 'canceled' }, cancelledOrders[i]), market));
}
return result;
}
async watchExecuteRequest(requestIdString, request) {
// the v2 gateway dispatches requests concurrently, so responses arrive
// in completion order, not send order — every execute carries a unique
// request id and its response is correlated by the echoed i