DeXter-on-Radix / website

Community built order book dex on Radix.
https://dexteronradix.com/
Other
15 stars 22 forks source link

Market order not working for FLOOP/XRD pair #593

Open fliebenberg opened 1 month ago

fliebenberg commented 1 month ago

Currently when I try to submit a market order on the FLOOP/XRD pair I get an error message in the wallet. The problem is that we are sending 9999 as the slippage limit, which creates a problem in the component as it calculates a limit price higher than the maximum price available on the pair. It is better to just set the slippage limit to -1 if we dont want a slippage limit to apply. The component will then set the max/min price to the max/min price available on the orderbook. I will also fix this bug in the component when I create AlphaDEX v2, but for now we need to use -1 as the slippage value for market orders.

dcts commented 3 weeks ago

The slippage is set with this logic:

function getSlippage(type: OrderType): number {
  return type === OrderType.MARKET ? 9999 : -1; // acceppt unlimeted slippage on market orders
}

For LIMIT orders setting it to -1 does work, for MARKET orders I get this error when trying to do that: "Could not convert to OrderInput: Error: Could not create new order from Object. Only one of price or slippage must be specified."

dcts commented 3 weeks ago

@fliebenberg I am not sure how to fix this. I tried different slippages for CUPPA (which has similar precision value as FLOOP), none of them worked:

I also tried setting a very high price and no slippage (as the error says either price or slippage must be set). But that did not work either, I got this error:

Price specified is lower than the best available sell price (2'300'000)

Which is weird as the price I specified was very high (999'999'999).

dcts commented 3 weeks ago

Full log:

{
  "message": "Could not create valid tx manifest: No order could be matched with specified price.",
  "quote": {
    "status": 200,
    "message": "FAILURE",
    "quote": {
      "pairAddress": "component_tdx_2_1cztfwyla4xa5hp4y7l9ss5ul3j2yh9mkmwv3cxyuh2jmf7pr03p923",
      "requiredAmount": 0,
      "fromToken": {
        "address": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc",
        "name": "Radix",
        "symbol": "XRD",
        "iconUrl": "https://assets.radixdlt.com/icons/icon-xrd-32x32.png"
      },
      "fromAmount": 0,
      "toToken": {
        "address": "resource_tdx_2_1th0aurynw8gv73p22e8t6ztg9200qdhxzfpfpqw2yexaj6h3l6zwdm",
        "name": "Cuppa Test Token",
        "symbol": "CUPPA",
        "iconUrl": "https://picsum.photos/id/63/200"
      },
      "toAmount": 0,
      "orderAmount": 0,
      "orderbookAmount": 0,
      "bestPrice": 2300000,
      "worstPrice": 2300000,
      "avgPrice": 0,
      "slippage": 0,
      "exchangeFees": 0,
      "platformFees": 0,
      "liquidityFees": 0,
      "totalFees": 0,
      "expectedResult": "FAILURE",
      "resultCode": 3,
      "resultMessage": "No order could be matched with specified price.",
      "resultMessageLong": "Price specified is lower than the best available sell price (2300000)"
    },
    "request": {
      "pairAddress": "component_tdx_2_1cztfwyla4xa5hp4y7l9ss5ul3j2yh9mkmwv3cxyuh2jmf7pr03p923",
      "orderType": "MARKET",
      "side": "SELL",
      "tokenAddress": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc",
      "amount": 12376.91514269,
      "price": 999999999,
      "slippage": -1,
      "platformId": 4,
      "submitAccountAddress": "account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9",
      "settleAccountAddress": "account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9",
      "platformFee": 0.001
    }
  }
}
fliebenberg commented 3 weeks ago

The slippage is set with this logic:

function getSlippage(type: OrderType): number {
  return type === OrderType.MARKET ? 9999 : -1; // acceppt unlimeted slippage on market orders
}

For LIMIT orders setting it to -1 does work, for MARKET orders I get this error when trying to do that: "Could not convert to OrderInput: Error: Could not create new order from Object. Only one of price or slippage must be specified."

It seems like you are specifying a price for the market order? The API does not accept both price and slippage as it would not know which one to apply for the maximum price. Can you give an example of the full tx that gets sent to the API or to the client?

fliebenberg commented 3 weeks ago

Full log:

{
  "message": "Could not create valid tx manifest: No order could be matched with specified price.",
  "quote": {
    "status": 200,
    "message": "FAILURE",
    "quote": {
      "pairAddress": "component_tdx_2_1cztfwyla4xa5hp4y7l9ss5ul3j2yh9mkmwv3cxyuh2jmf7pr03p923",
      "requiredAmount": 0,
      "fromToken": {
        "address": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc",
        "name": "Radix",
        "symbol": "XRD",
        "iconUrl": "https://assets.radixdlt.com/icons/icon-xrd-32x32.png"
      },
      "fromAmount": 0,
      "toToken": {
        "address": "resource_tdx_2_1th0aurynw8gv73p22e8t6ztg9200qdhxzfpfpqw2yexaj6h3l6zwdm",
        "name": "Cuppa Test Token",
        "symbol": "CUPPA",
        "iconUrl": "https://picsum.photos/id/63/200"
      },
      "toAmount": 0,
      "orderAmount": 0,
      "orderbookAmount": 0,
      "bestPrice": 2300000,
      "worstPrice": 2300000,
      "avgPrice": 0,
      "slippage": 0,
      "exchangeFees": 0,
      "platformFees": 0,
      "liquidityFees": 0,
      "totalFees": 0,
      "expectedResult": "FAILURE",
      "resultCode": 3,
      "resultMessage": "No order could be matched with specified price.",
      "resultMessageLong": "Price specified is lower than the best available sell price (2300000)"
    },
    "request": {
      "pairAddress": "component_tdx_2_1cztfwyla4xa5hp4y7l9ss5ul3j2yh9mkmwv3cxyuh2jmf7pr03p923",
      "orderType": "MARKET",
      "side": "SELL",
      "tokenAddress": "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc",
      "amount": 12376.91514269,
      "price": 999999999,
      "slippage": -1,
      "platformId": 4,
      "submitAccountAddress": "account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9",
      "settleAccountAddress": "account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9",
      "platformFee": 0.001
    }
  }
}

Sorry, I see you provided the request info here. For market orders you should be able to leave out both price and slippage, but I see the API throws an error. I am looking into this...

fliebenberg commented 3 weeks ago

@dcts I have made some changes to the stokenet API which should now allow a -1 and -1 for both price and slippage for MARKET orders. So when we submit market orders on Dexter we can use this. Can you please check if this fixes the issue. I could test it with the request above on the API, but we still need to make sure it works for the app.

fliebenberg commented 3 weeks ago

Once it is confirmed working for stokenet I will update the mainnet APIs. That takes quite some time, so I first want to ensure it si working on stokenet.