Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Предзаказ обмена

Получить перечень маркетов:

если enabled = true и offChainSwapEnabled = true - на рынке разрешен офф-чейн обмен

query {
    swapMarkets {
        id
        baseCurrencyId
        quoteCurrencyId
        enabled
        offChainSwapPricePrecision # сколько знаков после запятой показывать в прайсе
        offChainMinBaseAmount # минимальное количество обмена в базовой валюте
        offChainMaxBaseAmount # максимальное количество обмена в базовой валюте
        offChainMinQuoteAmount # минимальное количество обмена в квотируемой валюте
        offChainMaxQuoteAmount # максимальное количество обмена в квотируемой валюте
        offChainCommission # комиссия в процентах
        offChainSwapEnabled # флаг включения оффчейн обмена на рынке
    }
}

Пример ответа:

{
  "data": {
    "swapMarkets": [
      {
        "id": "A1-A11",
        "baseCurrencyId": "A1",
        "quoteCurrencyId": "A11",
        "enabled": false,
        "offChainSwapPricePrecision": 4,
        "offChainMinBaseAmount": 0,
        "offChainMaxBaseAmount": 1000,
        "offChainMinQuoteAmount": 0,
        "offChainMaxQuoteAmount": 1000,
        "offChainCommission": 1,
        "offChainSwapEnabled": true
      },
      {
        "id": "A1-EUR",
        "baseCurrencyId": "A1",
        "quoteCurrencyId": "EUR",
        "enabled": false,
        "offChainSwapPricePrecision": null,
        "offChainMinBaseAmount": null,
        "offChainMaxBaseAmount": null,
        "offChainMinQuoteAmount": null,
        "offChainMaxQuoteAmount": null,
        "offChainCommission": null,
        "offChainSwapEnabled": false
      },
      ...
      {
        "id": "ETH-USDT",
        "baseCurrencyId": "ETH",
        "quoteCurrencyId": "USDT",
        "enabled": true,
        "offChainSwapPricePrecision": 4,
        "offChainMinBaseAmount": 0.001,
        "offChainMaxBaseAmount": 10,
        "offChainMinQuoteAmount": 10,
        "offChainMaxQuoteAmount": 18,
        "offChainCommission": 5,
        "offChainSwapEnabled": true
      },
      ...
    ]
  }
}

Предзаказ обмена

Сначала необходимо получить квоту (информацию о цене, по которой можно будет обменять деньги).

В ответе присутствуют поля createdAt и expireAt: перед запрос квоты необходимо сохранить текущее время пользователя. После получения ответа от сервера рассчитать разницу между серверным временем и временем пользователя и использовать эту разницу для расчета expireAt во времени пользователя.

mutation {
    getOffChainSwapQuote(
        fromCurrencyId: "ETH",
        toCurrencyId: "USDT",
        # direction can be 'to' or 'from'
        direction: "from",
        amount: "0.005"
    ) {
        id
        fromCurrencyId
        toCurrencyId
        direction
        amount
        give # сколько спишут с баланса пользователя (с учетом комиссии)
        receive # сколько в результате получит на баланс пользователь (с учетом комиссии)
        commissionCurrencyId
        commission # комиссию, которую заплатит пользователь
        createdAt
        expireAt
        status
        isActive
        isErrored
    }
}

Результат запроса:

{
  "data": {
    "getOffChainSwapQuote": {
      "id": "45f2c531-fcdd-4d44-bc9a-45e6426d679b",
      "fromCurrencyId": "ETH",
      "toCurrencyId": "USDT",
      "direction": "from",
      "amount": 0.005,
      "give": 0.005,
      "receive": 18.03,
      "commissionCurrencyId": "USDT",
      "commission": 0.95,
      "createdAt": "2024-06-07T10:29:09.048Z",
      "expireAt": "2024-06-07T10:29:19.048Z",
      "status": "waiting",
      "isActive": true,
      "isErrored": false
    }
  }
}

Возможные ошибки:

  1. Превышен max amount:

{
  "data": {
    "getOffChainSwapQuote": {
      "id": null,
      "fromCurrencyId": null,
      "toCurrencyId": null,
      "direction": null,
      "amount": null,
      "give": null,
      "receive": null,
      "commissionCurrencyId": null,
      "commission": null,
      "createdAt": null,
      "expireAt": null,
      "status": "Amount is more then max",
      "isActive": null,
      "isErrored": true
    }
  }
}
  1. Не достигнут min amount:

{
  "data": {
    "getOffChainSwapQuote": {
      "id": null,
      "fromCurrencyId": null,
      "toCurrencyId": null,
      "direction": null,
      "amount": null,
      "give": null,
      "receive": null,
      "commissionCurrencyId": null,
      "commission": null,
      "createdAt": null,
      "expireAt": null,
      "status": "Amount is less then min",
      "isActive": null,
      "isErrored": true
    }
  }
}
  1. Не найден рынок или на рынке enabled = false или offChainSwapEnabled = false:

