Snapshots

This commit is contained in:
Luis Fernando Molina committed 2020-05-10 14:17:33 +02:00
1 parent e91125801d
commit 6368221937
75 files changed
+8943 -4332

No files matched your search

+106 -34
View File
@@ -3,7 +3,7 @@
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, InvalidAddress, RateLimitExceeded, PermissionDenied } = require ('./base/errors');
const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, InvalidAddress, RateLimitExceeded, PermissionDenied, NotSupported } = require ('./base/errors');
const { ROUND, TRUNCATE } = require ('./base/functions/number');
// ---------------------------------------------------------------------------
@@ -37,6 +37,7 @@ module.exports = class binance extends Exchange {
'fetchTransactions': false,
'fetchTradingFee': true,
'fetchTradingFees': true,
'cancelAllOrders': true,
},
'timeframes': {
'1m': '1m',
@@ -57,6 +58,10 @@ module.exports = class binance extends Exchange {
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/29604020-d5483cdc-87ee-11e7-94c7-d1a8d9169293.jpg',
'test': {
'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1',
'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1',
},
'api': {
'web': 'https://www.binance.com',
'wapi': 'https://api.binance.com/wapi/v3',
@@ -130,6 +135,8 @@ module.exports = class binance extends Exchange {
'lending/union/purchaseRecord',
'lending/union/redemptionRecord',
'lending/union/interestHistory',
'lending/project/list',
'lending/project/position/list',
],
'post': [
'asset/dust',
@@ -146,6 +153,7 @@ module.exports = class binance extends Exchange {
'userDataStream',
'futures/transfer',
// lending
'lending/customizedFixed/purchase',
'lending/daily/purchase',
'lending/daily/redeem',
],
@@ -211,6 +219,8 @@ module.exports = class binance extends Exchange {
'income',
],
'post': [
'batchOrders',
'positionSide/dual',
'positionMargin',
'marginType',
'order',
@@ -221,6 +231,7 @@ module.exports = class binance extends Exchange {
'listenKey',
],
'delete': [
'batchOrders',
'order',
'allOpenOrders',
'listenKey',
@@ -267,6 +278,7 @@ module.exports = class binance extends Exchange {
'order/test',
],
'delete': [
'openOrders', // added on 2020-04-25 for canceling all open orders per symbol
'orderList', // oco
'order',
],
@@ -289,7 +301,6 @@ module.exports = class binance extends Exchange {
'fetchTradesMethod': 'publicGetAggTrades', // publicGetTrades, publicGetHistoricalTrades
'fetchTickersMethod': 'publicGetTicker24hr',
'defaultTimeInForce': 'GTC', // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
'defaultLimitOrderType': 'limit', // or 'limit_maker'
'defaultType': 'spot', // 'spot', 'future'
'hasAlreadyAuthenticatedSuccessfully': false,
'warnOnFetchOpenOrdersWithoutSymbol': true,
@@ -326,6 +337,32 @@ module.exports = class binance extends Exchange {
});
}
setSandboxMode (enabled) {
if (enabled) { // eslint-disable-line no-extra-boolean-cast
if ('test' in this.urls) {
const type = this.safeString (this.options, 'defaultType', 'spot');
if (type !== 'future') {
throw new NotSupported (this.id + ' does not have a sandbox URL for ' + type + " markets, set exchange.options['defaultType'] = 'future' or don't use the sandbox for " + this.id);
}
if (typeof this.urls['api'] === 'string') {
this.urls['api_backup'] = this.urls['api'];
this.urls['api'] = this.urls['test'];
} else {
this.urls['api_backup'] = this.extend ({}, this.urls['api']);
this.urls['api'] = this.extend ({}, this.urls['test']);
}
} else {
throw new NotSupported (this.id + ' does not have a sandbox URL');
}
} else if ('api_backup' in this.urls) {
if (typeof this.urls['api'] === 'string') {
this.urls['api'] = this.urls['api_backup'];
} else {
this.urls['api'] = this.extend ({}, this.urls['api_backup']);
}
}
}
nonce () {
return this.milliseconds () - this.options['timeDifference'];
}
@@ -476,7 +513,7 @@ module.exports = class binance extends Exchange {
'max': undefined,
},
'cost': {
'min': -1 * Math.log10 (precision['amount']),
'min': undefined,
'max': undefined,
},
},
@@ -720,7 +757,7 @@ module.exports = class binance extends Exchange {
async fetchBidsAsks (symbols = undefined, params = {}) {
await this.loadMarkets ();
const defaultType = this.safeString2 (this.options, 'fetchOpenOrders', 'defaultType', 'spot');
const defaultType = this.safeString2 (this.options, 'fetchBidsAsks', 'defaultType', 'spot');
const type = this.safeString (params, 'type', defaultType);
const query = this.omit (params, 'type');
const method = (type === 'spot') ? 'publicGetTickerBookTicker' : 'fapiPublicGetTickerBookTicker';
@@ -737,12 +774,12 @@ module.exports = class binance extends Exchange {
parseOHLCV (ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) {
return [
ohlcv[0],
parseFloat (ohlcv[1]),
parseFloat (ohlcv[2]),
parseFloat (ohlcv[3]),
parseFloat (ohlcv[4]),
parseFloat (ohlcv[5]),
this.safeInteger (ohlcv, 0),
this.safeFloat (ohlcv, 1),
this.safeFloat (ohlcv, 2),
this.safeFloat (ohlcv, 3),
this.safeFloat (ohlcv, 4),
this.safeFloat (ohlcv, 5),
];
}
@@ -870,6 +907,10 @@ module.exports = class binance extends Exchange {
if (market !== undefined) {
symbol = market['symbol'];
}
let cost = undefined;
if ((price !== undefined) && (amount !== undefined)) {
cost = price * amount;
}
return {
'info': trade,
'timestamp': timestamp,
@@ -878,11 +919,11 @@ module.exports = class binance extends Exchange {
'id': id,
'order': orderId,
'type': undefined,
'takerOrMaker': takerOrMaker,
'side': side,
'takerOrMaker': takerOrMaker,
'price': price,
'amount': amount,
'cost': price * amount,
'cost': cost,
'fee': fee,
};
}
@@ -1180,6 +1221,8 @@ module.exports = class binance extends Exchange {
} else if (uppercaseType === 'STOP') {
stopPriceIsRequired = true;
priceIsRequired = true;
} else if (uppercaseType === 'STOP_MARKET') {
stopPriceIsRequired = true;
}
if (priceIsRequired) {
if (price === undefined) {
@@ -1339,6 +1382,27 @@ module.exports = class binance extends Exchange {
return this.parseOrder (response);
}
async cancelAllOrders (symbol = undefined, params = {}) {
if (symbol === undefined) {
throw new ArgumentsRequired (this.id + ' cancelAllOrders requires a symbol argument');
}
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'symbol': market['id'],
};
const defaultType = this.safeString2 (this.options, 'cancelAllOrders', 'defaultType', 'spot');
const type = this.safeString (params, 'type', defaultType);
const query = this.omit (params, 'type');
const method = (type === 'spot') ? 'privateDeleteOpenOrders' : 'fapiPrivateDeleteAllOpenOrders';
const response = await this[method] (this.extend (request, query));
if (Array.isArray (response)) {
return this.parseOrders (response, market);
} else {
return response;
}
}
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
if (symbol === undefined) {
throw new ArgumentsRequired (this.id + ' fetchMyTrades requires a symbol argument');
@@ -1571,10 +1635,7 @@ module.exports = class binance extends Exchange {
}
parseTransactionStatusByType (status, type = undefined) {
if (type === undefined) {
return status;
}
const statuses = {
const statusesByType = {
'deposit': {
'0': 'pending',
'1': 'ok',
@@ -1589,32 +1650,38 @@ module.exports = class binance extends Exchange {
'6': 'ok', // Completed
},
};
return (status in statuses[type]) ? statuses[type][status] : status;
const statuses = this.safeValue (statusesByType, type, {});
return this.safeString (statuses, status, status);
}
parseTransaction (transaction, currency = undefined) {
//
// fetchDeposits
// { insertTime: 1517425007000,
// amount: 0.3,
// address: "0x0123456789abcdef",
// addressTag: "",
// txId: "0x0123456789abcdef",
// asset: "ETH",
// status: 1 }
//
// {
// insertTime: 1517425007000,
// amount: 0.3,
// address: "0x0123456789abcdef",
// addressTag: "",
// txId: "0x0123456789abcdef",
// asset: "ETH",
// status: 1
// }
//
// fetchWithdrawals
//
// { amount: 14,
// address: "0x0123456789abcdef...",
// {
// amount: 14,
// address: "0x0123456789abcdef...",
// successTime: 1514489710000,
// transactionFee: 0.01,
// addressTag: "",
// txId: "0x0123456789abcdef...",
// id: "0123456789abcdef...",
// asset: "ETH",
// applyTime: 1514488724000,
// status: 6 }
// transactionFee: 0.01,
// addressTag: "",
// txId: "0x0123456789abcdef...",
// id: "0123456789abcdef...",
// asset: "ETH",
// applyTime: 1514488724000,
// status: 6
// }
//
const id = this.safeString (transaction, 'id');
const address = this.safeString (transaction, 'address');
@@ -1624,7 +1691,7 @@ module.exports = class binance extends Exchange {
tag = undefined;
}
}
const txid = this.safeValue (transaction, 'txId');
const txid = this.safeString (transaction, 'txId');
const currencyId = this.safeString (transaction, 'asset');
const code = this.safeCurrencyCode (currencyId, currency);
let timestamp = undefined;
@@ -1854,6 +1921,11 @@ module.exports = class binance extends Exchange {
'timestamp': this.nonce (),
'recvWindow': this.options['recvWindow'],
}, params));
} else if (path === 'batchOrders') {
query = this.rawencode (this.extend ({
'timestamp': this.nonce (),
'recvWindow': this.options['recvWindow'],
}, params));
} else {
query = this.urlencode (this.extend ({
'timestamp': this.nonce (),