Connecting Market Trading

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 a smooth and accurate display of trades and order information in the Admin Panel, the market settings should match those of the external exchange we're connected to. This ensures everything looks consistent and reduces the chance of any mix-ups or errors due to mismatched market settings.

Example for UNI / BTC market configuration before External Exchange connection

External Exchange Market configuration:

 

Screenshot from 2024-05-23 12-57-21.png

 

  1. Min. Order Amount in Base currency is 1 UNI

  2. Min. Order Total in Quote currency is 0.000082 BTC

  3. Taker fee 0.1% (Always in Quote currency for WhiteBit Broker)

  4. Maker fee 0.1% (Always in Quote currency for WhiteBit Broker)

  5. Price precision for order creation is 7 (Quote currency precision)

  6. Amount precision for order creation is 2 (Base currency precision)

  7. Total is in Quote currency with Quote currency precision (7)

 

Internal Exchange Market configuration settings parameters:

Screenshot from 2024-05-23 12-53-34.png
  1. Enabled
    During the editing process for trading, the functionality should be disabled. Additionally, the operator must confirm that there are no open orders for this market. This precaution ensures that no active trades are affected and maintains the integrity and accuracy of the trading system.

  2. Trading Bot
    There is no need to activate the trading bot for the external exchange. The external market should have enough liquidity for trading and dynamic trading. Ensuring sufficient liquidity in the external market is crucial for smooth and efficient trading operations, minimizing the risk of slippage and allowing for the execution of trades at desired prices.

  3. Market position
    The operator should select the market position to be reflected for display on the UI. This selection ensures that the chosen market position is accurately represented in the user interface on Trading page.

  4. Amount precision
    The amount precision should be no less than the amount precision from the external market and no less than the base currency precision. This ensures that the displayed amounts are accurate and consistent with both the external market standards and the base currency requirements, facilitating precise and reliable financial transactions.

  5. Minimum amount
    The minimum amount to create an order must be no less than the minimum specified in the external market settings. In determining this parameter, the operator must also consider the minimum amount (Min. Order Total) in the quote currency from the external exchange. This ensures compliance with the external market's requirements and guarantees that all orders meet the necessary thresholds for execution.

To calculate the minimum amount required for a limit order creation considering dynamic price changes, we need to ensure that the order amount and the order total meet the specified minimum conditions. Given the conditions:

  • Minimum Order Amount = 1 UNI

  • Minimum Order Total = 0.000082 BTC

  • Price = variable, denoted as ( P ) BTC per UNI

We can derive the following formulas:

  1. Minimum Order Amount Condition: The amount must be at least the minimum order amount.

    Amount≥1 UNI

  2. Minimum Order Total Condition: The total value of the order (Amount × Price) must be at least the minimum order total.

    Amount×P≥0.000082 BTC

Now, let's solve the second equation for the amount:

Therefore, the minimum amount required for the order creation must satisfy both conditions:

  1. The amount must be at least 1 UNI (from the minimum order amount condition).

  2. The amount must be greater than or equal to 0.000082 / P * UNI (from the minimum order total condition).

So, the formula for the minimum amount required for a limit order creation with dynamic price changes can be expressed as:

This formula ensures that the minimum order amount is always at least 1 UNI, but also accounts for the minimum order total condition based on the dynamic price ( P ).

  1. Price precision

    The price precision should be no less than the price precision from the external market and no less than the quote currency precision. This ensures that the displayed prices are accurate and consistent with both the external market standards and the requirements of the quote currency, facilitating precise and reliable financial transactions.

  2. Minimum price and Maximum price
    To establish formulas for the minimum and maximum prices on the market with dynamically changing prices, we must consider the following:

    1. Minimum Price: The minimum price should be no less than the precision specified by the external market.

    2. Maximum Price: There's no inherent maximum price, as it's usually constrained by market dynamics and liquidity.

    Given the dynamic nature of prices, we'll denote the precision as 𝑃𝑝Pp​ (precision from the external market) and 𝑃𝑞Pq​ (precision of the quote currency).

    The formula for the minimum price can be expressed as:

    Minimum Price=𝑃𝑝×10−𝑃𝑞Minimum Price=Pp​×10−Pq

    This ensures that the price precision is no less than the precision specified by the external market and the precision of the quote currency.

    As for the maximum price, it's not typically constrained by precision but rather by market dynamics. However, we can still provide a formula based on factors such as the highest observed price or a percentage increase over time. For example:

    Maximum Price=Highest observed price×(1+Percentage Increase)Maximum Price=Highest observed price×(1+Percentage Increase)

    This formula allows for a maximum price that reflects the dynamics of the market, potentially accounting for trends and volatility.

    Ultimately, the minimum price ensures precision compliance, while the maximum price is more influenced by market conditions.

  3. Maker fee (%) and Taker fee (%)
    To determine the maker and taker fees on a market connected to an external exchange, which must cover expenses for broker trading on that exchange, we need to consider the costs incurred by the broker and ensure that the fees are sufficient to cover these expenses. Let's denote:

    • Broker ExpensesBroker Expenses: The total expenses incurred by the broker for trading on the external exchange.

    • Maker FeeMaker Fee: The percentage fee charged to makers on the market.

    • Taker FeeTaker Fee: The percentage fee charged to takers on the market.

    We can use the following formulas to calculate the maker and taker fees:

Where:

  1. Total Maker VolumeTotal Maker Volume: The total volume generated by maker trades on the market.

  2. Total Taker VolumeTotal Taker Volume: The total volume generated by taker trades on the market.

These formulas ensure that the fees charged to makers and takers are proportional to the expenses incurred by the broker for trading on the external exchange, and they are designed to cover these expenses while maintaining fairness and competitiveness in the market.

 

External Exchange Connection

To ensure a smooth integration with an external exchange, here's a step-by-step process for UNI / BTC market connection:

  1. Disable Trading to Cancel All Open Orders:

    • Disable trading functionality to cancel all open orders associated with the market. This step ensures that no active orders are left unresolved during the integration process.

  2. Check for Open Orders:

    • Perform a check to ensure there are no remaining open orders in the system. This verification helps prevent any potential conflicts or discrepancies after the trading functionality is re-enabled.

query PublicOrderBook($market: String!){ publicOrderBook(market: $market) { buy { price amount cumulativeAmount } sell { price amount cumulativeAmount } } }
  1. Configure Trading According to External Exchange Settings:

    • Adjust the trading configurations based on the settings provided by the external exchange. This includes parameters such as minimum order amounts, price precision, trading fees, and any other relevant settings necessary for seamless trading operations.

  1. Connect to External Exchange:

    • Establish a connection with the external exchange using the configured settings. This connection enables communication between the trading platform and the exchange, facilitating real-time data retrieval and order execution.

A. Select External Exchange by pressing the “Edit” button in the ‘External exchanges’ portion

B. Press the “Update external exchanges” button. As a result, you should see the connected Exchange in ‘External exchanges’ portion:

  1. Enable Trading for Market:

    • Once the connection is successfully established and configurations are in place, enable trading functionality for the specific market. This action allows users to initiate new trades and interact with the connected external exchange seamlessly.

By following these steps, you can effectively integrate and connect to an external exchange while ensuring a smooth transition and reliable trading experience for users.

 

Make sure everything is working correctly

 

To ensure that everything is working correctly and all necessary functionalities are in place for seamless trading operations, you'll need to check correctly working for the following components:

  1. Market Dynamics Subscription and Query with 24-Hour Changes:

    • A subscription mechanism to receive real-time data for market dynamics, including 24-hour changes in price and volume. This data should be continuously updated to reflect the latest market conditions.

subscription MarketDynamics($market: String){ marketDynamics(market: $market){ marketId startPrice lastPrice amount24h lowPrice highPrice } }

 

query GetMarketDynamics($market: String!) { marketDynamics(market: $market) { startPrice lastPrice amount24h lowPrice highPrice } }

 

  1. Public Order Book Subscription and Query:

    • A subscription system to fetch and display the public order book data. This includes both the buy and sell orders at various price levels, allowing users to assess market depth and liquidity.

 

 

  1. Public Trades Subscription and Query:

    • A subscription to receive public trade data, which includes information about executed trades such as price, amount, and timestamp. This data helps users track recent market activity and trade history.

 

 

  1. Trading View Chart Integration:

    • A Trading View chart component into the user interface. Ensure that the chart dynamically updates based on the trade operations made, displaying relevant market data such as price movements, volume, and trading indicators.

  2. Ensure Correct Functionality:

    • Thoroughly test each component to verify that data is being received accurately and displayed correctly in the user interface. Pay special attention to data synchronization and real-time updates to ensure smooth user experience.

With these components and their correct functionality, users will have access to comprehensive market data and trading tools, enabling them to make informed decisions and execute trades effectively on the platform.