{
  "data": {
    "getOffChainSwapQuote": {
      "id": null,
      "fromCurrencyId": null,
      "toCurrencyId": null,
      "direction": null,
      "amount": null,
      "give": null,
      "receive": null,
      "commissionCurrencyId": null,
      "commission": null,
      "createdAt": null,
      "expireAt": null,
      "status": "Offchain Swap isn't enabled",
      "isActive": null,
      "isErrored": true
    }
  }
}
  1. Ошибка сервиса - не получается получить квоту:

{
  "data": {
    "getOffChainSwapQuote": {
      "id": null,
      "fromCurrencyId": null,
      "toCurrencyId": null,
      "direction": null,
      "amount": null,
      "give": null,
      "receive": null,
      "commissionCurrencyId": null,
      "commission": null,
      "createdAt": null,
      "expireAt": null,
      "status": "Internal Server Error. Try later",
      "isActive": null,
      "isErrored": true
    }
  }
}

Подтверждение квоты (запуск обмена)

mutation {
    confirmOffChainSwapQuote(id: "85d0bc81-004b-4f27-b09f-6540529136e4")
}

Ответ на подтверждение

{
  "data": {
    "confirmOffChainSwapQuote": true
  }
}

________________________________________

  1. Отримання рейту - потрібне ДО формування квоти, для розуміння Юзером витраченної комісіі та приблизного рейту після обміну.
    1.1. При отриманні Квоті(перехід на крок підтвердження Квоти) має враховуватись баланс Брокера
    1.2. При невдалому отриманні Квоти - повідомляти причину помилки
    1.3. Попередня форма, до формування Квоти, має бути “калькулятором” для прозорого розуміння Юзером сплати комісіі, обрахунок, рейт
    1.4 Користивуч не має бути прив'язаний до Балансу Брокера, на етапі приблизного обрахування його обміну

  2. При цій запропонованій побудові - Фронт має отримувати зміну по квоті при кожній зміни кількості на обмін. Фронт не зможе адекватно обробляти це бо:

    Юзер може протягом короткоко часу ввести, змінити, додати Кількість на обмін багато разів - що приводить кожного разу до Нового запиту отримання Квоти, відповідно отримання Квоти може бути успішним/неуспішним та отримання Квоти може зайняти тривалий час .
    Це побуджує велечезну кількість запитів на отримання квоти, що буде означати не зовсім неочікуєму роботу обрахунку у формі на Фронті

  3. В нас має бути можливість користуватися офф-чейн свапом з підключеною зовнішньою Платформою та без, в контексті однієї форми для обміну.
    Якщо - ні , то налаштування потрібно розділити : ЮзерАпп з 2ма видами налаштувань обміну або внутрішній/або зовнішній . Поєднати це проблематично та потребує досліджень та роз'яснень, а потім погодження як це має бути для Операторів, які не потребують інтеграціі зовнішних Платформ.

  4. Для Обміну було б раціонально мати РейтСорс у налаштуваннях маркету з показником ЛастПрайс, отриманий з Трейдінгу(або інший рейт-сорс Зовнішньої платформи)
    Додатково: у маркета мало б бути делька рейт-сорсів. Та припиненні роботи одного рейт-сорсу(падііня сервісу) - вмикання наступного. Це запобігає некоректній роботі Свапу на платформі.

  5. В якій валюті береться комісія за Обмін на Зовнішній платформі?
    В нас є можливисть налаштування як у базовій так і у валюті квотування - чи не буде це ломати наш Обмін в Операціях?

____________________________________________________________________

depricated:


Для этого используем:

mutation {
  getSwapQuote(
      marketId: String!,
      from: String!,
      to: String!,
      # direction can be 'to' or 'from'                    
      direction: String!,
      amount: String!
  ): SwapQuote
}

Обратите внимание, параметр direction помогает указать в какой валюте указывается amount - во входящей или исходящей.

Пример 1.

Я хочу поменять 100 USDT на ETH запрос будет выглядеть:

mutation {
  swapQuote(
    from: "USDT",
    to: "ETH",
    marketId: "ETH-USDT",
    direction: "from",
    amount: "100"
  ) {
    id
    serviceId
    from
    to
    direction
    amount
    give
    receive
    rate
    internalGive
    internalReceive
    expireAt
    status
    isActive
    isErrored
  }
}

Пример 2.

Я хочу поменять USDT и получить в результате 0.001 ETH запрос будет выглядеть:

mutation {
  swapQuote(
    from: "USDT",
    to: "ETH",
    marketId: "ETH-USDT",
    direction: "to",
    amount: "0.001"
  ) {
    id
    serviceId
    from
    to
    direction
    amount
    give
    receive
    rate
    internalGive
    internalReceive
    expireAt
    status
    isActive
    isErrored
  }
}

Параметры из ответа:

give - сколько клиент должен будет заплатить без учета комиссии нашей системы (приблизительно, если direction = “to” и точно, если direction = “from”)

receive - сколько клиент получит без учета комиссии нашей системы (приблизительно, если direction = “from” и точно, если direction = “to”)

rate - receive / give

internalGive - сколько клиент заплатит с учетом нашей комиссии (приблизительно если direction = “to” и точно, если direction = “from”)

internalReceive - сколько клиент получит без учета комиссии нашей системы (приблизительно, если direction = “from” и точно, если direction = “to”)

expireAt - время, когда текущая квота утратит свою актуальность.

Обмен

После принятия клиентом решения об обмене (если попадаем в 10секундный интервал) используется следующий:

mutation {
  confirmSwapQuote(id: String!): SwapQuote
}

Передаем id квоты, serviceId, marketId

UX

Screenshot from 2024-04-24 18-18-12.png

Off- chain Swap Step 1

As a User, I can see main details of the form:

  • 'Quick Swap' header

  • Send section with main details:

    • 'Drop down' button to select Currency to Send with logo and ID (Ticker)

    • In case there is only one option for Currency to Send: the user can observe just this option with logo and currency ID (without drop-down

    • Currency to Send is selected according Wallet selected (by default for each Wallet) with logo and ID (Ticker)

    • Input field for amount to Swap (Send internally), pre-set "Minimum amount" to Swap by default

    • “Max” button

    • Asset's balance available for operation, in selected currency with currency ID

    'Reverse' button for changing Currency positions between 'Send' and 'Receive'

  • Receive section with main details:

    • 'Drop down' button to select Currency to Receive with logo and ID (Ticker)

    • The field 'Receive' with a calculated amount (Approximate) in Currency to Receive

    • The second Asset's balance (Currency to Receive) is currently available in its Wallet

  • Platform commission portion and ID (commission ID can be in the quote or base currency according to market settings)

  • Platform rate portion for selected Market Pair: Currency to Swap -> Currency to Receive (price precision, according to market settings)

  • Estimated result rate for selected Market Pair: Currency to Swap -> Currency to Receive (price precision, according to market settings)

    'Switch' icons as buttons to switch the Estimated result rate or Platform rate reflection Currency to Receive -> Currency to Swap

    'Swap' button

    'X' button below the main form to close the modal window


Actions on Step 1:


1. Press 'Drop Down' button to change Currency to Send and open the Currencies drop-down list :

  • See the list of currencies suggested as Currencies to Send (according to Market Pairs on the platform): - ‘Search’ field
    - Logo, ID/Ticker
    - Asset's balance available for operation
    - Selected Currency is ‘marked’

  • Select the Currency to Send from the list

See the Swap details changed according to the Market parameters with new selected Currency:

  • Pre-set for Send in the Input field for amount to Send (Minimum amount to send according to market settings)

  • Current Balance of Currency to Send

  • Option(s) for Currency(ies) to receive

  • Field 'Receive' with the calculated amount (Approximate) in Currency to Receive

  • Current Balance of Currency to Receive

  • Platform commission

  • Platform rate

  • Estimated result rate

  1. Press “Max” button and use all available balance for Swap operation:

  • See the calculated amount (Approximate) of Currency to Receive in the field 'Receive'

  • Observe that the Amount of the Currency to Receive depends on the estimated rate of the selected Market Pair and changes if the Amount to Send is edited

  • See the 'Swap' Button activated if the input amount fits the requirements

  • Platform commission displays data

  • Platform rate displays data

  • The estimated result rate displays the data
    In case the maximum balance is lower than the minimum required for Send:

  • 'Minimum amount to send' notification on top of the input field "Amount" (according to market settings)

  • See the 'Swap' Button deactivated

  • Field 'Receive' with “0.00” amount in Currency to Receive. The text has an error color

  • Platform commission has a ' – ' amount

  • Platform rate displays data

  • Estimated result rate has a ' – ' amount

  1. Press the 'Reverse' button and change the position of selected currencies Currency to Receive -> Currency to Send

  2. Press the 'Drop Down' button to change Currency to Receive and open the Currencies drop-down list

  • See the list of currencies suggested as Currencies to Receive (according to Market Pairs on the platform):
    - ‘Search’ field
    - Logo, ID/Ticker
    - Asset's balance available for operation
    - Selected Currency is ‘marked’

  • Select the Currency to Receive from the list

See the Swap details changed according to the Market parameters with the new selected Currency:

  • Pre-set for Send in the Input field for the amount to Send (Minimum amount to send according to market settings)

  • Current Balance of Currency to Send

  • Option(s) for Currency(ies) to Send

  • Field 'Receive' with a calculated amount (Approximate) in Currency to Receive

  • Current Balance of Currency to Receive

  • Platform commission

  • Platform rate

  • Estimated result rate

  1. Press the 'Switch' icon as a button in the Platform rate portion and change the rate reflection Base/Quote or Quote/Base
    Press the 'Switch' icon as a button in the Estimated result rate portion and change the rate reflection Base/Quote or Quote/Base

  1. Click on the Input field for the amount to Send and see previous input clears automatically and the 'Minimum amount to send' notification is on top of the input field "Amount" (according to market settings)

  2. Input amount for Send and:

  • See the calculated amount (Approximate) of Currency to Receive in the field 'Receive'

  • Observe that the Amount of the Currency to Receive depends on the estimated rate of the selected Market Pair and changes if the Amount to Send is edited

  • See the 'Swap' Button activated if the input amount fits the requirements

  • Input only 'dot' first and see automatically changing to ' 0. ' in the Input field

  • Platform commission displays data

  • Platform rate displays data

  • The estimated result rate displays the data

  1. Input amount of the Currency to Swap lower than the minimum allowed and...

  • 'Minimum amount to send' notification on top of the input field "Amount" (according to market settings)

  • See the 'Swap' Button deactivated

  • Field 'Receive' with “0.00” amount in Currency to Receive. The text has an error color

  • Platform commission has a ' – ' amount

  • Platform rate displays data

  • Estimated result rate has a ' – ' amount

  1. Input amount of the Currency to Send bigger than the amount of the Available Assets:

  • See the 'Swap' Button deactivated

  • The field 'Receive' with a calculated amount (Approximate) in Currency to Receive. The text has an error color

  • Platform commission displays data

  • Platform rate displays data

  • The estimated result rate displays the data

  1. Leave the input field for Amount to Send empty:

  • 'Minimum amount to send' notification on top of the input field "Amount" (according to market settings)

  • Field 'Receive' with “0.00” amount in Currency to Receive. The text has an error color

  • Platform commission has a ' – ' amount

  • Platform rate displays data

  • Estimated result rate has a ' – ' amount

  • See the 'Swap' Button deactivated

  1. In case the available balance of the Currency to Send is lower than the minimum amount of the Currency to Send (the first time open the form)

  • See the amount pre-set equal to the minimum amount to Send in the input field for Currency to Send

  • Field 'Receive' with a calculated amount (Approximate) in Currency to Receive. The text has an error color

  • See the 'Swap' Button deactivated

  • Platform commission displays data

  • Platform rate displays data

  • The estimated result rate displays the data

  1. Press the 'Swap' button and go to Off-chain Swap Step 2

  2. Press the ‘X' button below the 'Quick Swap' form and close the modal window 'Quick Swap’ form and get back to Wallet details

Off- chain Swap Step 2

Screenshot from 2024-04-24 18-57-48.png

As a User I can see main details of the form:

  • 'Confirmation' header

  • Send section with main details:

    • Currency to Send with logo and ID (Ticker)

    • Currency to Send is selected according to Step 1

    • Amount to Swap (Send internally) according to Step 1 inputs

  • 'Arrow' icon for displaying Currency swap positions between 'Send' and 'Receive'

  • Receive section with main details:

    • Currency to Receive with logo and ID (Ticker). Selected according to Step 1

    • The field 'Receive' with a calculated amount in Currency to Receive

  • Notice text message “Swap result in precise according to current rate”

  • Rate portion for selected Market Pair: Currency to Swap -> Currency to Receive (price precision, according to market settings)

  • Inverse rate portion for selected Market Pair: Currency to Swap -> Currency to Receive (price precision, according to market settings)

  • 'Confirm Swap' button (with timer)

  • 'X' button below the main form to close the modal window

Actions on Step 2:

  1. Press 'Confirm Swap' button and:

  • See popup notification 'Successful' if everything is correct

  • See the modal window 'Swap form' closing and get back to Wallet details

In case time is over 'Confirm Swap' button changes to “Refresh Quote” button

  • Rate portion and Inverse rate portions for selected Market Pair have stable data without updates

Screenshot from 2024-04-24 20-09-06.png

  1. Press ”Refresh Quote” button and:

  • Rate portion and Inverse rate portions for selected Market Pair updated with fresh data

  • The “Refresh Quote”' button changes to Confirm Swap' button with a timer

  1. Press the ‘X' button below the 'Confirmation' form and close the modal window 'Confirmation’ form and get back to Wallet details

Main Formulas:

Platform commission = Number from Market settings (Min or % or Max)

Platform commission coefficient = 1 - % of commission OR 1 + % of commission (depending on side)

Platform rate = Rate Source or Quote Rate

Estimated result rate = Rate Source * Platform commission coefficient

Receive amount = Send * Estimated result rate

  • No labels