[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchOpenOrder not work for stopLoss order #24377

Open
xuyangcn opened this issue Nov 26, 2024 · 31 comments
Open

fetchOpenOrder not work for stopLoss order #24377

xuyangcn opened this issue Nov 26, 2024 · 31 comments
Assignees

Comments

@xuyangcn
Copy link

Operating System

Ubuntu

Programming Languages

JavaScript

CCXT Version

4.4.33

Description

I create stopLoss order, but could not fetch the open orders

Code

 const orders = await exchangeClient.fetchOpenOrders(symbol= symbol,since=0,limit=20, params = { ordType: 'conditional', })  
 const orders = await exchangeClient.fetchOpenOrders(symbol= symbol,since=0,limit=20, params = { stop: true, })  
 const orders = await exchangeClient.fetchOpenOrders(symbol= symbol,since=0,limit=20, params = { stop: true, ordType: 'conditional', })  

@carlosmiei carlosmiei self-assigned this Nov 26, 2024
@carlosmiei
Copy link
Collaborator

Hello @xuyangcn,

What's the exchange being used?

@xuyangcn
Copy link
Author

okx

@xuyangcn
Copy link
Author

in okx.js , I can see response have order information, but after parseOrders, the ret is empty

const data = this.safeList(response, 'data', []);

const ret = this.parseOrders(data, market, since, limit, params);
console.log("ret", ret);

@carlosmiei
Copy link
Collaborator

@xuyangcn Can you please post a verbose log?

you can do

await exchange.loadMarkets()
exchange.verbose = true
// call fethcOpenOrders here

that will print the verbose request that you can post here

@xuyangcn
Copy link
Author
xuyangcn commented Nov 26, 2024

fetch Request:
okx GET https://www.okx.com/api/v5/trade/orders-algo-pending?instId=BLUR-USDT&limit=20&ordType=conditional
RequestHeaders:
RequestBody:
undefined

handleRestResponse:
okx GET https://www.okx.com/api/v5/trade/orders-algo-pending?instId=BLUR-USDT&limit=20&ordType=conditional 200 OK
ResponseHeaders:
{
'B-Locale': 'en_US',
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
'Cf-Cache-Status': 'DYNAMIC',
'Cf-Ray': '8e895ce18a530c4d-MRS',
Connection: 'keep-alive',
'Content-Encoding': 'gzip',
'Content-Type': 'application/json',
Date: 'Tue, 26 Nov 2024 10:58:21 GMT',
Expires: '0',
'Ok-After': '2016828546853150721',
'Ok-Before': '2016839820202778624',
Pragma: 'no-cache',
Server: 'cloudflare',
'Set-Cookie': 'locale=en-US; Max-Age=604800; Expires=Tue, 03-Dec-2024 10:58:21 GMT; Path=/, __cf_bm=RAyWBzAKakf5PCPSzfMkNyUCIBQuBGu1nWMeZ2IoOXs-1732618701-1.0.1.1-7pLeroKQ6PpouPIPdeGtyZPaQY1YAkOso6xS.s9fKh53BFv4p7TyLxcDcvL0NdFiHusY12nTaw54bCpiscM2pg; path=/; expires=Tue, 26-Nov-24 11:28:21 GMT; domain=.okx.com; HttpOnly; Secure; SameSite=None',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Transfer-Encoding': 'chunked',
Vary: 'Accept-Encoding, Origin',
'X-Brokerid': '0',
'X-Content-Type-Options': 'nosniff, nosniff',
'X-Frame-Options': 'SAMEORIGIN, DENY',
'X-Xss-Protection': '1; mode=block, 1; mode=block'
}
ResponseBody:
{"code":"0","data":[{"activePx":"","actualPx":"","actualSide":"","actualSz":"0","algoClOrdId":"e847386590ce4dBCea047aae8474a2c6","algoId":"2016839820202778624","amendPxOnTriggerType":"0","attachAlgoOrds":[],"cTime":"1732608910526","callbackRatio":"","callbackSpread":"","ccy":"","chaseType":"","chaseVal":"","clOrdId":"e847386590ce4dBCea047aae8474a2c6","closeFraction":"","failCode":"0","instId":"BLUR-USDT","instType":"SPOT","isTradeBorrowMode":"","last":"0.3173","lever":"","linkedOrd":{"ordId":""},"maxChaseType":"","maxChaseVal":"","moveTriggerPx":"","ordId":"","ordIdList":[],"ordPx":"","ordType":"conditional","posSide":"net","pxLimit":"","pxSpread":"","pxVar":"","quickMgnType":"","reduceOnly":"false","side":"buy","slOrdPx":"0.45","slTriggerPx":"0.4","slTriggerPxType":"last","state":"live","sz":"20","szLimit":"","tag":"e847386590ce4dBC","tdMode":"cash","tgtCcy":"","timeInterval":"","tpOrdPx":"","tpTriggerPx":"","tpTriggerPxType":"","triggerPx":"","triggerPxType":"","triggerTime":"","uTime":"1732608910526"},{"activePx":"","actualPx":"","actualSide":"","actualSz":"0","algoClOrdId":"e847386590ce4dBCa0a06a0094978729","algoId":"2016836406609747968","amendPxOnTriggerType":"0","attachAlgoOrds":[],"cTime":"1732608808793","callbackRatio":"","callbackSpread":"","ccy":"","chaseType":"","chaseVal":"","clOrdId":"e847386590ce4dBCa0a06a0094978729","closeFraction":"","failCode":"0","instId":"BLUR-USDT","instType":"SPOT","isTradeBorrowMode":"","last":"0.318","lever":"","linkedOrd":{"ordId":""},"maxChaseType":"","maxChaseVal":"","moveTriggerPx":"","ordId":"","ordIdList":[],"ordPx":"","ordType":"conditional","posSide":"net","pxLimit":"","pxSpread":"","pxVar":"","quickMgnType":"","reduceOnly":"false","side":"buy","slOrdPx":"0.45","slTriggerPx":"0.4","slTriggerPxType":"last","state":"live","sz":"20","szLimit":"","tag":"e847386590ce4dBC","tdMode":"cash","tgtCcy":"","timeInterval":"","tpOrdPx":"","tpTriggerPx":"","tpTriggerPxType":"","triggerPx":"","triggerPxType":"","triggerTime":"","uTime":"1732608808793"},{"activePx":"","actualPx":"","actualSide":"","actualSz":"0","algoClOrdId":"e847386590ce4dBC574c961d74ab8257","algoId":"2016833615753420800","amendPxOnTriggerType":"0","attachAlgoOrds":[],"cTime":"1732608725619","callbackRatio":"","callbackSpread":"","ccy":"","chaseType":"","chaseVal":"","clOrdId":"e847386590ce4dBC574c961d74ab8257","closeFraction":"","failCode":"0","instId":"BLUR-USDT","instType":"SPOT","isTradeBorrowMode":"","last":"0.3177","lever":"","linkedOrd":{"ordId":""},"maxChaseType":"","maxChaseVal":"","moveTriggerPx":"","ordId":"","ordIdList":[],"ordPx":"","ordType":"conditional","posSide":"net","pxLimit":"","pxSpread":"","pxVar":"","quickMgnType":"","reduceOnly":"false","side":"buy","slOrdPx":"0.45","slTriggerPx":"0.4","slTriggerPxType":"last","state":"live","sz":"20","szLimit":"","tag":"e847386590ce4dBC","tdMode":"cash","tgtCcy":"","timeInterval":"","tpOrdPx":"","tpTriggerPx":"","tpTriggerPxType":"","triggerPx":"","triggerPxType":"","triggerTime":"","uTime":"1732608725619"},{"activePx":"","actualPx":"","actualSide":"","actualSz":"0","algoClOrdId":"e847386590ce4dBC2ba170c9840991cc","algoId":"2016828546853150721","amendPxOnTriggerType":"0","attachAlgoOrds":[],"cTime":"1732608574554","callbackRatio":"","callbackSpread":"","ccy":"","chaseType":"","chaseVal":"","clOrdId":"e847386590ce4dBC2ba170c9840991cc","closeFraction":"","failCode":"0","instId":"BLUR-USDT","instType":"SPOT","isTradeBorrowMode":"","last":"0.3197","lever":"","linkedOrd":{"ordId":""},"maxChaseType":"","maxChaseVal":"","moveTriggerPx":"","ordId":"","ordIdList":[],"ordPx":"","ordType":"conditional","posSide":"net","pxLimit":"","pxSpread":"","pxVar":"","quickMgnType":"","reduceOnly":"false","side":"buy","slOrdPx":"0.45","slTriggerPx":"0.4","slTriggerPxType":"last","state":"live","sz":"20","szLimit":"","tag":"e847386590ce4dBC","tdMode":"cash","tgtCcy":"","timeInterval":"","tpOrdPx":"","tpTriggerPx":"","tpTriggerPxType":"","triggerPx":"","triggerPxType":"","triggerTime":"","uTime":"1732608574554"}],"msg":""}

@carlosmiei
Copy link
Collaborator

@xuyangcn The output seems ok, which symbol are you providing?

@xuyangcn
Copy link
Author

BLURUSDT

@carlosmiei
Copy link
Collaborator

@xuyangcn That format is incorrect, it should be BLUR/USDT, please read this: https://docs.ccxt.com/#/README?id=symbols-and-market-ids

@xuyangcn
Copy link
Author

Yes, I give BLUR/USDT, and internally, it translate to BLUR-USDT

@carlosmiei
Copy link
Collaborator

@xuyangcn But does it work now?

@xuyangcn
Copy link
Author

No, not because of the symbol, from the response, you can see that okx already return the orders, I think, it is parseOrder problem

@xuyangcn
Copy link
Author

it is still not working, it works on v1.xx, I just upgrade to 4.4.33

@carlosmiei
Copy link
Collaborator

@xuyangcn Can you try without since just to see if that makes a difference?

@xuyangcn
Copy link
Author

yes, if the since is 0, nothing return,
if I change to 1, then it returned my open orders,
without since, it will report error from okx
{"code":"51000","data":[],"msg":"Parameter param error"}

@carlosmiei
Copy link
Collaborator

@xuyangcn What if you don't provide since at all? since is not required you don't need to provide it

@xuyangcn
Copy link
Author

without since, it will report error from okx
{"code":"51000","data":[],"msg":"Parameter param error"}

@carlosmiei
Copy link
Collaborator

@xuyangcn How are you calling it exactly? since is not required so I'm not sure that's causing the error

@xuyangcn
Copy link
Author

const orders = await exchangeClient.fetchOpenOrders(symbol= symbol,since=1,limit=20, params = { ordType: 'conditional', })
in this way, it works fine.
if I remove since, it will report error.
if I since = 0, it return nothing.
I believe it is a bug,
and should look into
https://github.com/ccxt/ccxt/blob/master/js/src/base/Exchange.js#L1934

@carlosmiei
Copy link
Collaborator

if I remove since, it will report error.

@xuyangcn This does not make sense because OKX does not even accept a since https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-list

@xuyangcn
Copy link
Author

Yes, since and limit are implemented in ccxt side.
If you read the code https://github.com/ccxt/ccxt/blob/master/js/src/base/Exchange.js#L1934
See the line bolded. If I give since = 0, it makes secondCondition become false, then this order will not push to the array

filterByValueSinceLimit(array, field, value = undefined, since = undefined, limit = undefined, key = 'timestamp', tail = false) {
const valueIsDefined = this.valueIsDefined(value);
const sinceIsDefined = this.valueIsDefined(since);
const parsedArray = this.toArray(array);
let result = parsedArray;
// single-pass filter for both symbol and since
if (valueIsDefined || sinceIsDefined) {
result = [];
for (let i = 0; i < parsedArray.length; i++) {
const entry = parsedArray[i];
const entryFiledEqualValue = entry[field] === value;
const firstCondition = valueIsDefined ? entryFiledEqualValue : true;
const entryKeyValue = this.safeValue(entry, key);
const entryKeyGESince = (entryKeyValue) && since && (entryKeyValue >= since);
const secondCondition = sinceIsDefined ? entryKeyGESince : true;
if (firstCondition && secondCondition) {
result.push(entry);
}
}
}
if (tail && limit !== undefined) {
return this.arraySlice(result, -limit);
}
return this.filterByLimit(result, limit, key, sinceIsDefined);
}

@carlosmiei
Copy link
Collaborator

@xuyangcn I know but you reported an issue coming from the API directly

without since, it will report error from okx
{"code":"51000","data":[],"msg":"Parameter param error"}

@xuyangcn
Copy link
Author

const orders = await exchangeClient.fetchOpenOrders(symbol= symbol, limit=20,params = { ordType: 'conditional', })
I got this request link from your verbose, and it is wrong
okx GET https://www.okx.com/api/v5/trade/orders-pending?instId=BLUR-USDT&limit%5BordType%5D=conditional 400 Bad Request

But if I use below line
const orders = await exchangeClient.fetchOpenOrders(symbol= symbol, since=1,limit=20,params = { ordType: 'conditional', })
I got this request link from your verbose, and it is correct one.
okx GET https://www.okx.com/api/v5/trade/orders-algo-pending?instId=BLUR-USDT&limit=20&ordType=conditional 200 OK

@xuyangcn
Copy link
Author

without since, the url send to okx is wrong

@xuyangcn
Copy link
Author

there are two bugs, I think,

  1. without since, it makes a wrong http get request
  2. if since is 0, it makes secondCondition always equal to 0, and then no order return.

@carlosmiei
Copy link
Collaborator

@xuyangcn I think i can reproduce the issue when providing since=0 (I will take a look) but when I don't provide any since it works as expected, check this out:

n okx fetchOpenOrders "LTC/USDT:USDT" undefined undefined '{"trigger": true, "ordType":"conditional"}' --sandbox  --no-table
2024-11-26T14:22:48.592Z
Node.js: v18.18.0
CCXT v4.4.33
okx.fetchOpenOrders (LTC/USDT:USDT, , , [object Object])
2024-11-26T14:22:49.701Z iteration 0 passed in 340 ms

[
  {
    info: {}
    id: '2017146754403004416',
    clientOrderId: 'e847386590ce4dBC510e616e0438b78a',
    timestamp: 1732618057878,
    datetime: '2024-11-26T10:47:37.878Z',
    lastTradeTimestamp: undefined,
    lastUpdateTimestamp: 1732618057878,
    symbol: 'LTC/USDT:USDT',
    type: 'conditional',
    timeInForce: undefined,
    postOnly: undefined,
    side: 'buy',
    price: undefined,
    stopLossPrice: 100,
    takeProfitPrice: undefined,
    stopPrice: undefined,
    triggerPrice: undefined,
    average: undefined,
    cost: undefined,
    amount: 1,
    filled: undefined,
    remaining: undefined,
    status: 'open',
    fee: undefined,
    trades: [],
    reduceOnly: false,
    fees: []
  }
]
2024-11-26T14:22:49.701Z iterat

@xuyangcn
Copy link
Author

try without since, with limit=20

@xuyangcn
Copy link
Author

yes, since = 0 is fixed

@carlosmiei
Copy link
Collaborator

@xuyangcn as you can see

 n okx fetchOpenOrders "LTC/USDT:USDT" undefined 20 '{"trigger": true, "ordType":"conditional"}' --sandbox          
2024-11-26T16:00:25.768Z
Node.js: v18.18.0
CCXT v4.4.32
okx.fetchOpenOrders (LTC/USDT:USDT, , 20, [object Object])
2024-11-26T16:00:26.810Z iteration 0 passed in 338 ms

                 id |                    clientOrderId |     timestamp |                 datetime | lastTradeTimestamp | lastUpdateTimestamp |        symbol |        type | timeInForce | postOnly | side | price | stopLossPrice | takeProfitPrice | stopPrice | triggerPrice | average | cost | amount | filled | remaining | status | fee | trades | reduceOnly | fees
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2017146754403004416 | e847386590ce4dBC510e616e0438b78a | 1732618057878 | 2024-11-26T10:47:37.878Z |                    |       1732618057878 | LTC/USDT:USDT | conditional |             |          |  buy |       |           100 |                 |           |              |         |      |      1 |        |           |   open |     |     [] |      false |   []
2017769660556365824 | e847386590ce4dBCb1d8f95f54858ef3 | 1732636621928 | 2024-11-26T15:57:01.928Z |                    |       1732636621928 | LTC/USDT:USDT | conditional |             |          |  buy |       |           100 |                 |           |              |         |      |      1 |        |           |   open |     |     [] |      false |   []
2017772751087325184 | e847386590ce4dBC9b4c490e149f946e | 1732636714033 | 2024-11-26T15:58:34.033Z |           

@xuyangcn
Copy link
Author

my guess, you pass since = undefined,
and my way is
const orders = await exchangeClient.fetchOpenOrders(symbol= symbol, limit=20,params = { ordType: 'conditional', })

@carlosmiei
Copy link
Collaborator

@xuyangcn Wait, there's no named params in JS, how are you doing symbol=symbol, limit=20, etc ?

@xuyangcn
Copy link
Author
xuyangcn commented Dec 1, 2024

it has named params in JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants