Skip to content

Commit

Permalink
Merge pull request #16059 from sc0Vu/add-woo-edit-order
Browse files Browse the repository at this point in the history
woo: add edit order
  • Loading branch information
kroitor committed Jan 4, 2023
2 parents abfc243 + f9d575c commit f31b93d
Showing 1 changed file with 66 additions and 14 deletions.
80 changes: 66 additions & 14 deletions js/woo.js
Expand Up @@ -200,6 +200,12 @@ module.exports = class woo extends Exchange {
'post': {
'algo/order': 5,
},
'put': {
'order/{oid}': 2,
'order/client/{oid}': 2,
'algo/order/{oid}': 2,
'algo/order/client/{oid}': 2,
},
'delete': {
'algo/order/{oid}': 1,
'algo/orders/pending': 1,
Expand Down Expand Up @@ -773,6 +779,50 @@ module.exports = class woo extends Exchange {
);
}

async editOrder (id, symbol, type, side, amount, price = undefined, params = {}) {
/**
* @method
* @name woo#editOrder
* @description edit a trade order
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or '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|undefined} price the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
* @param {object} params extra parameters specific to the woo api endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'oid': id,
// 'quantity': this.amountToPrecision (symbol, amount),
// 'price': this.priceToPrecision (symbol, price),
};
if (price !== undefined) {
request['price'] = this.priceToPrecision (symbol, price);
}
if (amount !== undefined) {
request['quantity'] = this.amountToPrecision (symbol, amount);
}
const response = await this.v3PrivatePutOrderOid (this.extend (request, params));
//
// {
// "code": 0,
// "data": {
// "status": "string",
// "success": true
// },
// "message": "string",
// "success": true,
// "timestamp": 0
// }
//
const data = this.safeValue (response, 'data', {});
return this.parseOrder (data, market);
}

async cancelOrder (id, symbol = undefined, params = {}) {
/**
* @method
Expand Down Expand Up @@ -1790,39 +1840,41 @@ module.exports = class woo extends Exchange {
sign (path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
const version = section[0];
const access = section[1];
const pathWithParams = this.implodeParams (path, params);
let url = this.implodeHostname (this.urls['api'][access]);
url += '/' + version + '/';
path = this.implodeParams (path, params);
params = this.omit (params, this.extractParams (path));
params = this.keysort (params);
if (access === 'public') {
url += access + '/' + path;
url += access + '/' + pathWithParams;
if (Object.keys (params).length) {
url += '?' + this.urlencode (params);
}
} else {
this.checkRequiredCredentials ();
url += path;
let auth = '';
const ts = this.nonce ().toString ();
let auth = this.urlencode (params);
if (version === 'v3' && (method === 'POST')) {
url += pathWithParams;
headers = {
'x-api-key': this.apiKey,
'x-api-timestamp': ts,
};
if (version === 'v3' && (method === 'POST' || method === 'PUT' || method === 'DELETE')) {
auth = this.json (params);
body = auth;
auth = ts + method + '/' + version + '/' + path + body;
auth = ts + method + '/' + version + '/' + pathWithParams + body;
headers['content-type'] = 'application/json';
} else {
if (method === 'POST' || method === 'DELETE') {
auth = this.urlencode (params);
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
body = auth;
} else {
url += '?' + auth;
}
auth += '|' + ts;
headers['content-type'] = 'application/x-www-form-urlencoded';
}
const signature = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256');
headers = {
'x-api-key': this.apiKey,
'x-api-signature': signature,
'x-api-timestamp': ts,
'Content-Type': 'application/x-www-form-urlencoded',
};
headers['x-api-signature'] = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256');
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
Expand Down

0 comments on commit f31b93d

Please sign in to comment.