KTX.Finance
English
Search
K
Comment on page
💻

Direct Contract Interaction

Here you can find information on how to interact with our contracts directly

Introduction

As KTX.Finance is decentralized on Mantle Network, you can use all the functions directly. This guide can be used to interact directly with the smart contracts that run all the trading functions of KTX.Finance on the Mantle Network.
You only need three things:
  • Your own wallet address
  • https://explorer.mantle.xyz/ (or another Mantle block explorer)
  • The storage contract address is where all the important addresses are kept – including the address of the trading contract, as well as your trades themselves.
Before we open and close trades, it is important to know the different kinds of orders that exist. For more information, please check the Opening / Closing trades page.

It is also worth understanding the properties your trades have:

pairIndex: This corresponds to a trading pair, e.g. BTC = 0, ETH = 1, LINK = 2 etc. A full list of trading pairs can be found here.
index: As you can open 3 trades on each pair, there are 3 ‘slots’ your trade can sit in. These are index 0, 1, or 2. Your first trade will open in index 0, the second in index 1, and third in slot 3. If you close index 0, but leave open index 1, it will remain in index 1.

How to interact with the contract directly

Opening a Trade – Market and Limit Orders

  1. 1.
    Go to the ComplexOrderRouter contract on Mantle Network.
  2. 2.
    Right underneath ‘Write Contract’ you will see a red dot with ‘Connect to Web3’. Click this and connect your wallet (e.g. metamask). You should always double-check the site you are interacting with.
  3. 3.
    Scroll down to ‘3. createComplexOrder, you will now need to fill in the following properties:
    1. 1.
      _path(address[]): collateral token address with size = 1
      • for long orders, collateral token must be the same as index token, e.g.
        • must use $BTC to long $BTC
        • must use $ETH to long $ETH
        • KTX.Finance supports swap & order in this function, but it is not recommended as swap fee applies
      • for short orders, collateral token must be stable token
      • e.g.
        • long BTC with BTC as collateral, _path = ["BTC address"]
        • long ETH with ETH as collateral, _path = ["ETH address"]
        • short BTC with USDT as collateral, _path = ["USDT address"]
    2. 2.
      _amountIn(uint256): collateral token amount
      • always fill in amount of token as in collateral token, e.g.
        • if _path = ["ETH address"], 3*10^18 means 3 ETH
        • if _path = ["USDT address", "ETH address"], 3*10^6 means 3 USDT because USDT has 6 decimals
    3. 3.
      _minOut(uint256): swap minimum out
      • 0 if no swap required
      • fill minimum out if swap required
    4. 4.
      _isLong(bool): if this is long order
      • true: long order
      • false: short order
    5. 5.
      _referralCode(bytes32): refer code
      • the hex number of your referrer/best friend's refer code). You will have a decreased fee, and they make money – win win
      • fill 0x0000000000000000000000000000000000000000000000000000000000000000 if no refer code
    6. 6.
      _sizeDelta(uint256[]): a list of uint256 with size = 3
      • _sizeDelta[0]: position size
      • _sizeDelta[1]: decrease position size when take profit happens
        • normally _sizeDelta[1] = _sizeDelta[0], because you may want to close the entire position when take profit happens
        • 0 if you do not want to create take profit order
      • _sizeDelta[2]: decrease position size when stop loss happens
        • normally _sizeDelta[2] = _sizeDelta[0], because you may want to close the entire position when stop loss happens
        • 0 if you do not want to create stop loss order
      • leverage = _sizeDelta[0]/_amountIn, and please keep leverage at 2 - 100 to avoid unexpected liquidation.
      • e.g.
        • [610^18, 610^18, 6*10^18] for ETH means you want to open a position with size = 3ETH and fully close it when tp/sl happens.
    7. 7.
      _price(uint256[]): a list of uint256 with size = 3
      • _price[0]: acceptable price for position increase
        • price is changing every moment and we use this price as your acceptable price, normally you can calculate this price using: current_mark_price * (1 - acceptable_slippage) for long order and current_mark_price * (1 + acceptable_slippage) for short order. KTX by default uses 0.3% as acceptable_slippage on our website.
      • _price[1]: trigger price for take profit order
        • for long order, take profit price must be greater than _price[0]
        • for short order, take profit price must be smaller than _price[0]
      • _price[2]: trigger price for stop loss order
        • for long order, stop loss price must be smaller than _price[0]
        • for short order, stop loss price must be greater than _price[0]
    8. 8.
      _token(address[]): a list of address with size = 3
      • _token[0], index token
      • _token[1], take-back token when take profit happens
      • _token[1], take-back token when stop loss happens
      • normally _token[0] = _token[1] = _token[2] to avoid swap fees
      • e.g.
        • ["ETH address", "ETH address", "ETH address"] means long ETH
    9. 9.
      _executionFee(uint256[]): a list of uint256 with size = 3
      • _executionFee[0]: 10^17
      • _executionFee[2]: 10^17
      • _executionFee[1]: 10^17
      • currently we charge 0.1 MNT to cover the gas of position/order execution
    10. 10.
      value: value of this transaction
      • 3*10^17 if order contains both tp and sl
      • 2*10^17 if order contains tp or sl
      • 10^17 if order has no tp or sl
  4. 4.
    Click 'Write' and submit the transaction.

Finding your Open Trades

We provide APIs for you to quickly get your open positions.
Request URL:
Request body:
query MyQuery {
activePositions(
orderBy: timestamp
orderDirection: desc
where: {status: "active", account: "your_address_in_lower_case"}
) {
account
collateral
collateralToken
isLong
size
timestamp
indexToken
averagePrice
}
}

Finding your Limit / Stop Limit Orders

We provide APIs for you to quickly get your open limit orders.
Request URL:
Request body:
query MyQuery {
orders(
where: {status: open, account: "your_address_in_lower_case"}
orderBy: createdTimestamp
orderDirection: desc
) {
account
status
type
triggerPrice
triggerAboveThreshold
size
isLong
indexToken
index
id
createdTimestamp
}
}
Last modified 1mo ago