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

okex cancel order url not correct #336

Closed
86chenjie opened this issue Oct 18, 2017 · 24 comments
Closed

okex cancel order url not correct #336

86chenjie opened this issue Oct 18, 2017 · 24 comments
Assignees

Comments

@86chenjie
Copy link
Contributor

result = await ex.cancelOrder(result.id, null, {symbol: ccxtSymbol})

2017-10-18 15:07:44.513: okex POST https://www.okex.com/api/v1/future_cancel.do
4|crypto-m | Request:
4|crypto-m | { 'User-Agent': 'ccxt/1.9.149 (+https://github.com/ccxt-dev/ccxt) Node.js/8.6.0 (JavaScript)',
4|crypto-m | 'Content-Type': 'application/x-www-form-urlencoded' } api_key=aa8740d4-fb38-4ca3-a1fc-2c7a3daca79c&order_id=24532896&symbol=LTC%2FBTC&sign=C0C5CB42ADE5501CB37DFF47DD254B6F

should send to URL https://www.okex.com/api/v1/cancel_order.do

@kroitor kroitor self-assigned this Oct 18, 2017
@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Hi, @86chenjie !

Are you sure about that? I mean:

screen shot 2017-10-18 at 11 44 46

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Oh, I see... that is the future/spot conflict. Got it, will fix now!

kroitor added a commit that referenced this issue Oct 18, 2017
@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Ok, this is fixed as v.1.9.174+. Please update and try it again. We will be happy if you report back, as always. Also, note that I made the second (symbol) param mandatory for OK*, so now you can use a shorter form of it:

result = await ex.cancelOrder(result.id, ccxtSymbol) // just pass the symbol directly

Thx again for your help!

@86chenjie
Copy link
Contributor Author

@kroitor works. thanks

@86chenjie
Copy link
Contributor Author

86chenjie commented Oct 18, 2017

@kroitor btw https://www.okex.com/rest_api.html
this api https://www.okex.com/api/v1/batch_trade.do

let result = await ex.privatePostBatchTrade({
        symbol: ccxtSymbol,
        orders_data:  `[{price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},{price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}]`  
      })
4|crypto-m | 2017-10-18 18:11:00.961: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Request:
4|crypto-m |  { 'User-Agent': 'ccxt/1.9.174 (+https://github.com/ccxt-dev/ccxt) Node.js/8.6.0 (JavaScript)',
4|crypto-m |   'Content-Type': 'application/x-www-form-urlencoded' } api_key=aa8740d4-fb38-4ca3-a1fc-2c7a3daca79c&orders_data=%5B%7Bprice%3A0.0102851%2Camount%3A0.1%2Ctype%3A%27buy%27%7D%2C%7Bprice%3A0.0107066034%2Camount%3A0.1%2Ctype%3A%27sell%27%7D%5D&symbol=LTC%2FBTC&sign=7B1447F73B4AC0F725DD6385244188C3
4|crypto-m | 2017-10-18 18:11:01.003: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Response:
4|crypto-m | {"error_code":10007,"result":false}

how to use this api?

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie try adding .json(...) around the orders_data:

let result = await ex.privatePostBatchTrade({
symbol: ccxtSymbol,
orders_data: ex.json ([{price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},{price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}]),
})

Let me know if it helps or not. Really appreciate your feedback! )

