Connecting Market Off-chain Swap

Currencies
To configure the currency settings properly for trading, you need to ensure the following details are set correctly:

  • Currency Precision (Internal): This represents the decimal precision used for internal currency calculations within your system. It defines how many decimal points are used to display and calculate the currency values.

  • Trading Price Precision (Internal, Market Trading): This parameter specifies the decimal precision for trading prices within your system. It determines the level of accuracy for displaying buy and sell prices on the market.

  • Total (Volume) Precision: The total volume precision refers to the accuracy of the total traded volume in a transaction. It's important to align this precision with external exchanges to avoid discrepancies in volume calculations.

  • WhiteBit (External Exchange) Configurations: Make sure to align the currency precision and trading price precision settings with those of the WhiteBit external exchange. This ensures consistency and accuracy between your platform and the external exchange, reducing potential errors and confusion during trading activities.

    Currency precision [Internal] = Total (Volume) precision from WhiteBit [External exchange] configurations in order creation form

By verifying and matching these currency settings, you can maintain consistency in trading data and order details across platforms.

Market

Similarly, for off-chain swap operation details, it is essential that the Market settings in our system match those specified in the connected external exchange's settings. This consistency helps present financial data accurately and uniformly in the Admin Panel, minimizing discrepancies and misunderstandings that could arise from using different Market configurations.

By following these guidelines, you can ensure that the Off-Chain Swap feature functions correctly and that the data presented in the Admin Panel is reliable and accurate. This alignment is crucial for maintaining a smooth operation and preventing potential issues that could arise from misconfigured settings.

 

Example: Connecting the ADA/USDT Market for Off-Chain Swaps to an External Exchange

  1. Navigate to the Swap Page:

    1. Log in to your Admin Panel using your credentials

    2. From the main Menu options, locate and click on the "Operations" page

    3. In the side Menu options, find "On-/Off-chain Swap and Click on the "Configuration" option that appears under this section.

  2. Find the Market: / Use the Market Filter:
    a. On the Swap Configuration page, you will see the list of available markets as a table labeled "ID", “Base currency”, Quote currency”, “Off-Chain Swap“

    b. Above the Market table, you will find the "Filter" options.

    c. Use the Filter options to quickly locate any specific Market [ADA/USDT] from the list by entering relevant search criteria.

Screenshot from 2024-07-18 20-19-53.png

 

  1. Edit Off-Chain Swap Configuration:

    1. In the column labeled "Off-Chain Swap", find the row corresponding to the ADA/USDT market. In the "Off-Chain Swap" column, locate the row for the [ADA/USDT] market;

    2. Click the "Disable" button to view an information window that displays the full swap details for the disabled market;

    3. Click on the "pencil" icon in this row to open the "Edit Off Chain Swap" side menu on the right side of the page. Click the "pencil" icon in this row to open the "Edit Off Chain Swap" side menu on the right side of the page.

Screenshot from 2024-07-18 20-22-54.png

 

d. In the open window, you can configure the necessary settings for the swap.

 

  1. Configure Off-Chain Swap:
    In the "Edit Off Chain Swap" side menu, follow these steps to set up the external exchange connection:

 

  • Off-Chain Swap Service
    Select the available external exchange service for connection

 

  • Off-Chain Commission (%)
    Specify the off-chain commission that will be included in the quote from the external exchange.

    Formula for Commission: To calculate the commission for an off-chain swap with a connected external exchange that covers expenses and provides some profit for the internal exchange, you can use the following formula:

Total Commission = External Exchange Fee + Internal Handling Fee + Profit Margin

Where:

  • External Exchange Fee: The fee charged by the external exchange for the transaction;

  • Internal Handling Fee: A fixed or percentage-based fee to cover the operational costs of the internal exchange;

  • Profit Margin: A percentage added to ensure profitability for the internal exchange.

Example Calculation:

Assume:

  • External Exchange Fee: 0.1% (0.001)

  • Internal Handling Fee: 0.05% (0.0005)Profit Margin: 0.2% (0.002)

Total Commission = 0.001 + 0.0005 + 0.002 = 0.0035 (or 0.35%)

Adjusting for Good Rates

To ensure the rate remains competitive while covering expenses and providing profit, you might adjust the internal handling fee or profit margin based on market conditions. Here's a refined formula:

Total Commission} = External Exchange Fee + Internal Handling Fee + Market Adjustment Factor+ Profit Margin + Market Adjustment Factor

Where:

