GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #4956 from GimmerBot/master · electic/ccxt@7dbb11b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • js
    • mercado.js
  • keys.json
  • php
    • mercado.php
  • python/ccxt
    • async_support
      • mercado.py
    • mercado.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎js/mercado.js‎

Copy file name to clipboardExpand all lines: js/mercado.js
+144-43Lines changed: 144 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ---------------------------------------------------------------------------
44

55
const Exchange = require ('./base/Exchange');
6-
const { ExchangeError, ArgumentsRequired } = require ('./base/errors');
6+
const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors');
77

88
// ---------------------------------------------------------------------------
99

@@ -17,15 +17,33 @@ module.exports = class mercado extends Exchange {
1717
'version': 'v3',
1818
'has': {
1919
'CORS': true,
20-
'createMarketOrder': false,
20+
'createMarketOrder': true,
2121
'fetchOrder': true,
2222
'withdraw': true,
23+
'fetchOHLCV': true,
24+
'fetchOrders': true,
25+
'fetchOpenOrders': true,
26+
'fetchTicker': true,
27+
'fetchTickers': false,
28+
},
29+
'timeframes': {
30+
'5m': '5m',
31+
'15m': '15m',
32+
'30m': '30m',
33+
'1h': '1h',
34+
'6h': '6h',
35+
'12h': '12h',
36+
'1d': '1d',
37+
'3d': '3d',
38+
'1w': '1w',
39+
'2w': '2w',
2340
},
2441
'urls': {
2542
'logo': 'https://user-images.githubusercontent.com/1294454/27837060-e7c58714-60ea-11e7-9192-f05e86adb83f.jpg',
2643
'api': {
2744
'public': 'https://www.mercadobitcoin.net/api',
2845
'private': 'https://www.mercadobitcoin.net/tapi',
46+
'v4Public': 'https://www.mercadobitcoin.com.br/v4',
2947
},
3048
'www': 'https://www.mercadobitcoin.com.br',
3149
'doc': [
@@ -55,16 +73,23 @@ module.exports = class mercado extends Exchange {
5573
'list_orderbook',
5674
'place_buy_order',
5775
'place_sell_order',
76+
'place_market_buy_order',
77+
'place_market_sell_order',
5878
'withdraw_coin',
5979
],
6080
},
81+
'v4Public': {
82+
'get': [
83+
'{coin}/candle/',
84+
],
85+
},
6186
},
6287
'markets': {
63-
'BTC/BRL': { 'id': 'BRLBTC', 'symbol': 'BTC/BRL', 'base': 'BTC', 'quote': 'BRL', 'suffix': 'Bitcoin' },
64-
'LTC/BRL': { 'id': 'BRLLTC', 'symbol': 'LTC/BRL', 'base': 'LTC', 'quote': 'BRL', 'suffix': 'Litecoin' },
65-
'BCH/BRL': { 'id': 'BRLBCH', 'symbol': 'BCH/BRL', 'base': 'BCH', 'quote': 'BRL', 'suffix': 'BCash' },
66-
'XRP/BRL': { 'id': 'BRLXRP', 'symbol': 'XRP/BRL', 'base': 'XRP', 'quote': 'BRL', 'suffix': 'Ripple' },
67-
'ETH/BRL': { 'id': 'BRLETH', 'symbol': 'ETH/BRL', 'base': 'ETH', 'quote': 'BRL', 'suffix': 'Ethereum' },
88+
'BTC/BRL': { 'id': 'BRLBTC', 'symbol': 'BTC/BRL', 'base': 'BTC', 'quote': 'BRL', 'precision': { 'amount': 8, 'price': 5 }, 'suffix': 'Bitcoin' },
89+
'LTC/BRL': { 'id': 'BRLLTC', 'symbol': 'LTC/BRL', 'base': 'LTC', 'quote': 'BRL', 'precision': { 'amount': 8, 'price': 5 }, 'suffix': 'Litecoin' },
90+
'BCH/BRL': { 'id': 'BRLBCH', 'symbol': 'BCH/BRL', 'base': 'BCH', 'quote': 'BRL', 'precision': { 'amount': 8, 'price': 5 }, 'suffix': 'BCash' },
91+
'XRP/BRL': { 'id': 'BRLXRP', 'symbol': 'XRP/BRL', 'base': 'XRP', 'quote': 'BRL', 'precision': { 'amount': 8, 'price': 5 }, 'suffix': 'Ripple' },
92+
'ETH/BRL': { 'id': 'BRLETH', 'symbol': 'ETH/BRL', 'base': 'ETH', 'quote': 'BRL', 'precision': { 'amount': 8, 'price': 5 }, 'suffix': 'Ethereum' },
6893
},
6994
'fees': {
7095
'trading': {
@@ -168,48 +193,70 @@ module.exports = class mercado extends Exchange {
168193
}
169194

170195
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
171-
if (type === 'market')
172-
throw new ExchangeError (this.id + ' allows limit orders only');
173-
let method = 'privatePostPlace' + this.capitalize (side) + 'Order';
174-
let order = {
196+
const request = {
175197
'coin_pair': this.marketId (symbol),
176-
'quantity': amount,
177-
'limit_price': price,
178198
};
179-
let response = await this[method] (this.extend (order, params));
199+
let method = this.capitalize (side) + 'Order';
200+
if (type === 'limit') {
201+
method = 'privatePostPlace' + method;
202+
request['limit_price'] = this.priceToPrecision (symbol, price);
203+
request['quantity'] = this.amountToPrecision (symbol, amount);
204+
} else {
205+
method = 'privatePostPlaceMarket' + method;
206+
if (side === 'buy') {
207+
if (price === undefined) {
208+
throw new InvalidOrder (this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount');
209+
}
210+
request['cost'] = this.priceToPrecision (symbol, amount * price);
211+
} else {
212+
request['quantity'] = this.amountToPrecision (symbol, amount);
213+
}
214+
}
215+
const response = await this[method] (this.extend (request, params));
216+
// TODO: replace this with a call to parseOrder for unification
180217
return {
181218
'info': response,
182219
'id': response['response_data']['order']['order_id'].toString (),
183220
};
184221
}
185222

186223
async cancelOrder (id, symbol = undefined, params = {}) {
187-
if (symbol === undefined)
188-
throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
224+
if (symbol === undefined) {
225+
throw new ArgumentsRequired (this.id + ' cancelOrder () requires a symbol argument');
226+
}
189227
await this.loadMarkets ();
190-
let market = this.market (symbol);
191-
let response = await this.privatePostCancelOrder (this.extend ({
228+
const market = this.market (symbol);
229+
const request = {
192230
'coin_pair': market['id'],
193231
'order_id': id,
194-
}, params));
232+
};
233+
const response = await this.privatePostCancelOrder (this.extend (request, params));
195234
//
196-
// { response_data: { order: { order_id: 2176769,
197-
// coin_pair: "BRLBCH",
198-
// order_type: 2,
199-
// status: 3,
200-
// has_fills: false,
201-
// quantity: "0.10000000",
202-
// limit_price: "1996.15999",
203-
// executed_quantity: "0.00000000",
204-
// executed_price_avg: "0.00000",
205-
// fee: "0.00000000",
206-
// created_timestamp: "1536956488",
207-
// updated_timestamp: "1536956499",
208-
// operations: [] } },
209-
// status_code: 100,
210-
// server_unix_timestamp: "1536956499" }
235+
// {
236+
// response_data: {
237+
// order: {
238+
// order_id: 2176769,
239+
// coin_pair: 'BRLBCH',
240+
// order_type: 2,
241+
// status: 3,
242+
// has_fills: false,
243+
// quantity: '0.10000000',
244+
// limit_price: '1996.15999',
245+
// executed_quantity: '0.00000000',
246+
// executed_price_avg: '0.00000',
247+
// fee: '0.00000000',
248+
// created_timestamp: '1536956488',
249+
// updated_timestamp: '1536956499',
250+
// operations: []
251+
// }
252+
// },
253+
// status_code: 100,
254+
// server_unix_timestamp: '1536956499'
255+
// }
211256
//
212-
return this.parseOrder (response['response_data']['order'], market);
257+
const responseData = this.safeValue (response, 'response_data', {});
258+
const order = this.safeValue (responseData, 'order', {});
259+
return this.parseOrder (order, market);
213260
}
214261

215262
parseOrderStatus (status) {
@@ -302,16 +349,19 @@ module.exports = class mercado extends Exchange {
302349
}
303350

304351
async fetchOrder (id, symbol = undefined, params = {}) {
305-
if (symbol === undefined)
306-
throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
352+
if (symbol === undefined) {
353+
throw new ArgumentsRequired (this.id + ' fetchOrder () requires a symbol argument');
354+
}
307355
await this.loadMarkets ();
308-
let market = this.market (symbol);
309-
let response = undefined;
310-
response = await this.privatePostGetOrder (this.extend ({
356+
const market = this.market (symbol);
357+
const request = {
311358
'coin_pair': market['id'],
312359
'order_id': parseInt (id),
313-
}, params));
314-
return this.parseOrder (response['response_data']['order']);
360+
};
361+
const response = await this.privatePostGetOrder (this.extend (request, params));
362+
const responseData = this.safeValue (response, 'response_data', {});
363+
const order = this.safeValue (responseData, 'order');
364+
return this.parseOrder (order, market);
315365
}
316366

317367
async withdraw (code, amount, address, tag = undefined, params = {}) {
@@ -350,10 +400,61 @@ module.exports = class mercado extends Exchange {
350400
};
351401
}
352402

403+
parseOHLCV (ohlcv, market = undefined, timeframe = '1m', since = undefined, limit = undefined) {
404+
let timestamp = this.safeInteger (ohlcv, 'timestamp');
405+
if (timestamp !== undefined) {
406+
timestamp = timestamp * 1000;
407+
}
408+
return [
409+
timestamp,
410+
this.safeFloat (ohlcv, 'open'),
411+
this.safeFloat (ohlcv, 'high'),
412+
this.safeFloat (ohlcv, 'low'),
413+
this.safeFloat (ohlcv, 'close'),
414+
this.safeFloat (ohlcv, 'volume'),
415+
];
416+
}
417+
418+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
419+
await this.loadMarkets ();
420+
let market = this.market (symbol);
421+
let request = {
422+
'precision': this.timeframes[timeframe],
423+
'coin': market.id.toLowerCase (),
424+
};
425+
if (limit !== undefined && since !== undefined) {
426+
request['from'] = parseInt (since / 1000);
427+
request['to'] = this.sum (request['from'], limit * this.parseTimeframe (timeframe));
428+
} else if (since !== undefined) {
429+
request['from'] = parseInt (since / 1000);
430+
request['to'] = this.sum (this.seconds (), 1);
431+
} else if (limit !== undefined) {
432+
request['to'] = this.seconds ();
433+
request['from'] = request['to'] - (limit * this.parseTimeframe (timeframe));
434+
}
435+
let response = await this.v4PublicGetCoinCandle (this.extend (request, params));
436+
return this.parseOHLCVs (response['candles'], market, timeframe, since, limit);
437+
}
438+
439+
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
440+
if (symbol === undefined) {
441+
throw new ArgumentsRequired (this.id + ' fetchOrders () requires a symbol argument');
442+
}
443+
await this.loadMarkets ();
444+
const market = this.market (symbol);
445+
const request = {
446+
'coin_pair': market['base'],
447+
};
448+
const response = await this.privatePostListOrders (this.extend (request, params));
449+
const responseData = this.safeValue (response, 'response_data', {});
450+
const orders = this.safeValue (responseData, 'orders', []);
451+
return this.parseOrders (orders, market, since, limit);
452+
}
453+
353454
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
354455
let url = this.urls['api'][api] + '/';
355456
let query = this.omit (params, this.extractParams (path));
356-
if (api === 'public') {
457+
if (api === 'public' || (api === 'v4Public')) {
357458
url += this.implodeParams (path, params);
358459
if (Object.keys (query).length)
359460
url += '?' + this.urlencode (query);
Collapse file

‎keys.json‎

Copy file name to clipboardExpand all lines: keys.json
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"lbank": { "skip": true },
6363
"livecoin": { "skip": true },
6464
"luno": { "skip": true },
65-
"mercado": { "skip": true },
6665
"nova": { "skip": true },
6766
"okcoincny": { "skip": true },
6867
"okcoinusd": { "skip": true },

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.