P.S. For readability, paste code and verbose output in text enclosed with 3 backticks (```) for all text information, like so:


```JavaScript // ← this line adds js syntax color highlighting for readability
your code
```


```
your verbose output
```

@86chenjie
Copy link
Contributor Author

86chenjie commented Oct 18, 2017

@kroitor are you sure?
from the doc, orders_data is string like this:

[{price:3,amount:5,type:'sell'},{price:3,amount:3,type:'buy'}] 

image

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie yes, in the same docs they say that it should be a JSON string (means JSON-encoded, though, I agree, they are not very clear in their docs).

screen shot 2017-10-18 at 14 04 44

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

So, yes, I'm sure, you can add the ex.json(...) and go for it ;)

@86chenjie
Copy link
Contributor Author

4|crypto-m | 2017-10-18 19:06:45.944: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Request:
4|crypto-m |  { 'User-Agent': 'ccxt/1.9.174 (+https://github.com/ccxt-dev/ccxt) Node.js/8.6.0 (JavaScript)',
4|crypto-m |   'Content-Type': 'application/x-www-form-urlencoded' } api_key=aa8740d4-fb38-4ca3-a1fc-2c7a3daca79c&orders_data=%5B%7B%22price%22%3A0.0103292%2C%22amount%22%3A0.1%7D%2C%7B%22price%22%3A0.0107708736%2C%22amount%22%3A0.1%7D%5D&symbol=LTC%2FBTC&sign=B093C67C2B24C995073AE384A911B955
4|crypto-m | 2017-10-18 19:06:45.991: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Response:
4|crypto-m | {"error_code":10007,"result":false}

not work

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie ok, i'll debug it more and will get back to you as soon as possible with a solution to that.

@86chenjie
Copy link
Contributor Author

thanks 👍

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

I think I see where the problem is... Can you try this:

// version 1
let result = await ex.privatePostBatchTrade({
    symbol: ex.marketId (ccxtSymbol), // ← custom API needs manual conversion symbol → market id
    orders_data: '[{price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},{price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}]',
})

If it doesn't help, please try it the second time with ex.json () added:

// version 2
let result = await ex.privatePostBatchTrade({
    symbol: ex.marketId (ccxtSymbol), // ← custom API needs manual conversion symbol → market id
    orders_data: ex.json([
       {price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},
       {price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}
    ]),
})

We would be happy if you actually try both versions anyway...

If that doesn't help either, I'll debug it further...

@86chenjie
Copy link
Contributor Author

let result = await ex.privatePostBatchTrade({
        // symbol: ccxtSymbol,
        symbol: ex.marketId (ccxtSymbol),
        orders_data: `[{price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},{price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}]`
        // orders_data: ex.json(obj)
      })
var obj = [
        {
          price: g.depth.bidPrice * 0.98,
          amount: amount
        },
        {
          price: g.depth.askPrice * 1.02,
          amount: amount
        }
      ]
      let result = await ex.privatePostBatchTrade({
        // symbol: ccxtSymbol,
        symbol: ex.marketId (ccxtSymbol),
        // orders_data: `[{price:${g.depth.bidPrice * 0.98},amount:${amount},type:'buy'},{price:${g.depth.askPrice * 1.02},amount:${amount},type:'sell'}]`
        orders_data: ex.json(obj)
      })

both not work

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie can you show the verbose output of the version 1 once again?

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Nope, never mind, verbose output not needed.

@86chenjie
Copy link
Contributor Author

4|crypto-m | 2017-10-18 20:13:39.885: CONNECTED
4|crypto-m | 2017-10-18 20:13:41.892: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Request:
4|crypto-m |  { 'User-Agent': 'ccxt/1.9.174 (+https://github.com/ccxt-dev/ccxt) Node.js/8.6.0 (JavaScript)',
4|crypto-m |   'Content-Type': 'application/x-www-form-urlencoded' } api_key=aa8740d4-fb38-4ca3-a1fc-2c7a3daca79c&orders_data=%5B%7Bprice%3A0.0103195372%2Camount%3A0.1%2Ctype%3A%27buy%27%7D%2C%7Bprice%3A0.010755175799999999%2Camount%3A0.1%2Ctype%3A%27sell%27%7D%5D&symbol=ltc_btc&sign=F8F2AF0CEFB5DA0960E310605DE17EC5
4|crypto-m | 2017-10-18 20:13:41.933: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Response:
4|crypto-m | {"error_code":10007,"result":false}
4|crypto-m | 2017-10-18 20:16:25.142: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Request:
4|crypto-m |  { 'User-Agent': 'ccxt/1.9.174 (+https://github.com/ccxt-dev/ccxt) Node.js/8.6.0 (JavaScript)',
4|crypto-m |   'Content-Type': 'application/x-www-form-urlencoded' } api_key=aa8740d4-fb38-4ca3-a1fc-2c7a3daca79c&orders_data=%5B%7B%22price%22%3A0.010319811600000001%2C%22amount%22%3A0.1%7D%2C%7B%22price%22%3A0.010741518%2C%22amount%22%3A0.1%7D%5D&symbol=ltc_btc&sign=5533BC36B35563810F5C54402FD71C57
4|crypto-m | 2017-10-18 20:16:25.182: okex POST https://www.okex.com/api/v1/batch_trade.do 
4|crypto-m | Response:
4|crypto-m | {"error_code":10007,"result":false}

kroitor added a commit that referenced this issue Oct 18, 2017
@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie ok, looks like I found the problem now... Can you please update ccxt to 1.9.177+ and retry code snippet version 1 once more? Sorry for bothering you with this. Looks like OKEX doesn't like urlencoded-strings... But it should work now. If it doesn't, I'll go on with fixing this nasty bug...

homer

@86chenjie
Copy link
Contributor Author

@kroitor version 1 code works. 👍

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@86chenjie ok, please let me know if you experience any other difficulties with it. Thx a lot for your collaboration!

@86chenjie
Copy link
Contributor Author

@kroitor i have a question not related to ccxt:
fetchTrades() this api return dealed trade list, which contain a 'side' property,
'side': 'buy', // direction of the trade, 'buy' or 'sell'

i'm curious about how this 'side' is determined.
For me, there must be 1 buy order & 1 sell order for each trade, so how this field is determined?
thanks!

@kroitor
Copy link
Member

kroitor commented Oct 21, 2017

@86chenjie hi!

Are you familiar with the concept of "maker and taker" ? You're absolutely right, for each trade there should be 1 buy order and 1 sell order, and those 2 orders should match each other. But when 2 orders are matched only one trade is created for each matched pair of orders.

It goes like this: let's say, we put an order for buying and that order does not match any other order in the orderbook to be closed or "filled" immediately. The created order is placed into the orderbook then, and that order is hanging there until someone decides to create an opposite matching order. That "waiting" order is called a "market-maker" order, because it "makes" or "builds" the market by adding the volume of your offer (order) to the orderbook → you kinda "provide" liquidity to the market by placing an order that will be hanging there. The market accumulates more "ordered" volume overall, so each of our hanging orders are "market-making" orders. When you are market-making, you add to the total market liquidity.

But the "trade" (or "a fill") is created when someone creates a second matching order. Let's say another person places an order to sell the same volume as we were buying previously. The matching engine of the exchange can see both matching orders and the second order is considered to be a "market-taker" order. The second order closes or "fills" the first one and both of them are removed from the orderbook when the trade is created. So, the second order is taking the liquidity away from the orderbook, leaving less offered volume there. This is why it's called "a taker".

Now, because the trade is created when the second order is placed, the side of the trade is the side of that second order that does the fill, that is the taker in the example above. So, if we placed a buying market-maker order, the side of the trade will be side of the second market-taker sell order, or just "sell". In other words, the side of each trade is the taker side. Moreover, each maker order can be filled with one or more taker orders, effectively producing a row of taker-sell trades, which have the "sell" side. Most of exchange engines will consider that a "sell" trade, but there may be wild matching engines out there, which do it another way.

The buy is equivalent, but opposite – someone should be maker-selling, and some other one should be taker-buying. And the trades are on the "buy" side then.

I hope it answers your question.

@kroitor
Copy link
Member

kroitor commented Oct 21, 2017

P.S. Market-maker trading fees are usually much lower than market-taker fees. So it's more profitable to be a maker. Some exchanges don't even take a fee from the maker. And some low-volatile exchanges are even ready to pay you a rebate or "a reward" for market-making. You get some part of the fee added to your balance when you are a maker (they pay you for providing the liquidity).

@86chenjie
Copy link
Contributor Author

@kroitor thanks for your detailed explanation. totally make sense. 👍

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