Market Adjustment Factor: A value between 0 and 1 that adjusts the internal fees based on current market conditions.

Using the formula with Market Adjustment:

Total Commission=External Exchange Fee+(Internal Handling Fee×(1+Market Adjustment Factor))+(Profit Margin×(1+Market Adjustment Factor))

By using this formula, the internal exchange can ensure that all expenses are covered, and a reasonable profit margin is maintained while keeping the rates competitive.

 

  • Off-chain price precision

Make sure the number of decimal places for prices matches the external market and the currency being used. This ensures that the prices shown are accurate and trustworthy.

Off-chain price precision [Internal] = Total (Volume) precision from WhiteBit [External exchange] configurations from order creation form

 

  • Minimum Amounts: The smallest amount you can use in a transaction to ensure it runs smoothly and is worth the effort.

 

ADA (Base Currency):

Minimum: 10 ADA

To ensure each transaction is efficient and profitable, every swap must involve at least 10 ADA.

 

USDT (Quote Currency):

Minimum: 5 USDT

To maintain transaction efficiency and profitability, each swap must involve at least 5 USDT.

 

  • Maximum Amounts: the largest amount you can use in a transaction to keep the system safe and ensure there is enough currency available for everyone.

ADA (Base Currency):

Maximum: 500 ADA

To manage risk and ensure liquidity, no swap can exceed 500 ADA.

 

USDT (Quote Currency):

Maximum: 300 USDT

To control risk and maintain liquidity, no swap can be more than 300 USDT.

By setting these limits, we ensure that transactions are efficient and secure for all users.

 

  • Enable Off-Chain Service:

    • To enable the service: Turn the toggle switch on;

    • To disable the service: Turn the toggle switch off.

    Toggling the service on or off controls whether the off-chain swap functionality is active for the selected market, allowing you to manage its availability based on your needs.

 

  • Save Configuration:

    After entering the required details, review the configuration for accuracy. Click the "Save" button to apply the changes.

 

 

Test the Configuration

Perform a test swap to verify the configuration is correct and the Off-Chain Swap functionality works as expected.

query { offChainSwapMarkets { id baseCurrencyId baseCurrency { id precision } quoteCurrencyId quoteCurrency { id precision } enabled offChainSwapPricePrecision offChainMinBaseAmount offChainMaxBaseAmount offChainMinQuoteAmount offChainMaxQuoteAmount } }

Get a Quote for an Off-Chain Swap

mutation { getOffChainSwapQuote( fromCurrencyId: "USDT" toCurrencyId: "ADA" # direction can be 'to' or 'from' direction: "from" amount: "8" ) { id fromCurrencyId toCurrencyId direction amount give receive createdAt expireAt status isActive isErrored } }

 

Monitor and Maintain Off-Chain Swap Service

To keep the Off-Chain Swap service running smoothly, it's important to regularly check and take care of its performance and functionality. Follow these steps:

Steps to Monitor and Maintain Off-Chain Swap Service

  1. Regular Monitoring:

    • Performance Metrics: Continuously track key performance indicators like transaction times, success rates, and error rates.

    • System Logs: Frequently review system logs for any unusual activity or irregularities in the swap processes.

    • User Feedback: Collect and analyze user feedback to identify any issues or areas for improvement.

  2. Liquidity Management:

    • Broker Balance: Ensure the broker's balance on the external exchange is sufficient to meet users' liquidity requests for swaps.

    • Real-Time Updates: Use real-time updates to monitor the broker's balance and address any shortfalls promptly.

  3. Routine Maintenance:

    • Software Updates: Regularly update the off-chain swap system with the latest software patches and enhancements.

    • Health Checks: Perform regular system health checks to ensure all components are working correctly.

  4. Incident Management:

    • Issue Resolution: Quickly resolve any issues that arise, such as failed transactions or system outages.

    • User Notifications: Promptly inform users about any service disruptions or maintenance activities.

Example Monitoring Metrics

  • Transaction Success Rate: Percentage of successful swaps.

  • Average Transaction Time: Time taken to complete a swap.

  • Broker Balance Levels: Amount of liquidity available on the external exchange.

  • Error Rate: Frequency of errors occurring during swaps.

Summary

By regularly monitoring and maintaining the off-chain swap service, you can ensure its reliability and efficiency. Keeping a sufficient broker balance on the external exchange is crucial to meet user liquidity requests and maintain a seamless swapping experience. Implementing these steps will help identify potential issues early and maintain high service standards.