﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Forum. StockSharp</title>
  <id>https://stocksharp.com/handlers/atom.ashx?category=forum&amp;page=3</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-04-30T09:30:16Z</updated>
  <logo>https://stocksharp.com/images/logo.png</logo>
  <link href="https://stocksharp.com/handlers/atom.ashx?category=forum&amp;page=3" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.com/topic/25595/</id>
    <title type="text">Measuring Risk and Return - An Introduction to Markowitz Theory</title>
    <published>2024-03-21T03:04:52Z</published>
    <updated>2024-03-21T03:04:52Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#data" />
    <category term="#fmz" />
    <category term="#python" />
    <category term="#risk" />
    <category term="#crypto" />
    <category term="#Markowitz" />
    <category term="#MPT" />
    <category term="#return" />
    <category term="#asset" />
    <content type="html">Last week, when introducing [How to Measure Position Risk - An Introduction to the VaR Method](https://www.fmz.com/bbs-topic/10255), it was mentioned that the risk of a portfolio is not equal to the risks of individual assets and is related to their price correlation. Taking two assets as an example, if their positive correlation is very strong, meaning they rise and fall together, then diversifying investments will not reduce risk. If there&amp;#39;s a strong negative correlation, diversified investments can reduce risk significantly. The natural question then arises: how do we maximize returns at a certain level of risk when investing in a portfolio? This leads us to Markowitz Theory, which we are going to introduce today.&lt;br /&gt;&lt;br /&gt;The Modern Portfolio Theory (MPT), proposed by Harry Markowitz in 1952, is a mathematical framework for portfolio selection. It aims to maximize expected returns by choosing different combinations of risk assets while controlling risk. The core idea is that the prices of assets do not move completely in sync with each other (i.e., there is incomplete correlation between assets), and overall investment risk can be reduced through diversified asset allocation.&lt;br /&gt;&lt;br /&gt;### The Key Concept of Markowitz Theory&lt;br /&gt;1. **Expected Return Rate**: This is the return that investors expect to receive from holding assets or an investment portfolio, usually predicted based on historical return data.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149420
" title="https://stocksharp.com/file/149420
"&gt;https://stocksharp.com/file/149420
&lt;/a&gt;&lt;br /&gt;Where, &lt;a href="https://stocksharp.com/file/149421 " title="https://stocksharp.com/file/149421 "&gt;https://stocksharp.com/file/149421 &lt;/a&gt;is the expected return of the portfolio, &lt;a href="https://stocksharp.com/file/149422 " title="https://stocksharp.com/file/149422 "&gt;https://stocksharp.com/file/149422 &lt;/a&gt;is the weight of the i-th asset in the portfolio, &lt;a href="https://stocksharp.com/file/149423 " title="https://stocksharp.com/file/149423 "&gt;https://stocksharp.com/file/149423 &lt;/a&gt;is the expected return of the i-th asset.&lt;br /&gt;&lt;br /&gt;2. **Risk (Volatility or Standard Deviation)**: Used to measure the uncertainty of investment returns or the volatility of investments.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149424
" title="https://stocksharp.com/file/149424
"&gt;https://stocksharp.com/file/149424
&lt;/a&gt;&lt;br /&gt;Where, &lt;a href="https://stocksharp.com/file/149425 " title="https://stocksharp.com/file/149425 "&gt;https://stocksharp.com/file/149425 &lt;/a&gt;represents the total risk of the portfolio, &lt;a href="https://stocksharp.com/file/149426 " title="https://stocksharp.com/file/149426 "&gt;https://stocksharp.com/file/149426 &lt;/a&gt;is the covariance of asset i and asset j, which measures the price change relationship between these two assets.&lt;br /&gt;&lt;br /&gt;3. **Covariance**: Measures the mutual relationship between price changes of two assets.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149427
" title="https://stocksharp.com/file/149427
"&gt;https://stocksharp.com/file/149427
&lt;/a&gt;&lt;br /&gt;Where, &lt;a href="https://stocksharp.com/file/149428 " title="https://stocksharp.com/file/149428 "&gt;https://stocksharp.com/file/149428 &lt;/a&gt;is the correlation coefficient of asset i and asset j, &lt;a href="https://stocksharp.com/file/149432 " title="https://stocksharp.com/file/149432 "&gt;https://stocksharp.com/file/149432 &lt;/a&gt;and &lt;a href="https://stocksharp.com/file/149429 " title="https://stocksharp.com/file/149429 "&gt;https://stocksharp.com/file/149429 &lt;/a&gt;are respectively the standard deviations of asset i and asset j.&lt;br /&gt;&lt;br /&gt;4. **Efficient Frontier**: In the risk-return coordinate system, the efficient frontier is the set of investment portfolios that can provide the maximum expected return at a given level of risk.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149430
" title="https://stocksharp.com/file/149430
"&gt;https://stocksharp.com/file/149430
&lt;/a&gt;&lt;br /&gt;The diagram above is an illustration of an efficient frontier, where each point represents a different weighted investment portfolio. The x-axis denotes volatility, which equates to the level of risk, while the y-axis signifies return rate. Clearly, our focus lies on the upper edge of the graph as it achieves the highest returns at equivalent levels of risk.&lt;br /&gt;&lt;br /&gt;In quantitative trading and portfolio management, applying these principles requires statistical analysis of historical data and using mathematical models to estimate expected returns, standard deviations and covariances for various assets. Then optimization techniques are used to find the best asset weight allocation. This process often involves complex mathematical operations and extensive computer processing - this is why quantitative analysis has become so important in modern finance. Next, we will illustrate how to optimize with specific Python examples.&lt;br /&gt;&lt;br /&gt;### Python Code Example for Finding the Optimal Combination Using Simulation Method&lt;br /&gt;Calculating the Markowitz optimal portfolio is a multi-step process, involving several key steps, such as data preparation, portfolio simulation, and indicator calculation. Please refer to: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAUHMBT0RDOYV3HRm60Xu-4dDADxIxONR_JbWY-WOcZ2MZj5NHr6q4_LIRwrxE3Y0SQJ4Z-hJb0e4bQg0r070V4iNaicoSYA5e4-tGvB6cFgQK2RwhacsOWe_3S5-LMtaA" title="https://plotly.com/python/v3/ipython-notebooks/markowitz-portfolio-optimization/
"&gt;https://plotly.com/pytho...portfolio-optimization/
&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;1. **Obtain market data**:&lt;br /&gt;&lt;br /&gt;  Through the ```get_data``` function, obtain the historical price data of the selected digital currency. This is the necessary data for calculating returns and risks, which are used to build investment portfolios and calculate Sharpe ratios.&lt;br /&gt;&lt;br /&gt;2. **Calculate Return Rate and Risk**:&lt;br /&gt;&lt;br /&gt;  The ```calculate_returns_risk``` function was used to compute the annualized returns and annualized risk (standard deviation) for each digital currency. This is done to quantify the historical performance of each asset for use in an optimal portfolio.&lt;br /&gt;&lt;br /&gt;3. **Calculate Markowitz Optimal Portfolio**:&lt;br /&gt;&lt;br /&gt;  The ```calculate_optimal_portfolio``` function was used to simulate multiple investment portfolios. In each simulation, asset weights were randomly generated and then the expected return and risk of the portfolio were calculated based on these weights.&lt;br /&gt;  By randomly generating combinations with different weights, it is possible to explore multiple potential investment portfolios in order to find the optimal one. This is one of the core ideas of Markowitz&amp;#39;s portfolio theory.&lt;br /&gt;&lt;br /&gt;The purpose of the entire process is to find the investment portfolio that yields the best expected returns at a given level of risk. By simulating multiple possible combinations, investors can better understand the performance of different configurations and choose the combination that best suits their investment goals and risk tolerance. This method helps optimize investment decisions, making investments more effective.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;import numpy as np&lt;br /&gt;import pandas as pd&lt;br /&gt;import requests&lt;br /&gt;import matplotlib.pyplot as plt&lt;br /&gt;&lt;br /&gt;# Obtain market data&lt;br /&gt;def get_data(symbols):&lt;br /&gt;    data = []&lt;br /&gt;    for symbol in symbols:&lt;br /&gt;        url = &amp;#39;https://api.binance.com/api/v3/klines?symbol=%s&amp;amp;interval=%s&amp;amp;limit=1000&amp;#39;%(symbol,&amp;#39;1d&amp;#39;)&lt;br /&gt;        res = requests.get(url)&lt;br /&gt;        data.append([float(line[4]) for line in res.json()])&lt;br /&gt;    return data&lt;br /&gt;&lt;br /&gt;def calculate_returns_risk(data):&lt;br /&gt;    returns = []&lt;br /&gt;    risks = []&lt;br /&gt;&lt;br /&gt;    for d in data:&lt;br /&gt;        daily_returns = np.diff(d) / d[:-1]&lt;br /&gt;        annualized_return = np.mean(daily_returns) * 365&lt;br /&gt;        annualized_volatility = np.std(daily_returns) * np.sqrt(365)&lt;br /&gt;&lt;br /&gt;        returns.append(annualized_return)&lt;br /&gt;        risks.append(annualized_volatility)&lt;br /&gt;&lt;br /&gt;    return np.array(returns), np.array(risks)&lt;br /&gt;&lt;br /&gt;# Calculate Markowitz Optimal Portfolio&lt;br /&gt;def calculate_optimal_portfolio(returns, risks):&lt;br /&gt;    n_assets = len(returns)&lt;br /&gt;    num_portfolios = 3000&lt;br /&gt;&lt;br /&gt;    results = np.zeros((4, num_portfolios), dtype=object) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    for i in range(num_portfolios):&lt;br /&gt;        weights = np.random.random(n_assets)&lt;br /&gt;        weights /= np.sum(weights)&lt;br /&gt;&lt;br /&gt;        portfolio_return = np.sum(returns * weights)&lt;br /&gt;        portfolio_risk = np.sqrt(np.dot(weights.T, np.dot(np.cov(returns, rowvar=False), weights)))&lt;br /&gt;&lt;br /&gt;        results[0, i] = portfolio_return&lt;br /&gt;        results[1, i] = portfolio_risk&lt;br /&gt;        results[2, i] = portfolio_return / portfolio_risk&lt;br /&gt;        results[3, i] = list(weights) # Convert weights to a list&lt;br /&gt;&lt;br /&gt;    return results&lt;br /&gt;&lt;br /&gt;symbols = [&amp;#39;BTCUSDT&amp;#39;,&amp;#39;ETHUSDT&amp;#39;, &amp;#39;BNBUSDT&amp;#39;,&amp;#39;LINKUSDT&amp;#39;,&amp;#39;BCHUSDT&amp;#39;,&amp;#39;LTCUSDT&amp;#39;]&lt;br /&gt;data = get_data(symbols)&lt;br /&gt;&lt;br /&gt;returns, risks = calculate_returns_risk(data)&lt;br /&gt;optimal_portfolios = calculate_optimal_portfolio(returns, risks)&lt;br /&gt;&lt;br /&gt;max_sharpe_idx = np.argmax(optimal_portfolios[2])&lt;br /&gt;optimal_return = optimal_portfolios[0, max_sharpe_idx]&lt;br /&gt;optimal_risk = optimal_portfolios[1, max_sharpe_idx]&lt;br /&gt;optimal_weights = optimal_portfolios[3, max_sharpe_idx]&lt;br /&gt;&lt;br /&gt;# Output results&lt;br /&gt;print(&amp;quot;Optimal combination:&amp;quot;)&lt;br /&gt;for i in range(len(symbols)):&lt;br /&gt;    print(f&amp;quot;{symbols[i]} Weight: {optimal_weights[i]:.4f}&amp;quot;)&lt;br /&gt;&lt;br /&gt;print(f&amp;quot;Expected return rate: {optimal_return:.4f}&amp;quot;)&lt;br /&gt;print(f&amp;quot;Expected risk (standard deviation): {optimal_risk:.4f}&amp;quot;)&lt;br /&gt;print(f&amp;quot;Sharpe ratio: {optimal_return / optimal_risk:.4f}&amp;quot;)&lt;br /&gt;&lt;br /&gt;# Visualized investment portfolio&lt;br /&gt;plt.figure(figsize=(10, 5))&lt;br /&gt;plt.scatter(optimal_portfolios[1], optimal_portfolios[0], c=optimal_portfolios[2], marker=&amp;#39;o&amp;#39;, s=3)&lt;br /&gt;plt.title(&amp;#39;portfolio&amp;#39;)&lt;br /&gt;plt.xlabel(&amp;#39;std&amp;#39;)&lt;br /&gt;plt.ylabel(&amp;#39;return&amp;#39;)&lt;br /&gt;plt.colorbar(label=&amp;#39;sharp&amp;#39;)&lt;br /&gt;plt.show()&lt;br /&gt;```&lt;br /&gt;Final output result:&lt;br /&gt;Optimal combination:&lt;br /&gt;Weight of BTCUSDT: 0.0721&lt;br /&gt;Weight of ETHUSDT: 0.2704&lt;br /&gt;Weight of BNBUSDT: 0.3646&lt;br /&gt;Weight of LINKUSDT: 0.1892&lt;br /&gt;Weight of BCHUSDT: 0.0829&lt;br /&gt;Weight of LTCUSDT: 0.0209&lt;br /&gt;Expected return rate: 0.4195&lt;br /&gt;Expected risk (standard deviation): 0.1219&lt;br /&gt;Sharpe ratio: 3.4403&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149431
" title="https://stocksharp.com/file/149431
"&gt;https://stocksharp.com/file/149431
&lt;/a&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y60yuzHEw3YKQQfs6AuOb9k5xBqwFgVWHPNNNoTBpmSjIwVoBPMr_yJmBachsA7MjzwT4lF6wNksWlmoAmDPfjwVQHKmxZAlf7udVmWNxpLvI" title="https://blog.mathquant.com/2023/11/13/measuring-risk-and-return-an-introduction-to-markowitz-theory.html"&gt;https://blog.mathquant.c...to-markowitz-theory.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25594/</id>
    <title type="text">Cracking the Code: Exploring Order Book Balance in Centralized Exchanges</title>
    <published>2024-03-21T01:10:21Z</published>
    <updated>2024-03-21T01:10:21Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#data" />
    <category term="#market" />
    <category term="#fmz" />
    <category term="#exchange" />
    <category term="#binance" />
    <category term="#crypto" />
    <category term="#order" />
    <content type="html">Recently, I have summarized some key insights from papers studying limit order books. You will learn how to measure the imbalance of transaction volume in the order book and its predictive ability for price trends. This article explores methods of using order book data to model price changes.&lt;br /&gt;&lt;br /&gt;### First, let&amp;#39;s talk about the order book.&lt;br /&gt;Exchange order book balance refers to the relative balance state between buy and sell orders in an exchange. The order book is a real-time record of all pending buy and sell orders on the market. This includes orders from buyers and sellers who are willing to trade at different prices.&lt;br /&gt;&lt;br /&gt;Below are some key concepts related to exchange order book balance:&lt;br /&gt;&lt;br /&gt;- Buyer and Seller Orders: Buyer orders in the order book represent investors willing to purchase assets at a specific price, while seller orders represent investors willing to sell assets at a specific price.&lt;br /&gt;&lt;br /&gt;- Order Book Depth: Order book depth refers to the number of orders on both the buyer and seller sides. A greater depth indicates there are more buy and sell orders in the market, which may be more liquid.&lt;br /&gt;&lt;br /&gt;- Transaction Price and Transaction Volume: The transaction price is the price of the most recent trade, while the transaction volume is the quantity of assets traded at that price. The transaction price and volume are determined by the competition between buyers and sellers in the order book.&lt;br /&gt;&lt;br /&gt;- Order Book Imbalance: Order book imbalance refers to the discrepancy between the number of buy and sell orders or total transaction volume. This can be determined by examining the depth of the order book, if one side has significantly more orders than the other, there may be an order book imbalance.&lt;br /&gt;&lt;br /&gt;- Market Depth Chart: The market depth chart graphically presents the depth and balance of the order book. Typically, the number of orders from buyers and sellers is displayed on the price level in a bar chart or other visual ways.&lt;br /&gt;&lt;br /&gt;- Factors Affecting the Price: The balance of the order book directly affects market prices. If there are more buy orders, it may push up the price; on the contrary, if there are more sell orders, it may cause a drop in price.&lt;br /&gt;&lt;br /&gt;- High-frequency Trading and Algorithmic Trading: Order book balance is crucial for high-frequency trading and algorithmic trading, as they rely on real-time order book data to make decisions, aiming to seize market opportunities quickly.&lt;br /&gt;&lt;br /&gt;Understanding the balance of order books is important for investors, traders, and market analysts, because it provides useful information about market liquidity, potential price direction, and market trends.&lt;br /&gt;&lt;br /&gt;### Imbalance in Trading Volume&lt;br /&gt;A key idea when analyzing limit order books is to determine whether the overall market tends to buy or sell. This concept is known as imbalance in trading volume.&lt;br /&gt;&lt;br /&gt;The imbalance in trading volume at time t is defined as:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149405
" title="https://stocksharp.com/file/149405
"&gt;https://stocksharp.com/file/149405
&lt;/a&gt;&lt;br /&gt;Where, &lt;a href="https://stocksharp.com/file/149406 " title="https://stocksharp.com/file/149406 "&gt;https://stocksharp.com/file/149406 &lt;/a&gt;represents the transaction volume of the best buy order at time t, &lt;a href="https://stocksharp.com/file/149407 " title="https://stocksharp.com/file/149407 "&gt;https://stocksharp.com/file/149407 &lt;/a&gt;represents the transaction volume of the best sell order at time t. We can interpret ρt close to 1 as strong buying pressure, and ρt close to -1 as strong selling pressure. This only considers the transaction volumes of orders placed at the best buy price and best sell price, that is, L1 order book.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149408
" title="https://stocksharp.com/file/149408
"&gt;https://stocksharp.com/file/149408
&lt;/a&gt;&lt;br /&gt;Imbalance in trading volume and price changes. The graph shows the imbalance of tiered trading volumes (x-axis) and the average value of future price movements, standardized by price difference (y-axis). The dataset is a quarter&amp;#39;s order flow from a certain market. There seems to be a linear relationship between first-level order imbalance and future price changes. However, on average, future price changes are within the bid-ask spread.&lt;br /&gt;&lt;br /&gt;The imbalance in trading volume ρt will be divided into the following three paragraphs:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149409
" title="https://stocksharp.com/file/149409
"&gt;https://stocksharp.com/file/149409
&lt;/a&gt;&lt;br /&gt;It was discovered that these segments can predict future price changes:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149410
" title="https://stocksharp.com/file/149410
"&gt;https://stocksharp.com/file/149410
&lt;/a&gt;&lt;br /&gt;Regarding the predictive ability of volume imbalance, an analysis was conducted on the tick-by-tick order book of a certain commodity from January 2014 to December 2014. For each arriving market order (MO), the volume imbalance was recorded and segmented according to the number of ticks in which the mid-price changed within the next 10 milliseconds. The chart shows the distribution and mid-price changes for each segment. We can see that positive price changes are more likely to occur before order books with greater buying pressure. Similarly, negative changes are more likely to occur before order books with greater selling pressure.&lt;br /&gt;&lt;br /&gt;### Order Flow Imbalance&lt;br /&gt;&lt;br /&gt;The imbalance of trading volume focuses on the total trading volume in the limit order book. One drawback is that some of this volume may come from old orders, which contain less relevant information. We can instead focus on the trading volume of recent orders. This concept is known as order flow imbalance. You can achieve this by tracking individual markets and limit orders (requires Level 3 data) or observing changes in the limit order book.&lt;br /&gt;&lt;br /&gt;Since Level 3 data is expensive and usually only available to institutional traders, we will focus on changes in the limit order book.&lt;br /&gt;&lt;br /&gt;We can calculate the order flow imbalance by looking at how much the trading volumes have moved at best bid price and best ask price. The change in trading volume at best bid price is:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149411
" title="https://stocksharp.com/file/149411
"&gt;https://stocksharp.com/file/149411
&lt;/a&gt;&lt;br /&gt;This is a function involving three scenarios. The first scenario is, if the best buying price is higher than the previous best buying price, then all transaction volumes are new transaction volumes.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149412
" title="https://stocksharp.com/file/149412
"&gt;https://stocksharp.com/file/149412
&lt;/a&gt;&lt;br /&gt;The second scenario is, if the best buying price is the same as the previous best buying price, then the new transaction volume is the difference between the current total transaction volume and the previous total transaction volume.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149413
" title="https://stocksharp.com/file/149413
"&gt;https://stocksharp.com/file/149413
&lt;/a&gt;&lt;br /&gt;The third scenario is, if the best buying price is lower than the previous best buying price, then all previous orders have been traded and are no longer in the order book.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149414
" title="https://stocksharp.com/file/149414
"&gt;https://stocksharp.com/file/149414
&lt;/a&gt;&lt;br /&gt;The calculation method for the change in transaction volume at the best selling price is similar:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149415
" title="https://stocksharp.com/file/149415
"&gt;https://stocksharp.com/file/149415
&lt;/a&gt;&lt;br /&gt;The net order flow imbalance (OFI) at time t is given by the following formula:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149416
" title="https://stocksharp.com/file/149416
"&gt;https://stocksharp.com/file/149416
&lt;/a&gt;&lt;br /&gt;This will be a positive value when there are more buy orders, and a negative value when there are more sell orders. It measures both the quantity and direction of the transaction volume. In the previous part, order imbalance only measured direction without measuring the quantity of transactions.&lt;br /&gt;&lt;br /&gt;You can add these values to get the net order flow imbalance (OFI) over a period of time:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149418
" title="https://stocksharp.com/file/149418
"&gt;https://stocksharp.com/file/149418
&lt;/a&gt;&lt;br /&gt;Use regression models to test whether order flow imbalance contains information about future price changes:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149417
" title="https://stocksharp.com/file/149417
"&gt;https://stocksharp.com/file/149417
&lt;/a&gt;&lt;br /&gt;The calculated OFI value above focuses on the best buying price and selling price. In part 4, the values of the top 5 best prices were also calculated, providing 5 inputs instead of just one. They found that a deep study of the order book can provide new information for future price changes.&lt;br /&gt;&lt;br /&gt;### Summary&lt;br /&gt;Here, I have summarized some key insights from papers studying the order volume in limit order books. These papers indicate that the order book contains information highly predictive of future price changes. However, these changes cannot overcome the bid-ask spread.&lt;br /&gt;&lt;br /&gt;I have added links to the papers in the references section. Please refer to them for more detailed information.&lt;br /&gt;&lt;br /&gt;References &amp;amp; Notes&lt;br /&gt;&lt;br /&gt;- &amp;#193;lvaro Cartea, Ryan Francis Donnelly, and Sebastian Jaimungal: &amp;quot;Enhancing Trading Strategies with Order Book Signals&amp;quot; Applied Mathematical Finance 25(1) pp. 1–35 (2018)&lt;br /&gt;- Alexander Lipton, Umberto Pesavento, and Michael G Sotiropoulos: &amp;quot;Trade arrival dynamics and quote imbalance in a limit order book&amp;quot; arXiv (2013)&lt;br /&gt;- &amp;#193;lvaro Cartea, Sebastian Jaimungal, and J. Penalva: &amp;quot;Algorithmic and high-frequency trading.&amp;quot; Cambridge University Press&lt;br /&gt;- Ke Xu, Martin D. Gould, and Sam D. Howison: &amp;quot;Multi-Level Order-Flow Imbalance in a Limit Order Book&amp;quot; arXiv (2019)&lt;br /&gt;&lt;br /&gt;Reprinted from: Author ~ {Leigh Ford, Adrian}.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y62i5LOkGofAD0pQKW1rZ8lJmxoRx8amKP1FBwVsQEbvwqSTlu_iSjVWCUm_iGnu4iLYeeOXrZskzBXrbRPWHTN6Uoty6nuW8jRnph-_OwyEWuOoYklCxUxNY-B9PXUuZSw" title="https://blog.mathquant.com/2023/11/13/a-brief-discussion-on-the-balance-of-order-books-in-centralized-exchanges.html"&gt;https://blog.mathquant.c...ntralized-exchanges.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25590/</id>
    <title type="text">Decoding Trends: Exploring the Correlation Between Currency Fluctuations and Bitcoin Price Movements</title>
    <published>2024-03-20T09:12:58Z</published>
    <updated>2024-03-20T09:12:58Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#strategy" />
    <category term="#data" />
    <category term="#market" />
    <category term="#analysis" />
    <category term="#fmz" />
    <category term="#bitcoin" />
    <category term="#formula" />
    <category term="#crypto" />
    <category term="#Ethereum" />
    <content type="html">In previous articles, we discussed a common phenomenon in the digital currency market: most digital currencies, especially those that follow the price fluctuations of Bitcoin and Ethereum, often show a trend of rising and falling together. This phenomenon reveals their high correlation with mainstream currencies. However, the degree of correlation between different digital currencies also varies. So how does this difference in correlation affect the market performance of each currency? In this article, we will use the bull market in the second half of 2023 as an example to explore this issue.&lt;br /&gt;&lt;br /&gt;### The Synchronous Origin of the Digital Currency Market&lt;br /&gt;The digital currency market is known for its volatility and uncertainty. Bitcoin and Ethereum, as the two giants in the market, often play a leading role in price trends. Most small or emerging digital currencies, in order to maintain market competitiveness and trading activity, often keep a certain degree of price synchronization with these mainstream currencies, especially those coins made by project parties. This synchronicity reflects the psychological expectations and trading strategies of market participants, which are important considerations in designing quantitative trading strategies.&lt;br /&gt;&lt;br /&gt;### Formula and Calculation Method of Correlation&lt;br /&gt;In the field of quantitative trading, the measurement of correlation is achieved through statistical methods. The most commonly used measure is the Pearson correlation coefficient, which measures the degree of linear correlation between two variables. Here are some core concepts and calculation methods:&lt;br /&gt;&lt;br /&gt;The range of the Pearson Correlation Coefficient (denoted as r) is from -1 to +1, where +1 indicates a perfect positive correlation, -1 indicates a perfect negative correlation, and 0 indicates no linear relationship. The formula for calculating this coefficient is as follows:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149366
" title="https://stocksharp.com/file/149366
"&gt;https://stocksharp.com/file/149366
&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Among them, &lt;a href="https://stocksharp.com/file/149367 " title="https://stocksharp.com/file/149367 "&gt;https://stocksharp.com/file/149367 &lt;/a&gt;and &lt;a href="https://stocksharp.com/file/149368 " title="https://stocksharp.com/file/149368 "&gt;https://stocksharp.com/file/149368 &lt;/a&gt;are the observed values of two random variables, &lt;a href="https://stocksharp.com/file/149369 " title="https://stocksharp.com/file/149369 "&gt;https://stocksharp.com/file/149369 &lt;/a&gt;and &lt;a href="https://stocksharp.com/file/149370 " title="https://stocksharp.com/file/149370 "&gt;https://stocksharp.com/file/149370 &lt;/a&gt;are the average values of these two random variables respectively. Using Python scientific computing related packages, it&amp;#39;s easy to calculate correlation.&lt;br /&gt;&lt;br /&gt;### Data Collection&lt;br /&gt;This article has collected the 4h K-line data for the entire year of 2023 from Binance, selecting 144 currencies that were listed on January 1st. The specific code to download the data is as follows:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;import requests&lt;br /&gt;from datetime import date,datetime&lt;br /&gt;import time&lt;br /&gt;import pandas as pd&lt;br /&gt;import numpy as np&lt;br /&gt;import matplotlib.pyplot as plt&lt;br /&gt;&lt;br /&gt;ticker = requests.get(&amp;#39;https://fapi.binance.com/fapi/v1/ticker/24hr&amp;#39;)&lt;br /&gt;ticker = ticker.json()&lt;br /&gt;sort_symbols = [k[&amp;#39;symbol&amp;#39;][:-4] for k in sorted(ticker, key=lambda x :-float(x[&amp;#39;quoteVolume&amp;#39;])) if k[&amp;#39;symbol&amp;#39;][-4:] == &amp;#39;USDT&amp;#39;]&lt;br /&gt;&lt;br /&gt;def GetKlines(symbol=&amp;#39;BTCUSDT&amp;#39;,start=&amp;#39;2020-8-10&amp;#39;,end=&amp;#39;2023-8-10&amp;#39;,period=&amp;#39;1h&amp;#39;,base=&amp;#39;fapi&amp;#39;,v = &amp;#39;v1&amp;#39;):&lt;br /&gt;    Klines = []&lt;br /&gt;    start_time = int(time.mktime(datetime.strptime(start, &amp;quot;%Y-%m-%d&amp;quot;).timetuple()))*1000 + 8*60*60*1000&lt;br /&gt;    end_time =  min(int(time.mktime(datetime.strptime(end, &amp;quot;%Y-%m-%d&amp;quot;).timetuple()))*1000 + 8*60*60*1000,time.time()*1000)&lt;br /&gt;    intervel_map = {&amp;#39;m&amp;#39;:60*1000,&amp;#39;h&amp;#39;:60*60*1000,&amp;#39;d&amp;#39;:24*60*60*1000}&lt;br /&gt;    while start_time &amp;lt; end_time:&lt;br /&gt;        time.sleep(0.5)&lt;br /&gt;        mid_time = start_time+1000*int(period[:-1])*intervel_map[period[-1]]&lt;br /&gt;        url = &amp;#39;https://&amp;#39;+base+&amp;#39;.binance.com/&amp;#39;+base+&amp;#39;/&amp;#39;+v+&amp;#39;/klines?symbol=%s&amp;amp;interval=%s&amp;amp;startTime=%s&amp;amp;endTime=%s&amp;amp;limit=1000&amp;#39;%(symbol,period,start_time,mid_time)&lt;br /&gt;        res = requests.get(url)&lt;br /&gt;        res_list = res.json()&lt;br /&gt;        if type(res_list) == list and len(res_list) &amp;gt; 0:&lt;br /&gt;            start_time = res_list[-1][0]+int(period[:-1])*intervel_map[period[-1]]&lt;br /&gt;            Klines += res_list&lt;br /&gt;        if type(res_list) == list and len(res_list) == 0:&lt;br /&gt;            start_time = start_time+1000*int(period[:-1])*intervel_map[period[-1]]&lt;br /&gt;        if mid_time &amp;gt;= end_time:&lt;br /&gt;            break&lt;br /&gt;    df = pd.DataFrame(Klines,columns=[&amp;#39;time&amp;#39;,&amp;#39;open&amp;#39;,&amp;#39;high&amp;#39;,&amp;#39;low&amp;#39;,&amp;#39;close&amp;#39;,&amp;#39;amount&amp;#39;,&amp;#39;end_time&amp;#39;,&amp;#39;volume&amp;#39;,&amp;#39;count&amp;#39;,&amp;#39;buy_amount&amp;#39;,&amp;#39;buy_volume&amp;#39;,&amp;#39;null&amp;#39;]).astype(&amp;#39;float&amp;#39;)&lt;br /&gt;    df.index = pd.to_datetime(df.time,unit=&amp;#39;ms&amp;#39;)&lt;br /&gt;    return df&lt;br /&gt;&lt;br /&gt;start_date = &amp;#39;2023-01-01&amp;#39;&lt;br /&gt;end_date   = &amp;#39;2023-11-16&amp;#39;&lt;br /&gt;period = &amp;#39;4h&amp;#39;&lt;br /&gt;df_dict = {}&lt;br /&gt;&lt;br /&gt;for symbol in sort_symbols:   &lt;br /&gt;    print(symbol)&lt;br /&gt;    df_s = GetKlines(symbol=symbol+&amp;#39;USDT&amp;#39;,start=start_date,end=end_date,period=period)&lt;br /&gt;    if not df_s.empty:&lt;br /&gt;        df_dict[symbol] = df_s&lt;br /&gt;&lt;br /&gt;df_close = pd.DataFrame(index=pd.date_range(start=start_date, end=end_date, freq=period),columns=df_dict.keys())&lt;br /&gt;for symbol in symbols:&lt;br /&gt;    df_s = df_dict[symbol]&lt;br /&gt;    df_close[symbol] = df_s.close&lt;br /&gt;df_close = df_close.dropna(how=&amp;#39;any&amp;#39;,axis=1)&lt;br /&gt;```&lt;br /&gt;### Market Review&lt;br /&gt;After normalizing the data first, we calculate the index of average price fluctuations. It can be seen that there are two market trends in 2023. One is a significant increase at the beginning of the year, and the other is a major rise starting from October. Currently, it&amp;#39;s basically at a high point in terms of index.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;df_norm = df_close/df_close.fillna(method=&amp;#39;bfill&amp;#39;).iloc[0] #Normalization&lt;br /&gt;total_index = df_norm.mean(axis=1)&lt;br /&gt;total_index.plot(figsize=(15,6),grid=True);&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149362
" title="https://stocksharp.com/file/149362
"&gt;https://stocksharp.com/file/149362
&lt;/a&gt;&lt;br /&gt;### Correlation Analysis&lt;br /&gt;Pandas comes with a built-in correlation calculation. The weakest correlation with BTC price is shown in the following figure. Most currencies have a positive correlation, meaning they follow the price of BTC. However, some currencies have a negative correlation, which is considered an anomaly in digital currency market trends.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149363
" title="https://stocksharp.com/file/149363
"&gt;https://stocksharp.com/file/149363
&lt;/a&gt;&lt;br /&gt;```&lt;br /&gt;corr_symbols = df_norm.corrwith(df_norm.BTC).sort_values().index&lt;br /&gt;```&lt;br /&gt;### Correlation and Price Increase&lt;br /&gt;Here, the currencies are loosely divided into two groups. The first group consists of 40 currencies most correlated with BTC price, and the second group includes those least related to BTC price. By subtracting the index of the second group from that of the first, it represents going long on the first group while shorting the second one. In this way, we can calculate a relationship between price fluctuations and BTC correlation. Here is how you do it along with results:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;(df_norm[corr_symbols[-40:]].mean(axis=1)-df_norm[corr_symbols[:40]].mean(axis=1)).plot(figsize=(15,6),grid=True);&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149364
" title="https://stocksharp.com/file/149364
"&gt;https://stocksharp.com/file/149364
&lt;/a&gt;&lt;br /&gt;The results show that the currencies with stronger correlation to BTC price have better increases, and shorting currencies with low correlation also played a good hedging role. The imprecision here is that future data was used when calculating the correlation. Below, we divide the data into two groups: one group calculates the correlation, and another calculates the return after hedging. The result is shown in the following figure, and the conclusion remains unchanged.&lt;br /&gt;&lt;br /&gt;Bitcoin and Ethereum as market leaders often have a huge impact on overall market trends. When these cryptocurrencies rise in price, market sentiment usually becomes optimistic and many investors tend to follow this trend. Investors may see this as a signal of an overall market increase and start buying other currencies. Due to collective behavior of market participants, currencies highly correlated with mainstream ones might experience similar price increases. At such times, expectations about price trends can sometimes become self-fulfilling prophecies. On the contrary, currencies negatively correlated with Bitcoin are unique; their fundamentals may be deteriorating or they may no longer be within sight of mainstream investors - there could even exist Bitcoin&amp;#39;s blood-sucking situation where markets abandon them chasing for those able to keep up with rising prices.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;corr_symbols = (df_norm.iloc[:1500].corrwith(df_norm.BTC.iloc[:1500])-df_norm.iloc[:1500].corrwith(total_index[:1500])).sort_values().index &lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149365
" title="https://stocksharp.com/file/149365
"&gt;https://stocksharp.com/file/149365
&lt;/a&gt;&lt;br /&gt;### Summary&lt;br /&gt;This article discusses the Pearson correlation coefficient, revealing the degree of correlation between different currencies. The article demonstrates how to obtain data to calculate the correlation between currencies and use this data to assess market trends. It reveals that synchronicity in price fluctuations in the digital currency market not only reflects market psychology and strategy, but can also be quantified and predicted through scientific methods. This is particularly important for designing quantitative trading strategies.&lt;br /&gt;&lt;br /&gt;There are many areas where the ideas in this article can be expanded, such as calculating rolling correlations, separately calculating correlations during rises and falls, etc., which can yield a lot of useful information.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y6_fDA9lkxHIZMIaASo91h6OY2ufQT34QJk0z8S1ICA0Z4cwUYPZfzvD39JSCgFcFURtLawpNJWdgy3F56xFr2xsNSU4GMr6yp3viK1RVNguA" title="https://blog.mathquant.com/2023/11/17/the-correlation-between-the-rise-and-fall-of-currencies-and-bitcoin.html"&gt;https://blog.mathquant.c...rencies-and-bitcoin.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25589/</id>
    <title type="text">Unveiling the Price Dynamics: Analyzing Performance Post Listing on Perpetual Contracts</title>
    <published>2024-03-20T05:37:02Z</published>
    <updated>2024-03-20T05:37:02Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#code" />
    <category term="#data" />
    <category term="#fmz" />
    <category term="#contract" />
    <category term="#binance" />
    <category term="#spot" />
    <category term="#Kline" />
    <category term="#crypto" />
    <category term="#bull" />
    <content type="html">Most people know that once Binance announces the listing of a new perpetual contract, the spot price of this cryptocurrency often rises immediately. This has led to some robots scraping announcements constantly to buy in at the first moment, not to mention so-called insider information where the currency price has already risen before the announcement is even made. But how do these contract cryptocurrencies perform after they start trading? Do they continue their upward trend or have a pullback? Let&amp;#39;s analyze it today.&lt;br /&gt;&lt;br /&gt;### Data Preparation&lt;br /&gt;Download the 4h K-line data of Binance&amp;#39;s perpetual contract for the year 2023. The specific download code is introduced in the previous article: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAADHZKb-RfbDOdB_w3dJgQKt340BVBnfBL7FKDRx7ipd8M2SDjngavqKT7CrykkTgYA" title="https://www.fmz.com/bbs-topic/10286. "&gt;https://www.fmz.com/bbs-topic/10286. &lt;/a&gt;The listing time does not necessarily coincide with the 4-hour mark, which is a bit imprecise. However, the price at the start of trading is often chaotic. Using fixed intervals can filter out the impact of market opening without delaying analysis. In the data dataframe, NaN represents no data; once the first piece of data appears, it means that this coin has been listed. Here we calculate every 4 hours after listing relative to the first price increase and form a new table. Those already listed from the beginning are filtered out. As of November 16, 2023, Binance has listed a total of 86 currencies, averaging more than one every three days - quite frequent indeed.&lt;br /&gt;&lt;br /&gt;The following is the specific processing code, where only data within 150 days of going live has been extracted.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;df = df_close/df_close.fillna(method=&amp;#39;bfill&amp;#39;).iloc[0]&lt;br /&gt;price_changes = {}&lt;br /&gt;for coin in df.columns[df.iloc[0].isna()]:&lt;br /&gt;    listing_time = df[coin].first_valid_index()&lt;br /&gt;    price_changes[coin] = df[coin][df.index&amp;gt;listing_time].values&lt;br /&gt;changes_df = pd.DataFrame.from_dict(price_changes, orient=&amp;#39;index&amp;#39;).T&lt;br /&gt;changes_df.index = changes_df.index/6&lt;br /&gt;changes_df = changes_df[changes_df.index&amp;lt;150]&lt;br /&gt;changes_df.mean(axis=1).plot(figsize=(15,6),grid=True);&lt;br /&gt;```&lt;br /&gt;### Result Analysis&lt;br /&gt;The results are shown in the following graph, where the horizontal axis represents the number of days on the shelf and the vertical axis represents the average index. This result can be said to be unexpected but reasonable. Surprisingly, after new contracts are listed, they almost all fall, and the longer they are listed, the more they fall. At least within half a year there is no rebound. But it&amp;#39;s also reasonable to think about it; so-called listing benefits have been realized before listing, and subsequent continuous declines are normal. If you open up a K-line chart to look at weekly lines, you can also find that many newly-listed contract currencies follow this pattern - opening at their peak.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149353
" title="https://stocksharp.com/file/149353
"&gt;https://stocksharp.com/file/149353
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149354
" title="https://stocksharp.com/file/149354
"&gt;https://stocksharp.com/file/149354
&lt;/a&gt;&lt;br /&gt;### Exclude the Impact of the Index&lt;br /&gt;The previous article has mentioned that digital currencies are greatly affected by simultaneous rises and falls. Does the overall index&amp;#39;s decline affect their performance? Here, let&amp;#39;s change the price changes to be relative to the index changes and look at the results again. From what we see on the graph, it still looks the same - a continuous decline. In fact, it has declined even more compared to the index.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;total_index = df.mean(axis=1)&lt;br /&gt;df = df.divide(total_index,axis=0)&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149355
" title="https://stocksharp.com/file/149355
"&gt;https://stocksharp.com/file/149355
&lt;/a&gt;&lt;br /&gt;### Binance&amp;#39;s Currency Listing&lt;br /&gt;By analyzing the relationship between the number of currencies listed each week and the index, we can clearly see Binance&amp;#39;s listing strategy: frequent listings during a bull market, few listings during a bear market. February and October of this year were peak periods for listings, coinciding with bull markets. During times when the market was falling quite badly, Binance hardly listed any new contracts. It is evident that Binance also wants to take advantage of high trading volumes in bull markets and active new contracts to earn more transaction fees. They don&amp;#39;t want new contracts to fall too badly either, but unfortunately, they can&amp;#39;t always control it.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149356
" title="https://stocksharp.com/file/149356
"&gt;https://stocksharp.com/file/149356
&lt;/a&gt;&lt;br /&gt;### Summary&lt;br /&gt;This article analyzes the 4h K-line data of Binance&amp;#39;s perpetual contracts for the year 2023, showing that newly listed contracts tend to decline over a long period. This may reflect the market&amp;#39;s gradual cooling off from initial enthusiasm and return to rationality. If you design a strategy to short a certain amount of funds on the first day of trading, and close out after holding for some time, there is a high probability of making money. Of course, this also carries risks; past trends do not represent the future. But one thing is certain: there is no need to chase hot spot or go long on newly listed contract currencies.&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y62jT7jgUMxT5buH0Adozlwm7yqfufWT_GopKI_KFwlmgfOtowBcFv3wJuVmGPn4eBLGzgeWHm6e5jFwDG2g1hCeTDbyWVt2hkYBR2k9zHA2wvnNuu3-twQM60C7IfNIHew" title="https://blog.mathquant.com/2023/11/20/price-performance-after-the-currency-is-listed-on-perpetual-contracts.html"&gt;https://blog.mathquant.c...perpetual-contracts.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25586/</id>
    <title type="text">Unlocking Efficiency: Leveraging FMZ&amp;apos;s Extended API for Streamlined Group Control in Quantitative Trading</title>
    <published>2024-03-20T00:41:57Z</published>
    <updated>2024-03-20T00:41:57Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#data" />
    <category term="#fmz" />
    <category term="#parameter" />
    <category term="#API" />
    <category term="#robot" />
    <category term="#command" />
    <content type="html">With the popularization and development of quantitative trading, investors often need to manage a large number of live accounts, which brings great challenges to trading decisions, monitoring and execution. In order to improve management efficiency and reduce operational difficulty, traders on FMZ can use FMZ&amp;#39;s extended API for group control management. In this article, we will discuss the advantages of using FMZ&amp;#39;s extended API in quantitative trading and how to achieve efficient group control management.&lt;br /&gt;&lt;br /&gt;Many users have their own customer live accounts that need managing and maintaining. When there are many customer live accounts, a more convenient way is needed for managing them (as few as dozens or as many as hundreds). FMZ provides a powerful extended API; using this for group control management has become an ideal choice.&lt;br /&gt;&lt;br /&gt;### Centralized Monitoring&lt;br /&gt;Through FMZ&amp;#39;s extended API, you can centrally monitor the trading activities and asset conditions of all live accounts. Whether it is checking the positions of each account, historical trading records, or real-time monitoring of the profit and loss status of accounts, all of them can be achieved.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;// Global variable&lt;br /&gt;var isLogMsg = true   // Control whether the log is printed&lt;br /&gt;var isDebug = false   // Debug mode&lt;br /&gt;var arrIndexDesc = [&amp;quot;all&amp;quot;, &amp;quot;running&amp;quot;, &amp;quot;stop&amp;quot;]&lt;br /&gt;var descRobotStatusCode = [&amp;quot;In idle&amp;quot;, &amp;quot;Running&amp;quot;, &amp;quot;Stopping&amp;quot;, &amp;quot;Exited&amp;quot;, &amp;quot;Stopped&amp;quot;, &amp;quot;Strategy error&amp;quot;]&lt;br /&gt;var dicRobotStatusCode = {&lt;br /&gt;    &amp;quot;all&amp;quot; : -1,&lt;br /&gt;    &amp;quot;running&amp;quot; : 1,&lt;br /&gt;    &amp;quot;stop&amp;quot; : 4,&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Extended log function&lt;br /&gt;function LogControl(...args) {&lt;br /&gt;    if (isLogMsg) {&lt;br /&gt;        Log(...args)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// FMZ extended API call function&lt;br /&gt;function callFmzExtAPI(accessKey, secretKey, funcName, ...args) {&lt;br /&gt;    var params = {&lt;br /&gt;        &amp;quot;version&amp;quot; : &amp;quot;1.0&amp;quot;,&lt;br /&gt;        &amp;quot;access_key&amp;quot; : accessKey,&lt;br /&gt;        &amp;quot;method&amp;quot; : funcName,&lt;br /&gt;        &amp;quot;args&amp;quot; : JSON.stringify(args),&lt;br /&gt;        &amp;quot;nonce&amp;quot; : Math.floor(new Date().getTime())&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    var data = `${params[&amp;quot;version&amp;quot;]}|${params[&amp;quot;method&amp;quot;]}|${params[&amp;quot;args&amp;quot;]}|${params[&amp;quot;nonce&amp;quot;]}|${secretKey}`&lt;br /&gt;    params[&amp;quot;sign&amp;quot;] = Encode(&amp;quot;md5&amp;quot;, &amp;quot;string&amp;quot;, &amp;quot;hex&amp;quot;, data)&lt;br /&gt;    &lt;br /&gt;    var arrPairs = []&lt;br /&gt;    for (var k in params) {&lt;br /&gt;        var pair = `${k}=${params[k]}`&lt;br /&gt;        arrPairs.push(pair)&lt;br /&gt;    }&lt;br /&gt;    var query = arrPairs.join(&amp;quot;&amp;amp;&amp;quot;)&lt;br /&gt;    &lt;br /&gt;    var ret = null&lt;br /&gt;    try {&lt;br /&gt;        LogControl(&amp;quot;url:&amp;quot;, baseAPI + &amp;quot;/api/v1?&amp;quot; + query)&lt;br /&gt;        ret = JSON.parse(HttpQuery(baseAPI + &amp;quot;/api/v1?&amp;quot; + query))&lt;br /&gt;        if (isDebug) {&lt;br /&gt;            LogControl(&amp;quot;Debug:&amp;quot;, ret)&lt;br /&gt;        }&lt;br /&gt;    } catch(e) {&lt;br /&gt;        LogControl(&amp;quot;e.name:&amp;quot;, e.name, &amp;quot;e.stack:&amp;quot;, e.stack, &amp;quot;e.message:&amp;quot;, e.message)&lt;br /&gt;    }&lt;br /&gt;    Sleep(100)  // Control frequency&lt;br /&gt;    return ret &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Obtain all live trading information of the specified strategy Id.&lt;br /&gt;function getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode, maxRetry) {&lt;br /&gt;    var retryCounter = 0&lt;br /&gt;    var length = 100&lt;br /&gt;    var offset = 0&lt;br /&gt;    var arr = []&lt;br /&gt;&lt;br /&gt;    if (typeof(maxRetry) == &amp;quot;undefined&amp;quot;) {&lt;br /&gt;        maxRetry = 10&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    while (true) {&lt;br /&gt;        if (retryCounter &amp;gt; maxRetry) {&lt;br /&gt;            LogControl(&amp;quot;Exceeded the maximum number of retries&amp;quot;, maxRetry)&lt;br /&gt;            return null&lt;br /&gt;        }&lt;br /&gt;        var ret = callFmzExtAPI(accessKey, secretKey, &amp;quot;GetRobotList&amp;quot;, offset, length, robotStatusCode)&lt;br /&gt;        if (!ret || ret[&amp;quot;code&amp;quot;] != 0) {&lt;br /&gt;            Sleep(1000)&lt;br /&gt;            retryCounter++&lt;br /&gt;            continue&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        var robots = ret[&amp;quot;data&amp;quot;][&amp;quot;result&amp;quot;][&amp;quot;robots&amp;quot;]&lt;br /&gt;        for (var i in robots) {&lt;br /&gt;            if (robots[i].strategy_id != strategyId) {&lt;br /&gt;                continue&lt;br /&gt;            }&lt;br /&gt;            arr.push(robots[i])&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if (robots.length &amp;lt; length) {&lt;br /&gt;            break&lt;br /&gt;        }&lt;br /&gt;        offset += length&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return arr &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function main() {&lt;br /&gt;    var robotStatusCode = dicRobotStatusCode[arrIndexDesc[robotStatus]]&lt;br /&gt;    var robotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode)&lt;br /&gt;    if (!robotList) {&lt;br /&gt;        Log(&amp;quot;Failed to obtain live trading data&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    var robotTbl = {&amp;quot;type&amp;quot;: &amp;quot;table&amp;quot;, &amp;quot;title&amp;quot;: &amp;quot;live trading list&amp;quot;, &amp;quot;cols&amp;quot;: [], &amp;quot;rows&amp;quot;: []}&lt;br /&gt;    robotTbl.cols = [&amp;quot;live trading Id&amp;quot;, &amp;quot;live trading name&amp;quot;, &amp;quot;live trading status&amp;quot;, &amp;quot;strategy name&amp;quot;, &amp;quot;live trading profit&amp;quot;]&lt;br /&gt;&lt;br /&gt;    _.each(robotList, function(robotInfo) {&lt;br /&gt;        robotTbl.rows.push([robotInfo.id, robotInfo.name, descRobotStatusCode[robotInfo.status], robotInfo.strategy_name, robotInfo.profit])&lt;br /&gt;    })&lt;br /&gt;&lt;br /&gt;    LogStatus(_D(), &amp;quot;`&amp;quot; + JSON.stringify(robotTbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Strategy parameter design:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149332
" title="https://stocksharp.com/file/149332
"&gt;https://stocksharp.com/file/149332
&lt;/a&gt;&lt;br /&gt;Running on live trading:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149333
" title="https://stocksharp.com/file/149333
"&gt;https://stocksharp.com/file/149333
&lt;/a&gt;&lt;br /&gt;### One-click Execution&lt;br /&gt;Group control management makes it very convenient to execute transactions with one-click. You can buy, sell, and close positions on multiple live trading accounts simultaneously without having to open each account individually. This not only improves execution efficiency, but also reduces the possibility of operational errors.&lt;br /&gt;&lt;br /&gt;After obtaining the list of live trading accounts, we can send commands to these accounts and perform a series of predetermined operations. For example: clearing positions in the live account, pausing protection in the live account, switching modes in the live account. All these can be achieved through FMZ&amp;#39;s extended API ```CommandRobot```.&lt;br /&gt;&lt;br /&gt;As we continue writing code, we just need to add some interactions and calls to the extended API interface ```CommandRobot``` in our main function:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;function main() {&lt;br /&gt;    var robotStatusCode = dicRobotStatusCode[arrIndexDesc[robotStatus]]&lt;br /&gt;    var robotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode)&lt;br /&gt;    if (!robotList) {&lt;br /&gt;        Log(&amp;quot;Failed to obtain live trading data&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    var robotTbl = {&amp;quot;type&amp;quot;: &amp;quot;table&amp;quot;, &amp;quot;title&amp;quot;: &amp;quot;live trading list&amp;quot;, &amp;quot;cols&amp;quot;: [], &amp;quot;rows&amp;quot;: []}&lt;br /&gt;    robotTbl.cols = [&amp;quot;live trading Id&amp;quot;, &amp;quot;live trading name&amp;quot;, &amp;quot;live trading status&amp;quot;, &amp;quot;strategy name&amp;quot;, &amp;quot;live trading profit&amp;quot;]&lt;br /&gt;&lt;br /&gt;    _.each(robotList, function(robotInfo) {&lt;br /&gt;        robotTbl.rows.push([robotInfo.id, robotInfo.name, descRobotStatusCode[robotInfo.status], robotInfo.strategy_name, robotInfo.profit])&lt;br /&gt;    })&lt;br /&gt;&lt;br /&gt;    LogStatus(_D(), &amp;quot;`&amp;quot; + JSON.stringify(robotTbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;&lt;br /&gt;    while(true) {&lt;br /&gt;        LogStatus(_D(), &amp;quot;, Waiting to receive interactive commands&amp;quot;, &amp;quot;\n&amp;quot;, &amp;quot;`&amp;quot; + JSON.stringify(robotTbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;&lt;br /&gt;        var cmd = GetCommand()&lt;br /&gt;        if (cmd) {&lt;br /&gt;            var arrCmd = cmd.split(&amp;quot;:&amp;quot;)&lt;br /&gt;            if (arrCmd.length == 1 &amp;amp;&amp;amp; cmd == &amp;quot;coverAll&amp;quot;) {&lt;br /&gt;                _.each(robotList, function(robotInfo) {&lt;br /&gt;                    var strCmd = &amp;quot;Clearance&amp;quot;               // You can define the required message format&lt;br /&gt;                    if (robotInfo.status != 1) {     // Only the &amp;quot;live&amp;quot; trading platform can receive commands.&lt;br /&gt;                        return &lt;br /&gt;                    }&lt;br /&gt;                    var ret = callFmzExtAPI(accessKey, secretKey, &amp;quot;CommandRobot&amp;quot;, parseInt(robotInfo.id), strCmd)&lt;br /&gt;                    LogControl(&amp;quot;Send command to the live trading board with id: &amp;quot;, robotInfo.id, &amp;quot;:&amp;quot;, strCmd, &amp;quot;, execution result:&amp;quot;, ret)&lt;br /&gt;                })&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        Sleep(1000)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149334
" title="https://stocksharp.com/file/149334
"&gt;https://stocksharp.com/file/149334
&lt;/a&gt;&lt;br /&gt;The group control strategy sent instructions to &amp;quot;Test 1 A&amp;quot; and &amp;quot;Test 1 B&amp;quot;.&lt;br /&gt;&lt;br /&gt;### Strategy Synchronization&lt;br /&gt;With FMZ&amp;#39;s extended API, you can easily implement batch modifications of strategy parameters, and batch start or stop live trading.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149335
" title="https://stocksharp.com/file/149335
"&gt;https://stocksharp.com/file/149335
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149336
" title="https://stocksharp.com/file/149336
"&gt;https://stocksharp.com/file/149336
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149337
" title="https://stocksharp.com/file/149337
"&gt;https://stocksharp.com/file/149337
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149338
" title="https://stocksharp.com/file/149338
"&gt;https://stocksharp.com/file/149338
&lt;/a&gt;&lt;br /&gt;### Summary&lt;br /&gt;In quantitative trading, by using FMZ&amp;#39;s extended API for group control management, traders can monitor, execute and adjust multiple live accounts more efficiently. This centralized management method not only improves operational efficiency, but also helps to better implement risk control and strategy synchronization.&lt;br /&gt;&lt;br /&gt;For traders managing a large number of live accounts, FMZ&amp;#39;s extended API provides them with a powerful and flexible tool that makes quantitative trading more convenient and controllable.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y6xi6CcygGojFUBiqPTxAevq5wECkW1uLDRcZq-59qg9OKxUAia2AuB86x2UlrEKgVbhVLcTSWByK5cnm6thO7ha7JspnElZ9CclHO2tbtCWcgEDsFiuh3IYlqWjlIrZ8WADxxcmD3DOqzMbQtv1etWBp-dH16_zcVHvHGQrhEiKO" title="https://blog.mathquant.com/2023/11/20/the-advantages-of-using-fmzs-extended-api-for-efficient-group-control-management-in-quantitative-trading.html"&gt;https://blog.mathquant.c...uantitative-trading.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25583/</id>
    <title type="text">Unraveling the Mystery of Probability: Exploring Bayesian Decision Making and Mathematical Wisdom</title>
    <published>2024-03-19T09:11:08Z</published>
    <updated>2024-03-19T09:11:08Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#data" />
    <category term="#fmz" />
    <category term="#parameter" />
    <category term="#Bayes" />
    <category term="#formula" />
    <category term="#math" />
    <category term="#Shannon" />
    <category term="#finance" />
    <content type="html">Bayesian statistics is a powerful discipline in the field of mathematics, with wide applications in many areas including finance, medical research, and information technology. It allows us to combine prior beliefs with evidence to derive new posterior beliefs, enabling us to make wiser decisions.&lt;br /&gt;&lt;br /&gt;In this article, we will briefly introduce some of the main mathematicians who founded this field.&lt;br /&gt;&lt;br /&gt;Before Bayes&lt;br /&gt;To better understand Bayesian statistics, we need to go back to the 18th century and refer to mathematician De Moivre and his paper &amp;quot;The Doctrine of Chances&amp;quot;.&lt;br /&gt;&lt;br /&gt;In his paper, De Moivre solved many problems related to probability and gambling in his era. As you may know, his solution to one of these problems led to the origin of the normal distribution, but that&amp;#39;s another story.&lt;br /&gt;&lt;br /&gt;One of the simplest questions in his paper was:&lt;br /&gt;&lt;br /&gt;&amp;quot;What is the probability of getting three heads when flipping a fair coin three times consecutively?&amp;quot;&lt;br /&gt;&lt;br /&gt;Reading through the problems described in &amp;quot;The Doctrine of Chances&amp;quot;, you might notice that most start with an assumption from which they calculate probabilities for given events. For example, in the above question there is an assumption that considers the coin as fair; therefore, obtaining a head during a toss has a probability of 0.5.&lt;br /&gt;&lt;br /&gt;This would be expressed today in mathematical terms as:&lt;br /&gt;&lt;br /&gt;Formula&lt;br /&gt;```&lt;br /&gt;&amp;#119875;(&amp;#119883;|&amp;#120579;)&lt;br /&gt;```&lt;br /&gt;However, what if we don&amp;#39;t know whether the coin is fair? What if we don&amp;#39;t know ```&amp;#120579;``` ?&lt;br /&gt;&lt;br /&gt;### Thomas Bayes and Richard Price&lt;br /&gt;Nearly fifty years later, in 1763, a paper titled &amp;quot;A Solution to the Problems in the Doctrine of Chances&amp;quot; was published in the Philosophical Transactions of the Royal Society of London.&lt;br /&gt;&lt;br /&gt;In the first few pages of this document, there is a piece written by mathematician Richard Price that summarizes a paper his friend Thomas Bayes wrote several years before his death. In his introduction, Price explained some important discoveries made by Thomas Bayes that were not mentioned in De Moivre&amp;#39;s &amp;quot;Doctrine of Chances&amp;quot;.&lt;br /&gt;&lt;br /&gt;In fact, he referred to one specific problem:&lt;br /&gt;&lt;br /&gt;&amp;quot;Given an unknown event&amp;#39;s number of successes and failures, find its chance between any two named degrees.&amp;quot;&lt;br /&gt;&lt;br /&gt;In other words, after observing an event we determine what is the probability that an unknown parameter ```θ``` falls between two degrees. This is actually one of the first problems related to statistical inference in history and it gave rise to term inverse probability. In mathematical terms:&lt;br /&gt;&lt;br /&gt;Formula&lt;br /&gt;```&lt;br /&gt;&amp;#119875;( &amp;#120579; | &amp;#119883;）&lt;br /&gt;```&lt;br /&gt;This is of course what we call the posterior distribution of Bayes&amp;#39; theorem today.&lt;br /&gt;&lt;br /&gt;### For the Reason of No Cause and Effect&lt;br /&gt;Understanding the motivations behind the research of these two elder ministers, **Thomas Bayes** and **Richard Price**, is actually quite interesting. But to do this, we need to temporarily put aside some knowledge about statistics.&lt;br /&gt;&lt;br /&gt;We are in the 18th century when probability is becoming an increasingly interesting field for mathematicians. Mathematicians like de Moivre or Bernoulli have already shown that some events occur with a certain degree of randomness but are still governed by fixed rules. For example, if you roll a dice multiple times, one-sixth of the time it will land on six. It&amp;#39;s as if there&amp;#39;s a hidden rule determining fate&amp;#39;s chances.&lt;br /&gt;&lt;br /&gt;Now imagine being a mathematician and devout believer living during this period. You might be interested in understanding the relationship between this hidden rule and God.&lt;br /&gt;&lt;br /&gt;This was indeed the question asked by Bayes and Price themselves. They hoped that their solution would directly apply to proving &amp;quot;the world must be the result of wisdom and intelligence; therefore providing evidence for God&amp;#39;s existence as ultimate cause&amp;quot; - that is, cause without causality.&lt;br /&gt;&lt;br /&gt;### Laplace&lt;br /&gt;Surprisingly, around two years later in 1774, without having read Thomas Bayes&amp;#39; paper, the French mathematician Laplace wrote a paper titled &amp;quot;On the Causes of Events by Probability of Events&amp;quot;, which is about inverse probability problems. On the first page, you can read the main principle:&lt;br /&gt;&lt;br /&gt;&amp;quot;If an event can be caused by n different reasons, then the ratios between these causes&amp;#39; probabilities given the event are equal to the probabilities of events given these causes; and each cause&amp;#39;s existence probability equals to the probability of causes given this event divided by total probabilities of events given each one of these causes.&amp;quot;&lt;br /&gt;&lt;br /&gt;This is what we know today as Bayes&amp;#39; theorem:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149324
" title="https://stocksharp.com/file/149324
"&gt;https://stocksharp.com/file/149324
&lt;/a&gt;&lt;br /&gt;Where ```P(θ)``` is a uniform distribution.&lt;br /&gt;&lt;br /&gt;### Coin Experiment&lt;br /&gt;We will bring Bayesian statistics to the present by using Python and PyMC library, and conduct a simple experiment.&lt;br /&gt;&lt;br /&gt;Suppose a friend gives you a coin and asks if you think it&amp;#39;s a fair coin. Because he is in a hurry, he tells you that you can only toss the coin 10 times. As you can see, there is an unknown parameter ```p``` in this problem, which is the probability of getting heads in tossing coins, and we want to estimate the most likely value of the ```p```.&lt;br /&gt;&lt;br /&gt;(Note: We are not saying that parameter ```p``` is a random variable but rather that this parameter is fixed; we want to know where it&amp;#39;s most likely between.)&lt;br /&gt;&lt;br /&gt;To have different views on this problem, we will solve it under two different prior beliefs:&lt;br /&gt;&lt;br /&gt;- 1. You have no prior information about the fairness of the coin, so you assign an equal probability to ```p```. In this case, we will use what is called a non-informative prior because you haven&amp;#39;t added any information to your beliefs.&lt;br /&gt;&lt;br /&gt;- 2. From your experience, you know that even if a coin might be unfair, it&amp;#39;s hard to make it extremely unfair. Therefore, you believe the parameter ```p``` is unlikely to be less than 0.3 or more than 0.7. In this case, we will use an informative prior.&lt;br /&gt;&lt;br /&gt;For these two scenarios, our prior beliefs will be as follows:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149325
" title="https://stocksharp.com/file/149325
"&gt;https://stocksharp.com/file/149325
&lt;/a&gt;&lt;br /&gt;After flipping a coin 10 times, you got heads twice. With this evidence, where are we likely to find our parameter ```p```?&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149326
" title="https://stocksharp.com/file/149326
"&gt;https://stocksharp.com/file/149326
&lt;/a&gt;&lt;br /&gt;As you can see, in the first case, our prior distribution of parameter ```p``` is concentrated at the maximum likelihood estimate (MLE) ```p=0.2```, which is a method similar to that used by the frequency school. The true unknown parameter will be within the 95% confidence interval, between 0.04 and 0.48.&lt;br /&gt;&lt;br /&gt;On the other hand, in cases where there is high confidence that parameter ```p``` should be between 0.3 and 0.7, we can see that the posterior distribution is around 0.4, much higher than what our MLE gives us. In this case, the true unknown parameter will be within a 95% confidence interval between 0.23 and 0.57.&lt;br /&gt;&lt;br /&gt;Therefore, in the first case scenario you would tell your friend with certainty that this coin isn&amp;#39;t fair but in another situation you&amp;#39;d say it&amp;#39;s uncertain whether or not it&amp;#39;s fair.&lt;br /&gt;&lt;br /&gt;As you can see even when faced with identical evidence (two heads out of ten tosses), under different prior beliefs results may vary greatly; one advantage of Bayesian statistics over traditional methods lies here: like scientific methodology it allows us to update our beliefs by combining them with new observations and evidence.&lt;br /&gt;&lt;br /&gt;### END&lt;br /&gt;In today&amp;#39;s article, we saw the origins of Bayesian statistics and its main contributors. Subsequently, there have been many other important contributors to this field of statistics (Jeffreys, Cox, Shannon and so on), reprinted from quantdare.com.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y639wfXoqEZs3GnoRG_u0FEsc7r8-Fu3f7ARYJuPniwI7H7WkOzR-JqYMSLxlaelEjSkzb4YTUt6Y00geQTZ5Y6JsC1ekJ4CS-XzShWmjGIjSobM9kTNsNucSP3v7Mj6-cBa3yYRYw9tyaUDW6Gss4F4" title="https://blog.mathquant.com/2023/11/27/bayes-decoding-the-mystery-of-probability-exploring-the-mathematical-wisdom-behind-decision-making.html"&gt;https://blog.mathquant.c...ind-decision-making.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25578/</id>
    <title type="text">Which is More Suitable for Bottom Fishing, Low Market Value or Low Price?</title>
    <published>2024-03-19T05:15:22Z</published>
    <updated>2024-03-19T05:15:22Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#data" />
    <category term="#market" />
    <category term="#fmz" />
    <category term="#contract" />
    <category term="#binance" />
    <category term="#risk" />
    <category term="#bitcoin" />
    <category term="#indicator" />
    <content type="html">The previous articles &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAADHZKb-RfbDOdB_w3dJgQKtOFYh40OC5dg48A4wezcnse6T8uLbxzpcRWb5tsBTmb0" title="https://www.fmz.com/digest-topic/10286 "&gt;https://www.fmz.com/digest-topic/10286 &lt;/a&gt;and &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAADHZKb-RfbDOdB_w3dJgQKtOFYh40OC5dg48A4wezcnsc77TWG_lj0IXqHQAJmKZ30" title="https://www.fmz.com/digest-topic/10292 "&gt;https://www.fmz.com/digest-topic/10292 &lt;/a&gt;discussed the correlation between cryptocurrency price fluctuations and Bitcoin, as well as the impact of launching perpetual contracts on prices. This article will continue to explore another important factor affecting coin prices - market value. Readers familiar with quantitative trading should know that there is a most effective factor in the A-share market - small market value. The performance of small-cap stock rotation is very counter-intuitive, far exceeding various indicators, those interested can find out for themselves. So how does the price performance of small-cap or low-priced digital currencies look?&lt;br /&gt;&lt;br /&gt;### Data Processing and Collection&lt;br /&gt;This section uses the same data as the previous few articles, so it won&amp;#39;t be repeated here.&lt;br /&gt;&lt;br /&gt;### Performance of Low-Priced Currencies&lt;br /&gt;Low-priced currencies usually refer to digital currencies with lower unit prices. These currencies are more attractive to small investors due to their low prices. Most people only see many zeros in the price but don&amp;#39;t care much about the market value. Each unit reduction (zero) means that the price is multiplied by 10, which is very attractive to some people, but it may also be accompanied by higher price volatility and risk.&lt;br /&gt;&lt;br /&gt;As usual, let&amp;#39;s first look at the performance of the index, with two bull markets at the beginning and end of the year. Every week we select the 20 lowest priced currencies, and the results are very close to those of indicators, indicating that low prices do not provide too much additional return.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;h = 1&lt;br /&gt;lower_index = 1&lt;br /&gt;lower_index_list = [1]&lt;br /&gt;lower_symbols = df_close.iloc[0].dropna().sort_values()[:20].index&lt;br /&gt;lower_prices =  df_close.iloc[0][lower_symbols]&lt;br /&gt;date_list = [df_close.index[0]]&lt;br /&gt;for row in df_close.iterrows():&lt;br /&gt;    if h % 42 == 0:&lt;br /&gt;        date_list.append(row[0])&lt;br /&gt;        lower_index = lower_index * (row[1][lower_symbols] / lower_prices).mean()&lt;br /&gt;        lower_index_list.append(lower_index)&lt;br /&gt;        lower_symbols = row[1].dropna().sort_values()[:20].index&lt;br /&gt;        lower_prices = row[1][lower_symbols]&lt;br /&gt;    h += 1&lt;br /&gt;pd.DataFrame(data=lower_index_list,index=date_list).plot(figsize=(12,5),grid=True);&lt;br /&gt;total_index.plot(figsize=(12,5),grid=True); #overall index&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149322
" title="https://stocksharp.com/file/149322
"&gt;https://stocksharp.com/file/149322
&lt;/a&gt;&lt;br /&gt;### Performance of Small Market Cap Currencies&lt;br /&gt;Due to the constantly changing circulation, the market value calculation here uses the total supply volume, with data sourced from Coincapmarket. Those who need it can apply for a key. A total of 1000 currencies with the highest market values were selected. Due to naming methods and unknown total supplies, we obtained 205 currencies that overlap with Binance perpetual contracts.&lt;br /&gt;```&lt;br /&gt;import requests&lt;br /&gt;&lt;br /&gt;def get_latest_crypto_listings(api_key):&lt;br /&gt;    url = &amp;quot;https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?limit=1000&amp;quot;&lt;br /&gt;    headers = {&lt;br /&gt;        &amp;#39;Accepts&amp;#39;: &amp;#39;application/json&amp;#39;,&lt;br /&gt;        &amp;#39;X-CMC_PRO_API_KEY&amp;#39;: api_key,&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    response = requests.get(url, headers=headers)&lt;br /&gt;    if response.status_code == 200:&lt;br /&gt;        return response.json()&lt;br /&gt;    else:&lt;br /&gt;        return f&amp;quot;Error: {response.status_code}&amp;quot;&lt;br /&gt;&lt;br /&gt;# Use your API key&lt;br /&gt;api_key = &amp;quot;xxx&amp;quot;&lt;br /&gt;coin_data = get_latest_crypto_listings(api_key)&lt;br /&gt;supplys = {d[&amp;#39;symbol&amp;#39;]: d[&amp;#39;total_supply&amp;#39;] for d in coin_data[&amp;#39;data&amp;#39;]}&lt;br /&gt;include_symbols = [s for s in list(df_close.columns)  if s in supplys and supplys[s] &amp;gt; 0 ]&lt;br /&gt;```&lt;br /&gt;An index is drawn from the 10 cryptocurrencies with the lowest market value each week, and compared with the overall index. It can be seen that small-cap cryptocurrencies performed slightly better than the overall index in the bull market at the beginning of the year. However, they started to rise ahead of time during September-October&amp;#39;s sideways movement, and their final increase far exceeded that of the total index.&lt;br /&gt;&lt;br /&gt;Small-cap cryptocurrencies are often considered to have higher growth potential. Because their market values are low, even relatively small inflows of funds can cause significant price changes. This potential for high returns attracts investors and speculators&amp;#39; attention. When there is a stir at bottom markets, due to less resistance to rise, small-cap currencies often take off first and may even indicate that a general rising bull market is about to begin.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;df_close_include = df_close[include_symbols]&lt;br /&gt;df_norm = df_close_include/df_close_include.fillna(method=&amp;#39;bfill&amp;#39;).iloc[0] #Normalization&lt;br /&gt;total_index = df_norm.mean(axis=1)&lt;br /&gt;h = 1&lt;br /&gt;N = 10&lt;br /&gt;lower_index = 1&lt;br /&gt;lower_index_list = [1]&lt;br /&gt;lower_symbols = df_close_include.iloc[0].dropna().multiply(pd.Series(supplys)[include_symbols], fill_value=np.nan).sort_values()[:N].index&lt;br /&gt;lower_prices =  df_close_include.iloc[0][lower_symbols]&lt;br /&gt;date_list = [df_close_include.index[0]]&lt;br /&gt;for row in df_close_include.iterrows():&lt;br /&gt;    if h % 42 == 0:&lt;br /&gt;        date_list.append(row[0])&lt;br /&gt;        lower_index = lower_index * (row[1][lower_symbols] / lower_prices).mean()&lt;br /&gt;        lower_index_list.append(lower_index)&lt;br /&gt;        lower_symbols = row[1].dropna().multiply(pd.Series(supplys)[include_symbols], fill_value=np.nan).sort_values()[:N].index&lt;br /&gt;        lower_prices = row[1][lower_symbols]&lt;br /&gt;    h += 1&lt;br /&gt;pd.DataFrame(data=lower_index_list,index=date_list).plot(figsize=(12,5),grid=True);&lt;br /&gt;total_index.plot(figsize=(12,5),grid=True);&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149323
" title="https://stocksharp.com/file/149323
"&gt;https://stocksharp.com/file/149323
&lt;/a&gt;&lt;br /&gt;### Summary&lt;br /&gt;This article, through data analysis, found that low-priced currencies did not provide additional returns and their performance was close to the market index. The performance of small market cap currencies significantly exceeded the overall index increase. Below is a list of contract currencies with a market value less than 100 million U for reference, even though we are currently in a bull market.&lt;br /&gt;&lt;br /&gt;&amp;#39;HOOK&amp;#39;: 102007225,&lt;br /&gt;&amp;#39;SLP&amp;#39;: 99406669,&lt;br /&gt;&amp;#39;NMR&amp;#39;: 97617143,&lt;br /&gt;&amp;#39;RDNT&amp;#39;: 97501392,&lt;br /&gt;&amp;#39;MBL&amp;#39;: 93681270,&lt;br /&gt;&amp;#39;OMG&amp;#39;: 89129884,&lt;br /&gt;&amp;#39;NKN&amp;#39;: 85700948,&lt;br /&gt;&amp;#39;DENT&amp;#39;: 84558413,&lt;br /&gt;&amp;#39;ALPHA&amp;#39;: 81367392,&lt;br /&gt;&amp;#39;RAD&amp;#39;: 80849568,&lt;br /&gt;&amp;#39;HFT&amp;#39;: 79696303,&lt;br /&gt;&amp;#39;STMX&amp;#39;: 79472000,&lt;br /&gt;&amp;#39;ALICE&amp;#39;: 74615631,&lt;br /&gt;&amp;#39;OGN&amp;#39;: 74226686,&lt;br /&gt;&amp;#39;GTC&amp;#39;: 72933069,&lt;br /&gt;&amp;#39;MAV&amp;#39;: 72174400,&lt;br /&gt;&amp;#39;CTK&amp;#39;: 72066028,&lt;br /&gt;&amp;#39;UNFI&amp;#39;: 71975379,&lt;br /&gt;&amp;#39;OXT&amp;#39;: 71727646,&lt;br /&gt;&amp;#39;COTI&amp;#39;: 71402243,&lt;br /&gt;&amp;#39;HIGH&amp;#39;: 70450329,&lt;br /&gt;&amp;#39;DUSK&amp;#39;: 69178891,&lt;br /&gt;&amp;#39;ARKM&amp;#39;: 68822057,&lt;br /&gt;&amp;#39;HIFI&amp;#39;: 68805227,&lt;br /&gt;&amp;#39;CYBER&amp;#39;: 68264478,&lt;br /&gt;&amp;#39;BADGER&amp;#39;: 67746045,&lt;br /&gt;&amp;#39;AGLD&amp;#39;: 66877113,&lt;br /&gt;&amp;#39;LINA&amp;#39;: 62674752,&lt;br /&gt;&amp;#39;PEOPLE&amp;#39;: 62662701,&lt;br /&gt;&amp;#39;ARPA&amp;#39;: 62446098,&lt;br /&gt;&amp;#39;SPELL&amp;#39;: 61939184,&lt;br /&gt;&amp;#39;TRU&amp;#39;: 60944721,&lt;br /&gt;&amp;#39;REN&amp;#39;: 59955266,&lt;br /&gt;&amp;#39;BIGTIME&amp;#39;: 59209269,&lt;br /&gt;&amp;#39;XVG&amp;#39;: 57470552,&lt;br /&gt;&amp;#39;TLM&amp;#39;: 56963184,&lt;br /&gt;&amp;#39;BAKE&amp;#39;: 52022509,&lt;br /&gt;&amp;#39;COMBO&amp;#39;: 47247951,&lt;br /&gt;&amp;#39;DAR&amp;#39;: 47226484,&lt;br /&gt;&amp;#39;FLM&amp;#39;: 45542629,&lt;br /&gt;&amp;#39;ATA&amp;#39;: 44190701,&lt;br /&gt;&amp;#39;MDT&amp;#39;: 42774267,&lt;br /&gt;&amp;#39;BEL&amp;#39;: 42365397,&lt;br /&gt;&amp;#39;PERP&amp;#39;: 42095057,&lt;br /&gt;&amp;#39;REEF&amp;#39;: 41151983,&lt;br /&gt;&amp;#39;IDEX&amp;#39;: 39463580,&lt;br /&gt;&amp;#39;LEVER&amp;#39;: 38609947,&lt;br /&gt;&amp;#39;PHB&amp;#39;: 36811258,&lt;br /&gt;&amp;#39;LIT&amp;#39;: 35979327,&lt;br /&gt;&amp;#39;KEY&amp;#39;: 31964126,&lt;br /&gt;&amp;#39;BOND&amp;#39;: 29549985,&lt;br /&gt;&amp;#39;FRONT&amp;#39;: 29130102,&lt;br /&gt;&amp;#39;TOKEN&amp;#39;: 28047786,&lt;br /&gt;&amp;#39;AMB&amp;#39;: 24484151&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y6yakhZVRR2EuBPlrJniJl4yzYQNJoE9ijH27m1Norkq9cJx6uDntB1WvRbBs5QeHW70IA9FUvA1MzSOxGOwkN2m0hRm3wSK9DiRPBYiYtMlA1PyuvkBRgHjHc-mZv46XOw" title="https://blog.mathquant.com/2023/12/04/which-is-more-suitable-for-bottom-fishing-low-market-value-or-low-price.html"&gt;https://blog.mathquant.c...-value-or-low-price.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25577/</id>
    <title type="text">Seamless Setup: Installing Interactive Brokers IB Gateway on Linux with Easy-to-Follow Instructions</title>
    <published>2024-03-19T01:24:32Z</published>
    <updated>2024-03-19T01:24:32Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#data" />
    <category term="#market" />
    <category term="#fmz" />
    <category term="#exchange" />
    <category term="#linux" />
    <category term="#brokers" />
    <category term="#robot" />
    <category term="#server" />
    <content type="html">FMZ platform now supports the integration of Interactive Brokers (IB). It&amp;#39;s quite simple on Windows, so we won&amp;#39;t explain how to install it here. For Linux users who generally rent servers without a graphical interface and only have SSH, the installation is more challenging. This article will explain how to install IB Gateway for quantitative trading. We usually choose to install IB Gateway instead of TWS client, because the TWS client shuts down periodically and is not suitable for quantitative trading. Here we take Debian as an example:&lt;br /&gt;&lt;br /&gt;**Step 1: Install Desktop Services and VNC**&lt;br /&gt;&lt;br /&gt;First, you need to install desktop services and a VNC server to enable remote desktop access. Here, we will use xfce and TightVNC as examples. Execute the following commands in the terminal to install:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;sudo apt update&lt;br /&gt;sudo apt install xfce4 xfce4-goodies dbus-x11&lt;br /&gt;sudo apt install tightvncserver&lt;br /&gt;tightvncserver&lt;br /&gt;```&lt;br /&gt;Please note that the maximum length for the password during installation is 8 characters. Please set a highly secure password. The default startup port for the first session is 5901.&lt;br /&gt;&lt;br /&gt;**Step 2: Connect to VNC and Install IB Gateway**&lt;br /&gt;&lt;br /&gt;The default address is ```vnc://IP Address:5901```, you can log in by entering the password. For Windows, please download and install the VNC client yourself.&lt;br /&gt;&lt;br /&gt;Download page: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAADhaXejqp7odOS7glACFvElO2CZpDJRepIcUAnNzmK2sBrdehbuKPGZUeGQMklJCppE4g0E_HskW5TSAMiV8TG0nKnV2xwuGvt3SSC1u084HA" title="https://www.interactivebrokers.com/en/trading/ibgateway-stable.php
"&gt;https://www.interactiveb...ng/ibgateway-stable.php
&lt;/a&gt;&lt;br /&gt;Please use a tool similar to wget for downloading. If you can&amp;#39;t find the corresponding version, please click on &amp;quot;Download for Other Operating Systems&amp;quot; on the page to search.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;wget &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACU5kgXWWBAAeGTg9tDIrTIFNJhPDKBc2eFflF0P1Lw4c8P9OFAq-rjQjdjUFCHzNWwW557dbm2XbVucoCPPA9PvnvpuvPIEQyJQvoYo0ux2Gn8vJ-OEqOMneDzo2wYFKpXY7dCi6qIPPqxmSPcgmM8rXUA0sWPPVAmtyMKRQyr1Q" title="https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh
"&gt;https://download2.intera...standalone-linux-x64.sh
&lt;/a&gt;&lt;br /&gt;```&lt;br /&gt;If it&amp;#39;s inconvenient to download within VNC, you can initiate a separate SSH download and then install it under the VNC desktop environment.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;bash ibgateway-stable-standalone-linux-x64.sh&lt;br /&gt;```&lt;br /&gt;The interface can already be displayed here, you can manually run the installation directory directly by running ```./ibgateway```.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149319
" title="https://stocksharp.com/file/149319
"&gt;https://stocksharp.com/file/149319
&lt;/a&gt;&lt;br /&gt;After installation, log in and find the API option. Make sure to uncheck &amp;quot;Read-Only API&amp;quot;. The port number is also in the settings. Please configure the exchange correctly according to this port number.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149320
" title="https://stocksharp.com/file/149320
"&gt;https://stocksharp.com/file/149320
&lt;/a&gt;&lt;br /&gt;The exchange is configured as follows: Client ID. If you have multiple robots that need to connect, this needs to be set to different IDs, as IB does not allow the same Client ID to connect simultaneously.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149321
" title="https://stocksharp.com/file/149321
"&gt;https://stocksharp.com/file/149321
&lt;/a&gt;&lt;br /&gt;It should be noted that localhost and 127.0.0.1 are not the same network address at the lower level of the Linux operating system, here we use localhost.&lt;br /&gt;&lt;br /&gt;IB&amp;#39;s market data requires a paid subscription. If you need real-time ticker and depth information, please subscribe for a fee, otherwise you can only receive delayed tickers.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y66aICBE83vp0DNNhKDQ9E9Bv-TRcK_228AjVg98XAStIU06yYBwfQdX3d7Rz8ngliD_j2m39-SkbRJoy5HltqYh9HMs9tmjgkpSy_ZB9h63CQRb3JmjqX-NqnIM4acufRg" title="https://blog.mathquant.com/2023/12/04/instructions-for-installing-interactive-brokers-ib-gateway-in-linux-bash.html"&gt;https://blog.mathquant.c...teway-in-linux-bash.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25573/</id>
    <title type="text">Harness the Power of FMZ Extended API: A Step-by-Step Guide to Batch Modify Bot Parameters with Ease</title>
    <published>2024-03-18T08:56:55Z</published>
    <updated>2024-03-18T08:56:55Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#key" />
    <category term="#data" />
    <category term="#fmz" />
    <category term="#API" />
    <category term="#parameters" />
    <category term="#Kline" />
    <content type="html">How can I change the parameters of live tradings in batch on FMZ? When the number of live tradings exceeds dozens and reaches hundreds, it would be very inconvenient to configure live tradings one by one manually. At this time, we can use the FMZ extended API to complete these operations. So in this article, we will explore the group control of the bot, update some details of the parameters.&lt;br /&gt;&lt;br /&gt;In the previous article, we solved the problem of how to use the FMZ extended API to monitor all the live tradings, group control live tradings, and send commands to the live tradings. And we still use the interface call code we encapsulated in the previous article as a basis, continue to write code to realize the batch modification of the parameters of the live trading.&lt;br /&gt;&lt;br /&gt;Parameter settings:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149294
" title="https://stocksharp.com/file/149294
"&gt;https://stocksharp.com/file/149294
&lt;/a&gt;&lt;br /&gt;Strategy code:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;// Global variable&lt;br /&gt;var isLogMsg = true   // Controls whether logs are printed or not&lt;br /&gt;var isDebug = false   // Debugging mode&lt;br /&gt;var arrIndexDesc = [&amp;quot;all&amp;quot;, &amp;quot;running&amp;quot;, &amp;quot;stop&amp;quot;]&lt;br /&gt;var descRobotStatusCode = [&amp;quot;Idle&amp;quot;, &amp;quot;Running&amp;quot;, &amp;quot;Stopping&amp;quot;, &amp;quot;Exited&amp;quot;, &amp;quot;Stopped&amp;quot;, &amp;quot;There is an error in the strategy&amp;quot;]&lt;br /&gt;var dicRobotStatusCode = {&lt;br /&gt;    &amp;quot;all&amp;quot; : -1,&lt;br /&gt;    &amp;quot;running&amp;quot; : 1,&lt;br /&gt;    &amp;quot;stop&amp;quot; : 4,&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Extended logging functions&lt;br /&gt;function LogControl(...args) {&lt;br /&gt;    if (isLogMsg) {&lt;br /&gt;        Log(...args)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// FMZ extended API call functions&lt;br /&gt;function callFmzExtAPI(accessKey, secretKey, funcName, ...args) {&lt;br /&gt;    var params = {&lt;br /&gt;        &amp;quot;version&amp;quot; : &amp;quot;1.0&amp;quot;,&lt;br /&gt;        &amp;quot;access_key&amp;quot; : accessKey,&lt;br /&gt;        &amp;quot;method&amp;quot; : funcName,&lt;br /&gt;        &amp;quot;args&amp;quot; : JSON.stringify(args),&lt;br /&gt;        &amp;quot;nonce&amp;quot; : Math.floor(new Date().getTime())&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    var data = `${params[&amp;quot;version&amp;quot;]}|${params[&amp;quot;method&amp;quot;]}|${params[&amp;quot;args&amp;quot;]}|${params[&amp;quot;nonce&amp;quot;]}|${secretKey}`&lt;br /&gt;    params[&amp;quot;sign&amp;quot;] = Encode(&amp;quot;md5&amp;quot;, &amp;quot;string&amp;quot;, &amp;quot;hex&amp;quot;, data)&lt;br /&gt;    &lt;br /&gt;    var arrPairs = []&lt;br /&gt;    for (var k in params) {&lt;br /&gt;        var pair = `${k}=${params[k]}`&lt;br /&gt;        arrPairs.push(pair)&lt;br /&gt;    }&lt;br /&gt;    var query = arrPairs.join(&amp;quot;&amp;amp;&amp;quot;)&lt;br /&gt;    &lt;br /&gt;    var ret = null&lt;br /&gt;    try {&lt;br /&gt;        LogControl(&amp;quot;url:&amp;quot;, baseAPI + &amp;quot;/api/v1?&amp;quot; + query)&lt;br /&gt;        ret = JSON.parse(HttpQuery(baseAPI + &amp;quot;/api/v1?&amp;quot; + query))&lt;br /&gt;        if (isDebug) {&lt;br /&gt;            LogControl(&amp;quot;Debug:&amp;quot;, ret)&lt;br /&gt;        }&lt;br /&gt;    } catch(e) {&lt;br /&gt;        LogControl(&amp;quot;e.name:&amp;quot;, e.name, &amp;quot;e.stack:&amp;quot;, e.stack, &amp;quot;e.message:&amp;quot;, e.message)&lt;br /&gt;    }&lt;br /&gt;    Sleep(100)  // Control frequency&lt;br /&gt;    return ret &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Get information about all running bots for the specified strategy Id.&lt;br /&gt;function getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode, maxRetry) {&lt;br /&gt;    var retryCounter = 0&lt;br /&gt;    var length = 100&lt;br /&gt;    var offset = 0&lt;br /&gt;    var arr = []&lt;br /&gt;&lt;br /&gt;    if (typeof(maxRetry) == &amp;quot;undefined&amp;quot;) {&lt;br /&gt;        maxRetry = 10&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    while (true) {&lt;br /&gt;        if (retryCounter &amp;gt; maxRetry) {&lt;br /&gt;            LogControl(&amp;quot;Maximum number of retries exceeded&amp;quot;, maxRetry)&lt;br /&gt;            return null&lt;br /&gt;        }&lt;br /&gt;        var ret = callFmzExtAPI(accessKey, secretKey, &amp;quot;GetRobotList&amp;quot;, offset, length, robotStatusCode)&lt;br /&gt;        if (!ret || ret[&amp;quot;code&amp;quot;] != 0) {&lt;br /&gt;            Sleep(1000)&lt;br /&gt;            retryCounter++&lt;br /&gt;            continue&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        var robots = ret[&amp;quot;data&amp;quot;][&amp;quot;result&amp;quot;][&amp;quot;robots&amp;quot;]&lt;br /&gt;        for (var i in robots) {&lt;br /&gt;            if (robots[i].strategy_id != strategyId) {&lt;br /&gt;                continue&lt;br /&gt;            }&lt;br /&gt;            arr.push(robots[i])&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if (robots.length &amp;lt; length) {&lt;br /&gt;            break&lt;br /&gt;        }&lt;br /&gt;        offset += length&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return arr &lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;### Get to Know the RestartRobot Function of the FMZ Extended API First&lt;br /&gt;When we need to batch modify the parameters of the live trading and then run it, there are 2 cases for this scenario to begin with.&lt;br /&gt;&lt;br /&gt;- 1. Bot has been created&lt;br /&gt;For a live trading that has already been created, it is natural to restart it using the RestartRobot function, which is an extended API interface to FMZ.&lt;br /&gt;- 2. Bot has not been created&lt;br /&gt;For the live trading has not been created, there is no need to &amp;quot;modify&amp;quot; the parameters of the live trading, that&amp;#39;s the batch creation of the live trading to run, and we use FMZ extended API interface - NewRobot function.&lt;br /&gt;&lt;br /&gt;But no matter what kind of method, the next idea as well as the operation are similar, so we will use the ```RestartRobot``` extended API function as an example to explain.&lt;br /&gt;&lt;br /&gt;RestartRobot function is used in two ways:&lt;br /&gt;&lt;br /&gt;- 1. Configuration with only live trading ID passed in, not the parameters of live trading&lt;br /&gt;This approach keeps the parameter configuration unchanged when the live trading stopped, and restarts the live trading only.&lt;br /&gt;- 2. Configuration with live trading ID and the parameters of live trading passed in&lt;br /&gt;This approach starts the live trading running with the new parameter configuration.&lt;br /&gt;&lt;br /&gt;The first approach is not useful for our demand scenario, because our own demand is to modify a large number of parameters of the live trading in bulk. So the question is, the configuration of the parameters of the live trading is very complex, there are exchange object configuration, strategy parameter configuration, K-line period settings and so on.&lt;br /&gt;&lt;br /&gt;Do not worry, let&amp;#39;s explore them one by one.&lt;br /&gt;&lt;br /&gt;### Get the Information of the Live Trading You Want to Operate&lt;br /&gt;On FMZ, if you want to modify the parameter configuration of a live trading, then it must be non-running. Because only a live trading that is not running can have its parameter configuration modified. A live trading that is not in the running state may be in:&lt;br /&gt;&lt;br /&gt;- The strategy stopped.&lt;br /&gt;- Strategy has errors, stopped.&lt;br /&gt;&lt;br /&gt;So we need to get the live tradings for the specified strategy first, and these live tradings are in a **stopped state** or **have an error to stop**.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;function main() {&lt;br /&gt;    var stopRobotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, 4)&lt;br /&gt;    var errorRobotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, 5)&lt;br /&gt;    var robotList = stopRobotList.concat(errorRobotList)&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;This gives us all the information about the live trading that we need to change the configuration of, next we will get the detailed configuration of the live trading.&lt;br /&gt;&lt;br /&gt;### Modification of Live Trading Configuration Parameters&lt;br /&gt;For example, the live trading strategy for which we need to modify the parameters is as follows (i.e., the strategy whose strategy ID is the strategyId variable):&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149295
" title="https://stocksharp.com/file/149295
"&gt;https://stocksharp.com/file/149295
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149296
" title="https://stocksharp.com/file/149296
"&gt;https://stocksharp.com/file/149296
&lt;/a&gt;&lt;br /&gt;The strategy has 3 parameters as a test.&lt;br /&gt;&lt;br /&gt;Modify the strategy parameters for the live trading, but maybe we don&amp;#39;t want to modify the strategy&amp;#39;s exchange configuration, but for the Extended API interface RestartRobot function, either no parameters are specified (as is just start the live trading) or all parameter configurations must be specified.&lt;br /&gt;&lt;br /&gt;That is to say, before we use the RestartRobot function to start the live trading, we must use the extended API interface GetRobotDetail function to get the current configuration of the live trading first, and then we replace the part of the parameters that need to be modified, to re-construct the configuration parameters for the start of the live trading (i.e., the parameters that will be used to call RestartRobot), and then restart the live trading.&lt;br /&gt;&lt;br /&gt;So, next we traverse robotList, and get the current parameter configuration one by one, the ```/**/``` commented part of the following code is the live trading details, we need to deal with these data.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;function main() {&lt;br /&gt;    var stopRobotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, 4)&lt;br /&gt;    var errorRobotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, 5)&lt;br /&gt;&lt;br /&gt;    var robotList = stopRobotList.concat(errorRobotList)&lt;br /&gt;    _.each(robotList, function(robotInfo) {&lt;br /&gt;        var robotDetail = callFmzExtAPI(accessKey, secretKey, &amp;quot;GetRobotDetail&amp;quot;, robotInfo.id)&lt;br /&gt;        &lt;br /&gt;        /*&lt;br /&gt;        {&lt;br /&gt;            &amp;quot;code&amp;quot;: 0,&lt;br /&gt;            &amp;quot;data&amp;quot;: {&lt;br /&gt;                &amp;quot;result&amp;quot;: {&lt;br /&gt;                    &amp;quot;robot&amp;quot;: {&lt;br /&gt;                        ...&lt;br /&gt;                        &amp;quot;id&amp;quot;: 130350,&lt;br /&gt;                        ...&lt;br /&gt;                        &amp;quot;name&amp;quot;: &amp;quot;Test 1B&amp;quot;,&lt;br /&gt;                        &amp;quot;node_id&amp;quot;: 3022561,&lt;br /&gt;                        ...&lt;br /&gt;                        &amp;quot;robot_args&amp;quot;: &amp;quot;[[\&amp;quot;pairs\&amp;quot;,\&amp;quot;BTC_USDT,ETH_USDT,EOS_USDT,LTC_USDT\&amp;quot;],[\&amp;quot;col\&amp;quot;,3],[\&amp;quot;htight\&amp;quot;,300]]&amp;quot;,&lt;br /&gt;                        &amp;quot;start_time&amp;quot;: &amp;quot;2023-11-19 21:16:12&amp;quot;,&lt;br /&gt;                        &amp;quot;status&amp;quot;: 5,&lt;br /&gt;                        &amp;quot;strategy_args&amp;quot;: &amp;quot;[[\&amp;quot;pairs\&amp;quot;,\&amp;quot;Currency list\&amp;quot;,\&amp;quot;English comma spacing\&amp;quot;,\&amp;quot;BTC_USDT,ETH_USDT,EOS_USDT,LTC_USDT\&amp;quot;],[\&amp;quot;col\&amp;quot;,\&amp;quot;breadth\&amp;quot;,\&amp;quot;Total width of the page is 12\&amp;quot;,6],[\&amp;quot;htight\&amp;quot;,\&amp;quot;height\&amp;quot;,\&amp;quot;unit px\&amp;quot;,600],[\&amp;quot;$$$__cmd__$$$coverSymbol\&amp;quot;,\&amp;quot;close the position\&amp;quot;,\&amp;quot;close out trading pairs\&amp;quot;,\&amp;quot;\&amp;quot;]]&amp;quot;,&lt;br /&gt;                        &amp;quot;strategy_exchange_pairs&amp;quot;: &amp;quot;[3600,[186193],[\&amp;quot;BTC_USD\&amp;quot;]]&amp;quot;,&lt;br /&gt;                        &amp;quot;strategy_id&amp;quot;: 131242,&lt;br /&gt;                        &amp;quot;strategy_last_modified&amp;quot;: &amp;quot;2023-12-09 23:14:33&amp;quot;,&lt;br /&gt;                        &amp;quot;strategy_name&amp;quot;: &amp;quot;Test 1&amp;quot;,&lt;br /&gt;                        ...&lt;br /&gt;                    }&lt;br /&gt;                },&lt;br /&gt;                &amp;quot;error&amp;quot;: null&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        */&lt;br /&gt;&lt;br /&gt;        // Parse the exchange configuration data&lt;br /&gt;        var exchangePairs = JSON.parse(robotDetail.data.result.robot.strategy_exchange_pairs)&lt;br /&gt;&lt;br /&gt;        // Get the exchange object index, trading pairs, these settings are not going to be changed&lt;br /&gt;        var arrExId = exchangePairs[1]&lt;br /&gt;        var arrSymbol = exchangePairs[2]&lt;br /&gt;&lt;br /&gt;        // Parse parameter configuration data&lt;br /&gt;        var params = JSON.parse(robotDetail.data.result.robot.robot_args)&lt;br /&gt;&lt;br /&gt;        // Update parameters&lt;br /&gt;        var dicParams = {&lt;br /&gt;            &amp;quot;pairs&amp;quot; : &amp;quot;AAA_BBB,CCC_DDD&amp;quot;,&lt;br /&gt;            &amp;quot;col&amp;quot; : &amp;quot;999&amp;quot;,&lt;br /&gt;            &amp;quot;htight&amp;quot; : &amp;quot;666&amp;quot;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        var newParams = []&lt;br /&gt;        _.each(params, function(param) {&lt;br /&gt;            for (var k in dicParams) {&lt;br /&gt;                if (param[0] == k) {&lt;br /&gt;                    newParams.push([k, dicParams[k]])  // Construct the strategy parameters and update the new parameter values&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        })&lt;br /&gt;        &lt;br /&gt;        // Note that if there are spaces in the data you need to transcode it, otherwise the request will report an error&lt;br /&gt;        settings = {&lt;br /&gt;            &amp;quot;name&amp;quot;: robotDetail.data.result.robot.name,&lt;br /&gt;            // Strategy parameter&lt;br /&gt;            &amp;quot;args&amp;quot;: newParams,         &lt;br /&gt;            // The strategy ID can be obtained by the GetStrategyList method.&lt;br /&gt;            &amp;quot;strategy&amp;quot;: robotDetail.data.result.robot.strategy_id,&lt;br /&gt;            // K-period parameter, 60 means 60 seconds&lt;br /&gt;            &amp;quot;period&amp;quot;: exchangePairs[0],&lt;br /&gt;            // Specifies which docker to run on; not writing this attribute means automatically assigning the run&lt;br /&gt;            &amp;quot;node&amp;quot; : robotDetail.data.result.robot.node_id,&lt;br /&gt;            &amp;quot;exchanges&amp;quot;: []&lt;br /&gt;        }&lt;br /&gt;                                &lt;br /&gt;        for (var i = 0 ; i &amp;lt; arrExId.length ; i++) {&lt;br /&gt;            settings[&amp;quot;exchanges&amp;quot;].push({&amp;quot;pid&amp;quot;: arrExId[i], &amp;quot;pair&amp;quot;: arrSymbol[i]})&lt;br /&gt;        }&lt;br /&gt;        Log(settings) // Test&lt;br /&gt;        var retRestart = callFmzExtAPI(accessKey, secretKey, &amp;quot;RestartRobot&amp;quot;, robotInfo.id, settings)&lt;br /&gt;        Log(&amp;quot;retRestart:&amp;quot;, retRestart)&lt;br /&gt;    })&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;After running the batch parameter modification strategy, my live trading:&lt;br /&gt;&lt;br /&gt;- Test 1A&lt;br /&gt;- Test 1B&lt;br /&gt;&lt;br /&gt;Batch modification of parameters was done with the configured exchange objects, trading pairs and K-line periods unchanged:&lt;br /&gt;&lt;br /&gt;It was changed on the live trading page automatically:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149297
" title="https://stocksharp.com/file/149297
"&gt;https://stocksharp.com/file/149297
&lt;/a&gt;&lt;br /&gt;And start running. Because we specified the modified parameters in the code above:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;        // Update parameters&lt;br /&gt;        var dicParams = {&lt;br /&gt;            &amp;quot;pairs&amp;quot; : &amp;quot;AAA_BBB,CCC_DDD&amp;quot;,&lt;br /&gt;            &amp;quot;col&amp;quot; : &amp;quot;999&amp;quot;,&lt;br /&gt;            &amp;quot;htight&amp;quot; : &amp;quot;666&amp;quot;&lt;br /&gt;        }&lt;br /&gt;```&lt;br /&gt;### END&lt;br /&gt;For dozens, hundreds of live trading batch modify parameters, this method is more convenient. In the example, the parameters are modified to a uniform, of course you can customize your own modification rules in the code to specify different parameter configurations for each live trading. Or specify different exchange objects, trading pairs and so on.&lt;br /&gt;&lt;br /&gt;For the FMZ platform, these requirements are flexible and customizable to achieve. Feel free to leave a comment if you have any requirement ideas, we can discuss, research and learn from each other , and find the solution to the problem.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y61uCdRjWUjTNbtm92rvOKC9BxFOeM6rvv0o6aDWUN6x-a6TC71ZsaT_piJ5LyAyK_UtNcg69NV0oCDRWY2yJbcHAzDTrfCJSfNucrTdJuclshosoM9qkhyZGsq2B6wRR1A" title="https://blog.mathquant.com/2023/12/11/teach-you-to-use-the-fmz-extended-api-to-batch-modify-parameters-of-the-bot.html"&gt;https://blog.mathquant.c...rameters-of-the-bot.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25572/</id>
    <title type="text">Unlocking the Secrets of Perpetual Contract Grid Strategy Parameter Optimization with Python Backtesting</title>
    <published>2024-03-18T05:23:38Z</published>
    <updated>2024-03-18T05:23:38Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#fmz" />
    <category term="#contract" />
    <category term="#grid" />
    <category term="#parameter" />
    <category term="#DYDX" />
    <category term="#risk" />
    <content type="html">The perpetual grid strategy is a popular classic strategy on FMZ platform. Compared with the spot grid, there is no need to have currencies, and leverage can be added, which is much more convenient than the spot grid. However, since it is not possible to backtest on the FMZ Quant Platform directly, it is not conducive to screening currencies and determining parameter optimization. In this article, we will introduce the complete Python backtesting process, including data collection, backtesting framework, backtesting functions, parameter optimization, etc. You can try it yourself in juypter notebook.&lt;br /&gt;&lt;br /&gt;### Data Collection&lt;br /&gt;Generally, it is enough to use K-line data. For accuracy, the smaller the K-line period, the better. However, to balance the backtest time and data volume, in this article, we use 5min of data from the past two years for backtesting. The final data volume exceeded 200,000 lines. We choose DYDX as the currency. Of course, the specific currency and K-line period can be selected according to your own interests.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;import requests&lt;br /&gt;from datetime import date,datetime&lt;br /&gt;import time&lt;br /&gt;import pandas as pd&lt;br /&gt;import numpy as np&lt;br /&gt;import matplotlib.pyplot as plt&lt;br /&gt;import requests, zipfile, io&lt;br /&gt;%matplotlib inline&lt;br /&gt;&lt;br /&gt;def GetKlines(symbol=&amp;#39;BTC&amp;#39;,start=&amp;#39;2020-8-10&amp;#39;,end=&amp;#39;2021-8-10&amp;#39;,period=&amp;#39;1h&amp;#39;):&lt;br /&gt;    Klines = []&lt;br /&gt;    start_time = int(time.mktime(datetime.strptime(start, &amp;quot;%Y-%m-%d&amp;quot;).timetuple()))*1000&lt;br /&gt;    end_time = int(time.mktime(datetime.strptime(end, &amp;quot;%Y-%m-%d&amp;quot;).timetuple()))*1000&lt;br /&gt;    while start_time &amp;lt; end_time:&lt;br /&gt;        res = requests.get(&amp;#39;https://fapi.binance.com/fapi/v1/klines?symbol=%sUSDT&amp;amp;interval=%s&amp;amp;startTime=%s&amp;amp;limit=1000&amp;#39;%(symbol,period,start_time))&lt;br /&gt;        res_list = res.json()&lt;br /&gt;        Klines += res_list&lt;br /&gt;        start_time = res_list[-1][0]&lt;br /&gt;    return pd.DataFrame(Klines,columns=[&amp;#39;time&amp;#39;,&amp;#39;open&amp;#39;,&amp;#39;high&amp;#39;,&amp;#39;low&amp;#39;,&amp;#39;close&amp;#39;,&amp;#39;amount&amp;#39;,&amp;#39;end_time&amp;#39;,&amp;#39;volume&amp;#39;,&amp;#39;count&amp;#39;,&amp;#39;buy_amount&amp;#39;,&amp;#39;buy_volume&amp;#39;,&amp;#39;null&amp;#39;]).astype(&amp;#39;float&amp;#39;)&lt;br /&gt;&lt;br /&gt;df = GetKlines(symbol=&amp;#39;DYDX&amp;#39;,start=&amp;#39;2022-1-1&amp;#39;,end=&amp;#39;2023-12-7&amp;#39;,period=&amp;#39;5m&amp;#39;)&lt;br /&gt;df = df.drop_duplicates()&lt;br /&gt;```&lt;br /&gt;### Backtesting Framework&lt;br /&gt;For backtesting, we continue to choose the commonly used framework that supports USDT perpetual contracts in multiple currencies, which is simple and easy to use.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;class Exchange:&lt;br /&gt;    &lt;br /&gt;    def __init__(self, trade_symbols, fee=0.0004, initial_balance=10000):&lt;br /&gt;        self.initial_balance = initial_balance #Initial assets&lt;br /&gt;        self.fee = fee&lt;br /&gt;        self.trade_symbols = trade_symbols&lt;br /&gt;        self.account = {&amp;#39;USDT&amp;#39;:{&amp;#39;realised_profit&amp;#39;:0, &amp;#39;unrealised_profit&amp;#39;:0, &amp;#39;total&amp;#39;:initial_balance, &amp;#39;fee&amp;#39;:0}}&lt;br /&gt;        for symbol in trade_symbols:&lt;br /&gt;            self.account[symbol] = {&amp;#39;amount&amp;#39;:0, &amp;#39;hold_price&amp;#39;:0, &amp;#39;value&amp;#39;:0, &amp;#39;price&amp;#39;:0, &amp;#39;realised_profit&amp;#39;:0,&amp;#39;unrealised_profit&amp;#39;:0,&amp;#39;fee&amp;#39;:0}&lt;br /&gt;            &lt;br /&gt;    def Trade(self, symbol, direction, price, amount):&lt;br /&gt;        &lt;br /&gt;        cover_amount = 0 if direction*self.account[symbol][&amp;#39;amount&amp;#39;] &amp;gt;=0 else min(abs(self.account[symbol][&amp;#39;amount&amp;#39;]), amount)&lt;br /&gt;        open_amount = amount - cover_amount&lt;br /&gt;        self.account[&amp;#39;USDT&amp;#39;][&amp;#39;realised_profit&amp;#39;] -= price*amount*self.fee #Deduction of handling fee&lt;br /&gt;        self.account[&amp;#39;USDT&amp;#39;][&amp;#39;fee&amp;#39;] += price*amount*self.fee&lt;br /&gt;        self.account[symbol][&amp;#39;fee&amp;#39;] += price*amount*self.fee&lt;br /&gt;&lt;br /&gt;        if cover_amount &amp;gt; 0: #Close the position first.&lt;br /&gt;            self.account[&amp;#39;USDT&amp;#39;][&amp;#39;realised_profit&amp;#39;] += -direction*(price - self.account[symbol][&amp;#39;hold_price&amp;#39;])*cover_amount  #Profits&lt;br /&gt;            self.account[symbol][&amp;#39;realised_profit&amp;#39;] += -direction*(price - self.account[symbol][&amp;#39;hold_price&amp;#39;])*cover_amount&lt;br /&gt;            &lt;br /&gt;            self.account[symbol][&amp;#39;amount&amp;#39;] -= -direction*cover_amount&lt;br /&gt;            self.account[symbol][&amp;#39;hold_price&amp;#39;] = 0 if self.account[symbol][&amp;#39;amount&amp;#39;] == 0 else self.account[symbol][&amp;#39;hold_price&amp;#39;]&lt;br /&gt;            &lt;br /&gt;        if open_amount &amp;gt; 0:&lt;br /&gt;            total_cost = self.account[symbol][&amp;#39;hold_price&amp;#39;]*direction*self.account[symbol][&amp;#39;amount&amp;#39;] + price*open_amount&lt;br /&gt;            total_amount = direction*self.account[symbol][&amp;#39;amount&amp;#39;]+open_amount&lt;br /&gt;            &lt;br /&gt;            self.account[symbol][&amp;#39;hold_price&amp;#39;] = total_cost/total_amount&lt;br /&gt;            self.account[symbol][&amp;#39;amount&amp;#39;] += direction*open_amount&lt;br /&gt;                    &lt;br /&gt;    &lt;br /&gt;    def Buy(self, symbol, price, amount):&lt;br /&gt;        self.Trade(symbol, 1, price, amount)&lt;br /&gt;        &lt;br /&gt;    def Sell(self, symbol, price, amount):&lt;br /&gt;        self.Trade(symbol, -1, price, amount)&lt;br /&gt;        &lt;br /&gt;    def Update(self, close_price): #Updating of assets&lt;br /&gt;        self.account[&amp;#39;USDT&amp;#39;][&amp;#39;unrealised_profit&amp;#39;] = 0&lt;br /&gt;        for symbol in self.trade_symbols:&lt;br /&gt;            self.account[symbol][&amp;#39;unrealised_profit&amp;#39;] = (close_price[symbol] - self.account[symbol][&amp;#39;hold_price&amp;#39;])*self.account[symbol][&amp;#39;amount&amp;#39;]&lt;br /&gt;            self.account[symbol][&amp;#39;price&amp;#39;] = close_price[symbol]&lt;br /&gt;            self.account[symbol][&amp;#39;value&amp;#39;] = abs(self.account[symbol][&amp;#39;amount&amp;#39;])*close_price[symbol]&lt;br /&gt;            self.account[&amp;#39;USDT&amp;#39;][&amp;#39;unrealised_profit&amp;#39;] += self.account[symbol][&amp;#39;unrealised_profit&amp;#39;]&lt;br /&gt;        self.account[&amp;#39;USDT&amp;#39;][&amp;#39;total&amp;#39;] = round(self.account[&amp;#39;USDT&amp;#39;][&amp;#39;realised_profit&amp;#39;] + self.initial_balance + self.account[&amp;#39;USDT&amp;#39;][&amp;#39;unrealised_profit&amp;#39;],6)&lt;br /&gt;```&lt;br /&gt;### Grid Backtest Function&lt;br /&gt;The principle of the grid strategy is very simple. Sell when the price rises and buy when the price falls. It specifically involves three parameters: initial price, grid spacing, and trading value. The market of DYDX fluctuates greatly. It fell from the initial low of 8.6U to 1U, and then rose back to 3U in the recent bull market. The default initial price of the strategy is 8.6U, which is very unfavorable for the grid strategy, but the default parameters backtested a total profit of 9200U was made in two years, and a loss of 7500U was made during the period.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149291
" title="https://stocksharp.com/file/149291
"&gt;https://stocksharp.com/file/149291
&lt;/a&gt;&lt;br /&gt;```&lt;br /&gt;symbol = &amp;#39;DYDX&amp;#39;&lt;br /&gt;value = 100&lt;br /&gt;pct = 0.01&lt;br /&gt;&lt;br /&gt;def Grid(fee=0.0002, value=100, pct=0.01, init = df.close[0]):&lt;br /&gt;    e = Exchange([symbol], fee=0.0002, initial_balance=10000)&lt;br /&gt;    init_price = init&lt;br /&gt;    res_list = [] #For storing intermediate results&lt;br /&gt;    for row in df.iterrows():&lt;br /&gt;        kline = row[1] #To backtest a K-line will only generate one buy order or one sell order, which is not particularly accurate.&lt;br /&gt;        buy_price = (value / pct - value) / ((value / pct) / init_price + e.account[symbol][&amp;#39;amount&amp;#39;]) #The buy order price, as it is a pending order transaction, is also the final aggregated price&lt;br /&gt;        sell_price = (value / pct + value) / ((value / pct) / init_price + e.account[symbol][&amp;#39;amount&amp;#39;])&lt;br /&gt;        if kline.low &amp;lt; buy_price: #The lowest price of the K-line is lower than the current pending order price, the buy order is filled&lt;br /&gt;            e.Buy(symbol,buy_price,value/buy_price)&lt;br /&gt;        if kline.high &amp;gt; sell_price:&lt;br /&gt;            e.Sell(symbol,sell_price,value/sell_price)&lt;br /&gt;        e.Update({symbol:kline.close})&lt;br /&gt;        res_list.append([kline.time, kline.close, e.account[symbol][&amp;#39;amount&amp;#39;], e.account[&amp;#39;USDT&amp;#39;][&amp;#39;total&amp;#39;]-e.initial_balance,e.account[&amp;#39;USDT&amp;#39;][&amp;#39;fee&amp;#39;] ])&lt;br /&gt;    res = pd.DataFrame(data=res_list, columns=[&amp;#39;time&amp;#39;,&amp;#39;price&amp;#39;,&amp;#39;amount&amp;#39;,&amp;#39;profit&amp;#39;, &amp;#39;fee&amp;#39;])&lt;br /&gt;    res.index = pd.to_datetime(res.time,unit=&amp;#39;ms&amp;#39;)&lt;br /&gt;    return res&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149292
" title="https://stocksharp.com/file/149292
"&gt;https://stocksharp.com/file/149292
&lt;/a&gt;&lt;br /&gt;### Initial Price Impact&lt;br /&gt;The setting of the initial price affects the initial position of the strategy. The default initial price for the backtest just now is the initial price at startup, that is, no position is held at startup. And we know that the grid strategy will realize all profits when the price returns to the initial stage, so if the strategy can correctly predict the future market when it is launched, the income will be significantly improved. Here, we set the initial price to 3U and then backtest. In the end, the maximum drawdown was 9200U, and the final profit was 13372U. The final strategy does not hold positions. The profit is all the fluctuation profits, and the difference between the profits of the default parameters is the position loss caused by inaccurate judgment of the final price.&lt;br /&gt;&lt;br /&gt;However, if the initial price is set to 3U, the strategy will go short at the beginning and hold a large number of short positions. In this example, a short order of 17,000 U is directly held, so it faces greater risks.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149293
" title="https://stocksharp.com/file/149293
"&gt;https://stocksharp.com/file/149293
&lt;/a&gt;&lt;br /&gt;### Grid Spacing Settings&lt;br /&gt;The grid spacing determines the distance between pending orders. Obviously, the smaller the spacing, the more frequent the transactions, the lower the profit of a single transaction, and the higher the handling fee. However, it is worth noting that as the grid spacing becomes smaller and the grid value remains unchanged, when the price changes, the total positions will increase, and the risks faced are completely different. Therefore, to backtest the effect of grid spacing, it is necessary to convert the grid value.&lt;br /&gt;&lt;br /&gt;Since the backtest uses 5m K-line data, and each K-line is only traded once, which is obviously unrealistic, especially since the volatility of digital currencies is very high. A smaller spacing will miss many transactions in backtesting compared with the live trading. Only a larger spacing will have reference value. In this backtesting mechanism, the conclusions drawn are not accurate. Through tick-level order flow data backtesting, the optimal grid spacing should be 0.005-0.01.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;for p in [0.0005, 0.001 ,0.002 ,0.005, 0.01, 0.02, 0.05]:&lt;br /&gt;    res = Grid( fee=0.0002, value=value*p/0.01, pct=p, init =3)&lt;br /&gt;    print(p, round(min(res[&amp;#39;profit&amp;#39;]),0), round(res[&amp;#39;profit&amp;#39;][-1],0), round(res[&amp;#39;fee&amp;#39;][-1],0))&lt;br /&gt;    &lt;br /&gt;0.0005 -8378.0 144.0 237.0&lt;br /&gt;0.001 -9323.0 1031.0 465.0&lt;br /&gt;0.002 -9306.0 3606.0 738.0&lt;br /&gt;0.005 -9267.0 9457.0 781.0&lt;br /&gt;0.01 -9228.0 13375.0 550.0&lt;br /&gt;0.02 -9183.0 15212.0 309.0&lt;br /&gt;0.05 -9037.0 16263.0 131.0&lt;br /&gt;```&lt;br /&gt;### Grid Transaction Value&lt;br /&gt;As mentioned before, when the fluctuations are the same, the greater the value of the holding, the risk is proportional. However, as long as there is no rapid decline, 1% of the total funds and 1% of the grid spacing should be able to cope with most market conditions. In this DYDX example, a drop of almost 90% also triggered a liquidation. However, it should be noted that DYDX mainly falls. When the grid strategy goes long when it falls, it will fall by 100% at most, while there is no limit on the rise, and the risk is much higher. Therefore, Grid Strategy recommends users to choose only the long position mode for currencies they believe have potential.&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y6-pZvlamVNemG-BHT3hNGA8yhxHJ0ma5MTkxgWOTi7w44vQNGgQq1Th2F6NH16o_UhXJ02URaiN-8M4TuDWzs0KQXROsnsDeNXfYgQOYxa_V1Xl_G4p9VUu-PYiToPP-Ew" title="https://blog.mathquant.com/2023/12/11/detailed-explanation-of-perpetual-contract-grid-strategy-parameter-optimization.html"&gt;https://blog.mathquant.c...ameter-optimization.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25571/</id>
    <title type="text">How to Exploit Brainless Selling Bots with a High-Frequency Strategy in 80 Lines of Code</title>
    <published>2024-03-18T01:37:44Z</published>
    <updated>2024-03-18T01:37:44Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#market" />
    <category term="#fmz" />
    <category term="#bots" />
    <category term="#highfrequency" />
    <category term="#spot" />
    <category term="#orders" />
    <content type="html"># How to Exploit Brainless Selling Bots with a High-Frequency Strategy in 80 Lines of Code&lt;br /&gt;&lt;br /&gt;### Opportunity Observation&lt;br /&gt;Recently, I found that Binance has a currency STORJ market is very strange unintentionally when I was watching the market, the trading volume is very large, and the trading frequency is very fast, the specific one-minute K-line of the following chart, we can see that the trading volume of each minute are consistent, and the minute K-line can be seen in a long lower shadow line.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149286
" title="https://stocksharp.com/file/149286
"&gt;https://stocksharp.com/file/149286
&lt;/a&gt;&lt;br /&gt;Observe with Binance 1-second K-line, I found out the end of the story, someone is marketed 10,000-20,000 STORJs every 5-7s, regardless of the cost, and smashing a small hole in the K-line directly, while the price recovers in the short term. This operation was obviously caused by a robot on an iceberg commission. This selling operation lasted for a very long time, totaling an estimated $10 million level, and in many cases caused slippage of up to 0.1%, which means that the executor of this strategy lost tens of thousands of dollars in slippage on the trade only. But with such a mechanical operation and active trading, there was a clear opportunity for market making scalping.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149288
" title="https://stocksharp.com/file/149288
"&gt;https://stocksharp.com/file/149288
&lt;/a&gt;&lt;br /&gt;A simple change to the original spot HF strategy, and in a few minutes I got this bot that specializes in exploiting this brainless sale of iceberg commissions.&lt;br /&gt;&lt;br /&gt;### Strategy Idea&lt;br /&gt;Since the market sells in market price every few seconds, we just need to find the 10k depth in the buy order book and hang the order in front of it. So that when the iceberg sells, a high probability that the market-making robot just can receive, and at this time the transaction is very active, the momentary price decline also triggered some buy orders. By the same token, hanging sell orders can be thrown in the trend, so repeated operations. The frequency of transactions is very high, even if each time the yield is not large, the total return is also quite substantial. Of course, the premise of everything is to have a low-fee account, if the buying and selling fees both are 0.1%, then the space is not enough to pay the fees.&lt;br /&gt;&lt;br /&gt;### Strategy Performance&lt;br /&gt;The strategy is performing as follows, at first, none of the profits were printing, so I changed it this afternoon, and print out the profits, the crazy selling robots have changed the volume to about 5000 at a time, so it&amp;#39;s past the optimal time for arbitrage. I&amp;#39;m probably making 100-200U per hour at first, the key is risk free and low cost. On the flip side, the iceberg commission actually has a lot of skills, if you know how to write a strategy, you can spend ten minutes on FMZ to write the iceberg commission strategy that observes the depth of the buy order to decide the size and price of the order, observes the size of the active buy order to adjust the size of the pending order and take up the market monitoring and other characteristics, saving tens of thousands of dollars easily.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149289
" title="https://stocksharp.com/file/149289
"&gt;https://stocksharp.com/file/149289
&lt;/a&gt;&lt;br /&gt;### Strategy Source Code&lt;br /&gt;The strategy code is very simple, only 80 lines, which is suitable for beginners, here are some of the parameters such as order precision and so on written fixed in the program, you can change the parameters as follows. It is recommended to save it, in case of any exchange trading pairs or the traders are out of control, you can fell free to charge them some interest at any time.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149290
" title="https://stocksharp.com/file/149290
"&gt;https://stocksharp.com/file/149290
&lt;/a&gt;&lt;br /&gt;```&lt;br /&gt;function CancelPendingOrders() {&lt;br /&gt;    var orders = _C(exchange.GetOrders)&lt;br /&gt;    for (var j = 0; j &amp;lt; orders.length; j++) {&lt;br /&gt;        exchange.CancelOrder(orders[j].Id, orders[j])&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function onexit(){&lt;br /&gt;    CancelPendingOrders()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function GetPrice(Type, Depth) {&lt;br /&gt;    var sumAmount = 0&lt;br /&gt;    var checkAmount = Type == &amp;quot;Buy&amp;quot; ? CheckBuyAmount : CheckSellAmount&lt;br /&gt;    var deep = Type == &amp;quot;Buy&amp;quot; ? Depth.Bids : Depth.Asks&lt;br /&gt;    for(var i = 0; i &amp;lt; Math.min(20, deep.length); i++) {&lt;br /&gt;        if(Type == &amp;quot;Buy&amp;quot;  &amp;amp;&amp;amp; deep[i].Price == lastBuyPrice &amp;amp;&amp;amp; buyId){&lt;br /&gt;            sumAmount += deep[i].Amount - amountBuy //Subtract your own pending orders here&lt;br /&gt;        }else if(Type == &amp;quot;Sell&amp;quot;  &amp;amp;&amp;amp; deep[i].Price == lastSellPrice &amp;amp;&amp;amp; sellId){&lt;br /&gt;            sumAmount += deep[i].Amount - amountSell&lt;br /&gt;        }else{&lt;br /&gt;            sumAmount += deep[i].Amount&lt;br /&gt;        }&lt;br /&gt;        if(sumAmount &amp;gt;= checkAmount){&lt;br /&gt;            return deep[i].Price&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return deep[19].Price&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function OnTick() {&lt;br /&gt;    var depth = _C(exchange.GetDepth)&lt;br /&gt;    var buyPrice = _N(Math.min(GetPrice(&amp;quot;Buy&amp;quot;, depth) + 0.0001, depth.Asks[0].Price-0.0001) , 4) //Guaranteed at the market&lt;br /&gt;    var sellPrice = _N(Math.max(GetPrice(&amp;quot;Sell&amp;quot;, depth) - 0.0001, depth.Bids[0].Price+0.0001), 4)&lt;br /&gt;    LogStatus(&amp;#39;buy_price:&amp;#39;+buyPrice, &amp;#39;  sell price: &amp;#39;+sellPrice)&lt;br /&gt;    if ((sellPrice - buyPrice) &amp;lt; DiffPrice) {&lt;br /&gt;        buyPrice = 0&lt;br /&gt;    }&lt;br /&gt;    if(sellPrice != lastSellPrice &amp;amp;&amp;amp; sellId){&lt;br /&gt;        exchange.CancelOrder(sellId);&lt;br /&gt;        sellId = 0&lt;br /&gt;        lastSellPrice = 0&lt;br /&gt;    }&lt;br /&gt;    if(buyPrice != lastBuyPrice &amp;amp;&amp;amp; buyId){&lt;br /&gt;        exchange.CancelOrder(buyId);&lt;br /&gt;        buyId = 0&lt;br /&gt;        lastBuyPrice = 0&lt;br /&gt;    }   &lt;br /&gt;    var acc = _C(exchange.GetAccount)&lt;br /&gt;    if(account.Stocks+account.FrozenStocks != acc.Stocks+acc.FrozenStocks){&lt;br /&gt;        LogProfit((acc.Stocks+acc.FrozenStocks)*depth.Bids[0].Price+acc.Balance+acc.FrozenBalance - 2000)&lt;br /&gt;        Log(&amp;#39;free &amp;#39;+acc.Stocks, &amp;#39; lock: &amp;#39;+ acc.FrozenStocks, &amp;#39; total: &amp;#39; , (acc.Stocks+acc.FrozenStocks)*depth.Bids[0].Price+acc.Balance+acc.FrozenBalance)&lt;br /&gt;    }&lt;br /&gt;    account = acc&lt;br /&gt;    amountBuy = _N(Math.min(account.Balance / buyPrice - 0.1, Amount), 0)&lt;br /&gt;    amountSell = _N(account.Stocks, 0)&lt;br /&gt;    if (sellPrice &amp;gt; 0 &amp;amp;&amp;amp; amountSell &amp;gt; 40 &amp;amp;&amp;amp; sellId == 0) {&lt;br /&gt;        sellId = exchange.Sell(_N(sellPrice,4), amountSell)&lt;br /&gt;        lastSellPrice = sellPrice&lt;br /&gt;    }&lt;br /&gt;    if (buyPrice&amp;gt;0 &amp;amp;&amp;amp; amountBuy &amp;gt; 40 &amp;amp;&amp;amp; buyId == 0) {&lt;br /&gt;        buyId = exchange.Buy(_N(buyPrice,4), amountBuy)&lt;br /&gt;        lastBuyPrice = buyPrice&lt;br /&gt;    }&lt;br /&gt;    Sleep(Interval)&lt;br /&gt;}&lt;br /&gt;var account = {Stocks:0, FrozenStocks:0, Balance:0, FrozenBalance:0}&lt;br /&gt;var buyId = 0&lt;br /&gt;var sellId = 0&lt;br /&gt;var lastBuyPrice = 0&lt;br /&gt;var lastSellPrice = 0&lt;br /&gt;var amountSell = 0&lt;br /&gt;var amountBuy = 0&lt;br /&gt;var log_account_time = 0&lt;br /&gt;function main() {&lt;br /&gt;    CancelPendingOrders()&lt;br /&gt;    while (true) {&lt;br /&gt;        OnTick()&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y68KbrUbzjIJ1j709jbmqf8p4YYLYbda_SSPq72HsvOcwsrBXYbrGahQeg4VzdrQRBzw5LbpVYM55zJv7-5SKRfDKSX2nQMst-gtIamdFLlrv8gHCkVQgBZVHc6_481X-ZzoNs9r9ENy89GsPXd69plk" title="https://blog.mathquant.com/2023/12/25/how-to-exploit-brainless-selling-bots-with-a-high-frequency-strategy-in-80-lines-of-code.html"&gt;https://blog.mathquant.c...in-80-lines-of-code.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25567/</id>
    <title type="text">An Analysis of Common Requirements Design Examples in the Cryptocurrency Market (II)</title>
    <published>2024-03-15T06:42:30Z</published>
    <updated>2024-03-15T06:42:30Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#code" />
    <category term="#market" />
    <category term="#analysis" />
    <category term="#fmz" />
    <category term="#contract" />
    <category term="#exchange" />
    <category term="#javascript" />
    <category term="#binance" />
    <content type="html"># FMZ Quant: An Analysis of Common Requirements Design Examples in the Cryptocurrency Market (II)&lt;br /&gt;&lt;br /&gt;In response to the comments from readers in the previous article, they requested a program example for monitoring contract account transfers. In this article, we will use Binance exchange as the test object to implement the requirement and learn how to design it together.&lt;br /&gt;&lt;br /&gt;Cryptocurrency exchanges handle a large number of transactions every day, including the transfer of assets between different wallets. Monitoring these transfers in real time is crucial for traders and developers. In this article, we will explore a piece of JavaScript code designed to monitor recent asset transfers on a cryptocurrency exchange and discuss its key components.&lt;br /&gt;&lt;br /&gt;### Analyze Requirements&lt;br /&gt;I checked the documentation of Binance exchange and found that there is a transfer history interface that can query all transfer information. Since we are only monitoring transfer records that may occur, we do not need to obtain all transfer history. We only need to check recent transfer records within a certain range based on a certain frequency. If new transfer records are found, they will be updated and notified.&lt;br /&gt;&lt;br /&gt;Use the interface:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;// GET /sapi/v1/asset/transfer type, size : 100&lt;br /&gt;```&lt;br /&gt;So how to check the newly added transfer record? After reading Binance&amp;#39;s documentation, I found that there is a timestamp in the data returned by this interface. It is very simple to judge by the timestamp. As long as there is a record larger than the maximum timestamp currently recorded, it means that a new transfer action has occurred. Just use this to trigger it.&lt;br /&gt;&lt;br /&gt;The ```/sapi/v1/asset/transfer``` interface can request up to 100 pieces of data at a time. The detection will not cause problems for low-frequency transfers, unless the account has more than 100 transfer operations between the end of one detection and the start of the next detection. At this time, some new operation records may be missed, which is sufficient for general demand scenarios (generally, there will be no strategy to transfer funds crazily...).&lt;br /&gt;&lt;br /&gt;Of course, there are many details in the actual design. For example, checking the documentation, we found that there are many transfer directions, so we need to monitor each transfer direction. The code is defined ```var dicType = {...}``` to manage all transfer directions.&lt;br /&gt;&lt;br /&gt;In order to display the content better, we use a status bar table to output the last 5 transfer information in the strategy interface, so we constructed an object named ```monitor``` to record the data. Of course, you cannot record transfer information unlimitedly, so we only maintain 100 records for each transfer direction. If the number exceeds 100, we will delete premature records.&lt;br /&gt;&lt;br /&gt;### Code Example&lt;br /&gt;```&lt;br /&gt;function getRecentTransferHistory(TransType, typeDesc) {&lt;br /&gt;	// GET /sapi/v1/asset/transfer type, size : 100&lt;br /&gt;    &lt;br /&gt;    var rows = null &lt;br /&gt;    var ret = exchange.IO(&amp;quot;api&amp;quot;, &amp;quot;GET&amp;quot;, &amp;quot;/sapi/v1/asset/transfer&amp;quot;, `type=${TransType}&amp;amp;size=100`)&lt;br /&gt;    Log(&amp;quot;/sapi/v1/asset/transfer&amp;quot; + `type=${TransType}&amp;amp;size=100`)&lt;br /&gt;    if (ret &amp;amp;&amp;amp; typeof(ret.rows) != &amp;quot;undefined&amp;quot; &amp;amp;&amp;amp; Array.isArray(ret.rows)) {&lt;br /&gt;        rows = ret.rows&lt;br /&gt;    } else if (ret &amp;amp;&amp;amp; typeof(ret.total) != &amp;quot;undefined&amp;quot; &amp;amp;&amp;amp; ret.total == 0) {&lt;br /&gt;        rows = []&lt;br /&gt;    } else {&lt;br /&gt;    	Log(TransType, typeDesc, &amp;quot;inquiry failure&amp;quot;, ret)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    return rows&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var monitor = {}&lt;br /&gt;function monitorTransfers() {&lt;br /&gt;    var dicType = {&lt;br /&gt;        &amp;quot;MAIN_UMFUTURE&amp;quot;: &amp;quot;Spot wallet --&amp;gt; U-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;MAIN_CMFUTURE&amp;quot;: &amp;quot;Spot wallet --&amp;gt; Currency-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;UMFUTURE_MAIN&amp;quot;: &amp;quot;U-based contract wallet --&amp;gt; Spot wallet&amp;quot;,&lt;br /&gt;        &amp;quot;UMFUTURE_MARGIN&amp;quot;: &amp;quot;U-based contract wallet --&amp;gt; Leveraged full position wallet&amp;quot;,&lt;br /&gt;        &amp;quot;CMFUTURE_MAIN&amp;quot;: &amp;quot;Currency-based contract wallet --&amp;gt; Spot wallet&amp;quot;,&lt;br /&gt;        &amp;quot;MARGIN_UMFUTURE&amp;quot;: &amp;quot;Leveraged full position wallet --&amp;gt; U-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;MARGIN_CMFUTURE&amp;quot;: &amp;quot;Leveraged full position wallet --&amp;gt; Currency-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;CMFUTURE_MARGIN&amp;quot;: &amp;quot;Currency-based contract wallet --&amp;gt; Leveraged full position wallet&amp;quot;,&lt;br /&gt;        &amp;quot;FUNDING_UMFUTURE&amp;quot;: &amp;quot;Funds wallet --&amp;gt; U-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;UMFUTURE_FUNDING&amp;quot;: &amp;quot;U-based contract wallet --&amp;gt; Funds wallet&amp;quot;,&lt;br /&gt;        &amp;quot;FUNDING_CMFUTURE&amp;quot;: &amp;quot;Funds wallet --&amp;gt; Currency-based contract wallet&amp;quot;,&lt;br /&gt;        &amp;quot;CMFUTURE_FUNDING&amp;quot;: &amp;quot;Currency-based contract wallet --&amp;gt; Funds wallet&amp;quot;,&lt;br /&gt;        &amp;quot;UMFUTURE_OPTION&amp;quot;: &amp;quot;U-based contract wallet --&amp;gt; Options wallet&amp;quot;,&lt;br /&gt;        &amp;quot;OPTION_UMFUTURE&amp;quot;: &amp;quot;Options wallet --&amp;gt; U-based contract wallet&amp;quot;,&lt;br /&gt;        // integrated account&lt;br /&gt;        &amp;quot;MAIN_PORTFOLIO_MARGIN&amp;quot;: &amp;quot;Spot wallet --&amp;gt; Unified accounts wallet&amp;quot;,&lt;br /&gt;        &amp;quot;PORTFOLIO_MARGIN_MAIN&amp;quot;: &amp;quot;Unified accounts wallet --&amp;gt; Spot wallet&amp;quot;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    Log(&amp;quot;start testing&amp;quot;)&lt;br /&gt;    _.each(dicType, function(v, k) {&lt;br /&gt;        var rows = getRecentTransferHistory(k, v)&lt;br /&gt;        var maxTS = 0&lt;br /&gt;        _.each(rows, function(row) {&lt;br /&gt;            if (typeof(monitor[k]) == &amp;quot;undefined&amp;quot;) {&lt;br /&gt;            	monitor[k] = {&amp;quot;transType&amp;quot;: k, &amp;quot;typeDesc&amp;quot;: v, &amp;quot;recentRecords&amp;quot;: [], &amp;quot;lastTS&amp;quot;: 0}            	&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (row[&amp;quot;timestamp&amp;quot;] &amp;gt; monitor[k][&amp;quot;lastTS&amp;quot;]) {&lt;br /&gt;                monitor[k][&amp;quot;recentRecords&amp;quot;].push(row)&lt;br /&gt;                &lt;br /&gt;                if (monitor[k][&amp;quot;lastTS&amp;quot;] != 0) {&lt;br /&gt;                	Log(&amp;quot;New transfer records detected&amp;quot;, k, v, row, &amp;quot;#FF0000&amp;quot;)&lt;br /&gt;                }                &lt;br /&gt;            }&lt;br /&gt;            maxTS = Math.max(maxTS, row[&amp;quot;timestamp&amp;quot;])     &lt;br /&gt;        })&lt;br /&gt;        if (rows &amp;amp;&amp;amp; rows.length == 0) {&lt;br /&gt;            return &lt;br /&gt;        }&lt;br /&gt;        monitor[k][&amp;quot;lastTS&amp;quot;] = maxTS&lt;br /&gt;&lt;br /&gt;        var sortedArrayAscending = monitor[k][&amp;quot;recentRecords&amp;quot;].slice().sort((a, b) =&amp;gt; a.timestamp - b.timestamp)&lt;br /&gt;        monitor[k][&amp;quot;recentRecords&amp;quot;] = sortedArrayAscending&lt;br /&gt;&lt;br /&gt;        if (monitor[k][&amp;quot;recentRecords&amp;quot;].length &amp;gt; 100) {&lt;br /&gt;        	monitor[k][&amp;quot;recentRecords&amp;quot;].shift()&lt;br /&gt;        }&lt;br /&gt;        Sleep(1000)&lt;br /&gt;    })&lt;br /&gt;    Log(&amp;quot;commencement and termination&amp;quot;)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function main() {&lt;br /&gt;    LogReset()&lt;br /&gt;    while (true) {&lt;br /&gt;        monitorTransfers()&lt;br /&gt;&lt;br /&gt;        var tbls = []&lt;br /&gt;        _.each(monitor, function(v, k) {&lt;br /&gt;        	var tbl = {&lt;br /&gt;        		&amp;quot;type&amp;quot;: &amp;quot;table&amp;quot;, &lt;br /&gt;        		&amp;quot;title&amp;quot;: v[&amp;quot;typeDesc&amp;quot;], &lt;br /&gt;        		&amp;quot;cols&amp;quot;: [&amp;quot;asset&amp;quot;, &amp;quot;amount&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;tranId&amp;quot;, &amp;quot;time&amp;quot;], &lt;br /&gt;        		&amp;quot;rows&amp;quot;: []&lt;br /&gt;        	}&lt;br /&gt;&lt;br /&gt;            var arr = v[&amp;quot;recentRecords&amp;quot;].slice().sort((a, b) =&amp;gt; b.timestamp - a.timestamp)&lt;br /&gt;            for (var i = 0; i &amp;lt; arr.length; i++) {&lt;br /&gt;            	if (i &amp;lt; 5) {&lt;br /&gt;            		tbl[&amp;quot;rows&amp;quot;].push([arr[i][&amp;quot;asset&amp;quot;], arr[i][&amp;quot;amount&amp;quot;], arr[i][&amp;quot;status&amp;quot;], arr[i][&amp;quot;tranId&amp;quot;], _D(arr[i][&amp;quot;timestamp&amp;quot;])])&lt;br /&gt;            	}            	&lt;br /&gt;            }&lt;br /&gt;            tbls.push(tbl)&lt;br /&gt;        })        &lt;br /&gt;&lt;br /&gt;    	LogStatus(_D(), &amp;quot;\n&amp;quot;, &amp;quot;`&amp;quot; + JSON.stringify(tbls) + &amp;quot;`&amp;quot;)&lt;br /&gt;    	Sleep(1000 * 30)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;### Code Overview:&lt;br /&gt;The provided JavaScript code includes several functions that build a system together for monitoring recent asset transfers. Let&amp;#39;s analysis the main components:&lt;br /&gt;&lt;br /&gt;- getRecentTransferHistory function:&lt;br /&gt;&lt;br /&gt;      Purpose: Obtain the recent asset transfer history from the exchange API according to the specified parameters.&lt;br /&gt;      Parameters: TransType (transfer type), typeDesc (type description).&lt;br /&gt;      API endpoint: /sapi/v1/asset/transfer.&lt;br /&gt;&lt;br /&gt;- monitorTransfers function:&lt;br /&gt;&lt;br /&gt;      Purpose: Iterate over predefined transfer types, retrieve recent transfer history, and record any new transfers.&lt;br /&gt;      Use a dictionary (dicType) to map transfer types to human-readable descriptions.&lt;br /&gt;      Update the monitor object to track the latest transfers of each type.&lt;br /&gt;&lt;br /&gt;- main function:&lt;br /&gt;&lt;br /&gt;      Purpose: Run an infinite loop that monitors transfers continuously and displays the latest data.&lt;br /&gt;      Use the monitorTransfers function regularly.&lt;br /&gt;      Generate a table for each transfer type, including columns such as asset, amount, status, transaction ID, and timestamp.&lt;br /&gt;&lt;br /&gt;### Key Features:&lt;br /&gt;- Dynamic transfer type mapping:&lt;br /&gt;&lt;br /&gt;      The code uses a dictionary (dicType) to map transfer types to descriptive names, providing a clear explanation of the nature of each transfer.&lt;br /&gt;&lt;br /&gt;- Real-time monitoring:&lt;br /&gt;&lt;br /&gt;      The system checks for new transfers continuously, updates the monitor object and records any detected changes.&lt;br /&gt;&lt;br /&gt;- Data presentation:&lt;br /&gt;&lt;br /&gt;      Use tables to present each type of transfer data, including relevant details such as assets, amounts, status, transaction IDs, and timestamps.&lt;br /&gt;&lt;br /&gt;- Recent transfer history management:&lt;br /&gt;&lt;br /&gt;      Maintain a scrolling list of recent transfer records for each type, ensuring a concise and timely display.&lt;br /&gt;&lt;br /&gt;### Bot Test&lt;br /&gt;A transfer was made manually and the program detected the transfer operation.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149241
" title="https://stocksharp.com/file/149241
"&gt;https://stocksharp.com/file/149241
&lt;/a&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149242
" title="https://stocksharp.com/file/149242
"&gt;https://stocksharp.com/file/149242
&lt;/a&gt;&lt;br /&gt;### END:&lt;br /&gt;The provided JavaScript code provides a powerful solution for monitoring recent asset transfers on cryptocurrency exchanges. Its dynamic and real-time nature makes it a valuable tool for traders and developers seeking to understand asset movements between different wallets. This code can be modified and customized to specific needs, providing a solid foundation for those looking to enhance their cryptocurrency trading strategies or develop additional monitoring capabilities.&lt;br /&gt;&lt;br /&gt;This article throws some light on the topic and provides a design idea. May your cryptocurrency career be both informative and successful!&lt;br /&gt;&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y68xWe88Dm0XrWb6PcgGfeqkaV2Afp5k_ddZHA0TqJ2wDZelmTDXLQD8-7-9viCEjaeZOJ3PatyJj8e2AnCAAd0Bf3LRpUI07zRKoi5DGb0pp9GRDbmVC-kSLfzEf8nY7NcU0piK5sOjrZwvlxExJcFk" title="https://blog.mathquant.com/2023/12/25/fmz-quant-an-analysis-of-common-requirements-design-examples-in-the-cryptocurrency-market-ii.html"&gt;https://blog.mathquant.c...ocurrency-market-ii.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25566/</id>
    <title type="text">An Analysis of Common Requirements Design Examples in the Cryptocurrency Market (I)</title>
    <published>2024-03-15T01:17:45Z</published>
    <updated>2024-03-15T01:17:45Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#code" />
    <category term="#market" />
    <category term="#analysis" />
    <category term="#fmz" />
    <category term="#contract" />
    <category term="#OKX" />
    <category term="#exchange" />
    <category term="#python" />
    <content type="html">In the cryptocurrency asset trading space, obtaining and analyzing market data, querying rates, and monitoring account asset movements are all critical operations. Below are code examples of implementations for some common requirements.&lt;br /&gt;&lt;br /&gt;## 1. How do I write the code about getting the currency with the highest increase in 4 hours on Binance Spot?&lt;br /&gt;When writing a quantitative trading strategy program on FMZ platform, the first thing you need to do when you encounter a requirement is to analyze it. So based on the requirements, we analyzed the following contents:&lt;br /&gt;&lt;br /&gt;- Which programming language to use?&lt;br /&gt;The plan is to use Javascript to implement it.&lt;br /&gt;- Requires spot real-time quotes in all currencies&lt;br /&gt;The first thing we did when we saw the requirement was to look up Binance API document to find out if there was any aggregated quotes (it&amp;#39;s best to have aggregated quotes, it&amp;#39;s a lot of work to look up one by one).&lt;br /&gt;We found the aggregated quotes interface: ```GET &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACfL3Aq1BOw1cGTTrQiiafGkYUlRjtfZ1xZr8VTZyhnoOl1nHbP0GW8jLSblUKT3HM" title="https://api.binance.com/api/v3/ticker/price`"&gt;https://api.binance.com/api/v3/ticker/price`&lt;/a&gt;``.&lt;br /&gt;On FMZ platform, use the ```HttpQuery``` function to access the exchange ticker interface (public interface that does not require a signature).&lt;br /&gt;- Need to count data for a rolling window period of 4 hours&lt;br /&gt;Conceptualize how to design the structure of the statistical program.&lt;br /&gt;- Calculate price fluctuations and sort them&lt;br /&gt;Thinking about the price fluctuations algorithm, is it: ```price fluctuations (%) = (current price - initial price) / initial price * 100``` in &amp;quot;%&amp;quot;.&lt;br /&gt;&lt;br /&gt;After figuring out the problem, as well as defining the program. We then got down to the business of designing the program.&lt;br /&gt;&lt;br /&gt;### Code Design&lt;br /&gt;```&lt;br /&gt;var dictSymbolsPrice = {}&lt;br /&gt;&lt;br /&gt;function main() {&lt;br /&gt;    while (true) {&lt;br /&gt;        // GET &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACfL3Aq1BOw1cGTTrQiiafGkYUlRjtfZ1xZr8VTZyhnoHb4xqNwUICI8mGtl4SlDtU" title="https://api.binance.com/api/v3/ticker/price
"&gt;https://api.binance.com/api/v3/ticker/price
&lt;/a&gt;&lt;br /&gt;        try {&lt;br /&gt;            var arr = JSON.parse(HttpQuery(&amp;quot;https://api.binance.com/api/v3/ticker/price&amp;quot;))&lt;br /&gt;            if (!Array.isArray(arr)) {&lt;br /&gt;                Sleep(5000)&lt;br /&gt;                continue &lt;br /&gt;            }&lt;br /&gt;            &lt;br /&gt;            var ts = new Date().getTime()&lt;br /&gt;            for (var i = 0; i &amp;lt; arr.length; i++) {&lt;br /&gt;                var symbolPriceInfo = arr[i]&lt;br /&gt;                var symbol = symbolPriceInfo.symbol&lt;br /&gt;                var price = symbolPriceInfo.price&lt;br /&gt;&lt;br /&gt;                if (typeof(dictSymbolsPrice[symbol]) == &amp;quot;undefined&amp;quot;) {&lt;br /&gt;                    dictSymbolsPrice[symbol] = {name: symbol, data: []}&lt;br /&gt;                }&lt;br /&gt;                dictSymbolsPrice[symbol].data.push({ts: ts, price: price})&lt;br /&gt;            }&lt;br /&gt;        } catch(e) {&lt;br /&gt;            Log(&amp;quot;e.name:&amp;quot;, e.name, &amp;quot;e.stack:&amp;quot;, e.stack, &amp;quot;e.message:&amp;quot;, e.message)&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        // Calculate price fluctuations&lt;br /&gt;        var tbl = {&lt;br /&gt;            type : &amp;quot;table&amp;quot;,&lt;br /&gt;            title : &amp;quot;Price fluctuations&amp;quot;,&lt;br /&gt;            cols : [&amp;quot;trading pair&amp;quot;, &amp;quot;current price&amp;quot;, &amp;quot;price 4 hours ago&amp;quot;, &amp;quot;price fluctuations&amp;quot;, &amp;quot;data length&amp;quot;, &amp;quot;earliest data time&amp;quot;, &amp;quot;latest data time&amp;quot;],&lt;br /&gt;            rows : []&lt;br /&gt;        }&lt;br /&gt;        for (var symbol in dictSymbolsPrice) {&lt;br /&gt;            var data = dictSymbolsPrice[symbol].data&lt;br /&gt;            if (data[data.length - 1].ts - data[0].ts &amp;gt; 1000 * 60 * 60 * 4) {&lt;br /&gt;                dictSymbolsPrice[symbol].data.shift()&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            data = dictSymbolsPrice[symbol].data&lt;br /&gt;            dictSymbolsPrice[symbol].percentageChange = (data[data.length - 1].price - data[0].price) / data[0].price * 100&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        var entries = Object.entries(dictSymbolsPrice)&lt;br /&gt;        entries.sort((a, b) =&amp;gt; b[1].percentageChange - a[1].percentageChange)&lt;br /&gt;&lt;br /&gt;        for (var i = 0; i &amp;lt; entries.length; i++) {&lt;br /&gt;            if (i &amp;gt; 9) {&lt;br /&gt;                break&lt;br /&gt;            }   &lt;br /&gt;            var name = entries[i][1].name&lt;br /&gt;            var data = entries[i][1].data&lt;br /&gt;            var percentageChange = entries[i][1].percentageChange&lt;br /&gt;            var currPrice = data[data.length - 1].price&lt;br /&gt;            var currTs = _D(data[data.length - 1].ts)&lt;br /&gt;            var prePrice = data[0].price&lt;br /&gt;            var preTs = _D(data[0].ts)&lt;br /&gt;            var dataLen = data.length&lt;br /&gt;&lt;br /&gt;            tbl.rows.push([name, currPrice, prePrice, percentageChange + &amp;quot;%&amp;quot;, dataLen, preTs, currTs])&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        LogStatus(_D(), &amp;quot;\n&amp;quot;, &amp;quot;`&amp;quot; + JSON.stringify(tbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;        Sleep(5000)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;### Code Analysis&lt;br /&gt;- 1. Data structure&lt;br /&gt;```var dictSymbolsPrice = {}```: An empty object to store price information for each trading pair. The key is the symbol of the trading pair, and the value is an object containing the name of the trading pair, an array of price data, and information about the price fluctuations.&lt;br /&gt;- 2. Main function main()&lt;br /&gt;  2.1. Infinite loop&lt;br /&gt;```&lt;br /&gt;while (true) {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;The program continuously monitors the Binance API trading pair prices through an infinite loop.&lt;br /&gt;&lt;br /&gt;  2.2. Get price information&lt;br /&gt;```&lt;br /&gt;var arr = JSON.parse(HttpQuery(&amp;quot;https://api.binance.com/api/v3/ticker/price&amp;quot;))&lt;br /&gt;```&lt;br /&gt;Get the current price information of the trading pair via Binance API. If the return is not an array, wait for 5 seconds and retry.&lt;br /&gt;&lt;br /&gt;  2.3. Update price data&lt;br /&gt;```&lt;br /&gt;for (var i = 0; i &amp;lt; arr.length; i++) {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Iterate through the array of obtained price information and update the data in dictSymbolsPrice. For each trading pair, add the current timestamp and price to the corresponding data array.&lt;br /&gt;&lt;br /&gt;  2.4. Exception processing&lt;br /&gt;```&lt;br /&gt;} catch(e) {&lt;br /&gt;    Log(&amp;quot;e.name:&amp;quot;, e.name, &amp;quot;e.stack:&amp;quot;, e.stack, &amp;quot;e.message:&amp;quot;, e.message)&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Catch exceptions and log the exception information to ensure that the program can continue to execute.&lt;br /&gt;&lt;br /&gt;  2.5. Calculate the price fluctuations&lt;br /&gt;```&lt;br /&gt;for (var symbol in dictSymbolsPrice) {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Iterate through dictSymbolsPrice, calculate the price fluctuations of each trading pair, and remove the earliest data if it is longer than 4 hours.&lt;br /&gt;&lt;br /&gt;  2.6. Sort and generate tables&lt;br /&gt;```&lt;br /&gt;var entries = Object.entries(dictSymbolsPrice)&lt;br /&gt;entries.sort((a, b) =&amp;gt; b[1].percentageChange - a[1].percentageChange)&lt;br /&gt;&lt;br /&gt;for (var i = 0; i &amp;lt; entries.length; i++) {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Sort the trading pairs in descending order of their price fluctuations and generate a table containing information about the trading pairs.&lt;br /&gt;&lt;br /&gt;  2.7. Log output and delay&lt;br /&gt;```&lt;br /&gt;LogStatus(_D(), &amp;quot;\n&amp;quot;, &amp;quot;`&amp;quot; + JSON.stringify(tbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;Sleep(5000)&lt;br /&gt;```&lt;br /&gt;Output the table and the current time in the form of a log and wait for 5 seconds to continue the next round of the loop.&lt;br /&gt;&lt;br /&gt;The program obtains the real-time price information of the trading pair through Binance API, then calculates the price fluctuations, and outputs it to the log in the form of a table. The program is executed in a continuous loop to realize the function of real-time monitoring of the prices of trading pairs. Note that the program includes exception processing to ensure that the execution is not interrupted by exceptions when obtaining price information.&lt;br /&gt;&lt;br /&gt;### Live Trading Running Test&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149238
" title="https://stocksharp.com/file/149238
"&gt;https://stocksharp.com/file/149238
&lt;/a&gt;&lt;br /&gt;Since data can only be collected bit by bit at the beginning, it is not possible to calculate the price fluctuations on a rolling basis without collecting enough data for a 4-hour window. Therefore, the initial price is used as the base for calculation, and after collecting enough data for 4 hours, the oldest data will be eliminated in order to maintain the 4-hour window for calculating the price fluctuations.&lt;br /&gt;&lt;br /&gt;## 2. Check the full variety of funding rates for Binance U-denominated contracts&lt;br /&gt;Checking the funding rate is similar to the above code, first of all, we need to check the Binance API documentation to find the funding rate related interface. Binance has several interfaces that allow us to query the rate of funds, here we take the interface of the U-denominated contract as an example:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;GET &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACnpKUNUrsvTUe50LbpAqE3J_RruimpjMBn19u4HQFXey7Q6ctiI4d8we1_Qz5p5HY" title="https://fapi.binance.com/fapi/v1/premiumIndex
"&gt;https://fapi.binance.com/fapi/v1/premiumIndex
&lt;/a&gt;&lt;br /&gt;```&lt;br /&gt;### Code Implementation&lt;br /&gt;Since there are so many contracts, we&amp;#39;re exporting the top 10 largest funding rates here.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;function main() {&lt;br /&gt;    while (true) {&lt;br /&gt;        // GET &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACnpKUNUrsvTUe50LbpAqE3J_RruimpjMBn19u4HQFXey7Q6ctiI4d8we1_Qz5p5HY" title="https://fapi.binance.com/fapi/v1/premiumIndex
"&gt;https://fapi.binance.com/fapi/v1/premiumIndex
&lt;/a&gt;&lt;br /&gt;        try {&lt;br /&gt;            var arr = JSON.parse(HttpQuery(&amp;quot;https://fapi.binance.com/fapi/v1/premiumIndex&amp;quot;))&lt;br /&gt;            if (!Array.isArray(arr)) {&lt;br /&gt;                Sleep(5000)&lt;br /&gt;                continue &lt;br /&gt;            }&lt;br /&gt;            &lt;br /&gt;            arr.sort((a, b) =&amp;gt; parseFloat(b.lastFundingRate) - parseFloat(a.lastFundingRate))&lt;br /&gt;            var tbl = {&lt;br /&gt;                type: &amp;quot;table&amp;quot;,&lt;br /&gt;                title: &amp;quot;Top 10 funding rates for U-denominated contracts&amp;quot;,&lt;br /&gt;                cols: [&amp;quot;contracts&amp;quot;, &amp;quot;funding rate&amp;quot;, &amp;quot;marked price&amp;quot;, &amp;quot;index price&amp;quot;, &amp;quot;current rate time&amp;quot;, &amp;quot;next rate time&amp;quot;],&lt;br /&gt;                rows: []&lt;br /&gt;            }&lt;br /&gt;            for (var i = 0; i &amp;lt; 9; i++) {&lt;br /&gt;                var obj = arr[i]&lt;br /&gt;                tbl.rows.push([obj.symbol, obj.lastFundingRate, obj.markPrice, obj.indexPrice, _D(obj.time), _D(obj.nextFundingTime)])&lt;br /&gt;            }&lt;br /&gt;            LogStatus(_D(), &amp;quot;\n&amp;quot;, &amp;quot;`&amp;quot; + JSON.stringify(tbl) + &amp;quot;`&amp;quot;)&lt;br /&gt;        } catch(e) {&lt;br /&gt;            Log(&amp;quot;e.name:&amp;quot;, e.name, &amp;quot;e.stack:&amp;quot;, e.stack, &amp;quot;e.message:&amp;quot;, e.message)&lt;br /&gt;        }&lt;br /&gt;        Sleep(1000 * 10)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;The returned data structure is as follows, and check the Binance documentation, it shows that lastFundingRate is the funding rate we want.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;{&lt;br /&gt;    &amp;quot;symbol&amp;quot;:&amp;quot;STMXUSDT&amp;quot;,&lt;br /&gt;    &amp;quot;markPrice&amp;quot;:&amp;quot;0.00883606&amp;quot;,&lt;br /&gt;    &amp;quot;indexPrice&amp;quot;:&amp;quot;0.00883074&amp;quot;,&lt;br /&gt;    &amp;quot;estimatedSettlePrice&amp;quot;:&amp;quot;0.00876933&amp;quot;,&lt;br /&gt;    &amp;quot;lastFundingRate&amp;quot;:&amp;quot;0.00026573&amp;quot;,&lt;br /&gt;    &amp;quot;interestRate&amp;quot;:&amp;quot;0.00005000&amp;quot;,&lt;br /&gt;    &amp;quot;nextFundingTime&amp;quot;:1702828800000,&lt;br /&gt;    &amp;quot;time&amp;quot;:1702816229000&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;Live trading running test:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149239
" title="https://stocksharp.com/file/149239
"&gt;https://stocksharp.com/file/149239
&lt;/a&gt;&lt;br /&gt;### Getting OKX exchange contract funding rates of Python version&lt;br /&gt;A user has asked for a Python version of the example, and it&amp;#39;s for the OKX exchange. Here is an example:&lt;br /&gt;&lt;br /&gt;The data returned by the interface ```https://www.okx.com/priapi/v5/public/funding-rate-all?currencyType=1```:&lt;br /&gt;```&lt;br /&gt;{&lt;br /&gt;    &amp;quot;code&amp;quot;:&amp;quot;0&amp;quot;,&lt;br /&gt;    &amp;quot;data&amp;quot;:[&lt;br /&gt;        {&lt;br /&gt;            &amp;quot;fundingTime&amp;quot;:1702828800000,&lt;br /&gt;            &amp;quot;fundingList&amp;quot;:[&lt;br /&gt;                {&lt;br /&gt;                    &amp;quot;instId&amp;quot;:&amp;quot;BTC-USDT-SWAP&amp;quot;,&lt;br /&gt;                    &amp;quot;nextFundingRate&amp;quot;:&amp;quot;0.0001102188733642&amp;quot;,&lt;br /&gt;                    &amp;quot;minFundingRate&amp;quot;:&amp;quot;-0.00375&amp;quot;,&lt;br /&gt;                    &amp;quot;fundingRate&amp;quot;:&amp;quot;0.0000821861465884&amp;quot;,&lt;br /&gt;                    &amp;quot;maxFundingRate&amp;quot;:&amp;quot;0.00375&amp;quot;&lt;br /&gt;                } ...&lt;br /&gt;```&lt;br /&gt;Specific code:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;import requests&lt;br /&gt;import json&lt;br /&gt;from time import sleep&lt;br /&gt;from datetime import datetime&lt;br /&gt;&lt;br /&gt;def main():&lt;br /&gt;    while True:&lt;br /&gt;        # &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAX6jgKcm1O1gelyLxYvVdIuZk7xhWOdSLJzmIY9U2euHYh7hg3o0lfh7KAVNUc3PqsohDC5Uzvxe1b7hR5A0sEtJL8-7Q-gWMVzcGb83Bdeg" title="https://www.okx.com/priapi/v5/public/funding-rate-all?currencyType=1
"&gt;https://www.okx.com/pria...rate-all?currencyType=1
&lt;/a&gt;&lt;br /&gt;        try:&lt;br /&gt;            response = requests.get(&amp;quot;https://www.okx.com/priapi/v5/public/funding-rate-all?currencyType=1&amp;quot;)&lt;br /&gt;            arr = response.json()[&amp;quot;data&amp;quot;][0][&amp;quot;fundingList&amp;quot;]&lt;br /&gt;            Log(arr) &lt;br /&gt;            if not isinstance(arr, list):&lt;br /&gt;                sleep(5)&lt;br /&gt;                continue&lt;br /&gt;&lt;br /&gt;            arr.sort(key=lambda x: float(x[&amp;quot;fundingRate&amp;quot;]), reverse=True)&lt;br /&gt;&lt;br /&gt;            tbl = {&lt;br /&gt;                &amp;quot;type&amp;quot;: &amp;quot;table&amp;quot;,&lt;br /&gt;                &amp;quot;title&amp;quot;: &amp;quot;Top 10 funding rates for U-denominated contracts&amp;quot;,&lt;br /&gt;                &amp;quot;cols&amp;quot;: [&amp;quot;contracts&amp;quot;, &amp;quot;next rate&amp;quot;, &amp;quot;minimum&amp;quot;, &amp;quot;current&amp;quot;, &amp;quot;maximum&amp;quot;],&lt;br /&gt;                &amp;quot;rows&amp;quot;: []&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            for i in range(min(9, len(arr))):&lt;br /&gt;                obj = arr[i]&lt;br /&gt;                row = [&lt;br /&gt;                    obj[&amp;quot;instId&amp;quot;],&lt;br /&gt;                    obj[&amp;quot;nextFundingRate&amp;quot;],&lt;br /&gt;                    obj[&amp;quot;minFundingRate&amp;quot;],&lt;br /&gt;                    obj[&amp;quot;fundingRate&amp;quot;],&lt;br /&gt;                    obj[&amp;quot;maxFundingRate&amp;quot;]&lt;br /&gt;                ]&lt;br /&gt;                tbl[&amp;quot;rows&amp;quot;].append(row)&lt;br /&gt;            &lt;br /&gt;            LogStatus(_D(), &amp;quot;\n&amp;quot;, &amp;#39;`&amp;#39; + json.dumps(tbl) + &amp;#39;`&amp;#39;)&lt;br /&gt;&lt;br /&gt;        except Exception as e:&lt;br /&gt;            Log(f&amp;quot;Error: {str(e)}&amp;quot;)&lt;br /&gt;&lt;br /&gt;        sleep(10)&lt;br /&gt;```&lt;br /&gt;Live trading running test:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149240
" title="https://stocksharp.com/file/149240
"&gt;https://stocksharp.com/file/149240
&lt;/a&gt;&lt;br /&gt;### END&lt;br /&gt;These examples provide basic design ideas and calling methods, the actual project may need to make appropriate changes and extensions based on the specific needs. Hopefully, these codes can help you better meet the various needs in cryptocurrency digital asset trading.&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOQlbPNxIPafGj0KHUDS3Y68rVVLKlYDznwDv5ubvlY9vnNCSvXHE-hz8hgv4J0qmCzJz2XKYle71jKhvIjvYbkhtI3fwXGmA30gp8lPoFt3zpn8KRj_HYaEVGjDZeJ7k25G0KPS4RG1BFMJcIjIOdBoVAI5Af-REHEzXVwq5g_is" title="https://blog.mathquant.com/2023/12/19/fmz-quant-an-analysis-of-common-requirements-design-examples-in-the-cryptocurrency-market-i.html"&gt;https://blog.mathquant.c...tocurrency-market-i.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25563/</id>
    <title type="text">The Crucial Role of Efficient Quantitative Data Exploration Tools in Boosting Trading Success</title>
    <published>2024-03-14T09:21:47Z</published>
    <updated>2024-03-14T09:21:47Z</updated>
    <author>
      <name>FMZ Quant</name>
      <uri>https://stocksharp.com/users/185552/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="#trading" />
    <category term="#cryptocurrency" />
    <category term="#strategy" />
    <category term="#code" />
    <category term="#data" />
    <category term="#market" />
    <category term="#analysis" />
    <category term="#fmz" />
    <category term="#algorithmic" />
    <category term="#platform" />
    <content type="html">In today&amp;#39;s fiercely competitive financial market, quantitative trading, as a trading strategy based on data analysis and algorithmic models, is becoming an increasingly favored choice for investors and traders. In the field of quantitative trading, the value of data is becoming increasingly prominent. Therefore, an efficient and reliable quantitative data exploration tool has become an indispensable key to achieving successful transactions.&lt;br /&gt;&lt;br /&gt;In this era where data-driven decision-making is increasingly valued, the FMZ Quant data exploration module has emerged. As one of the essential tools in the field of quantitative trading, it is not only an ordinary data analysis software, but also a revolutionary innovation that provides investors with unique data analysis and mining functions, helping them seize opportunities and reduce risks in complex and ever-changing financial markets.&lt;br /&gt;&lt;br /&gt;FMZ Quant, as a professional quantitative trading platform, is supported by numerous quantitative trading tools. At present, the &amp;quot;Data Exploration&amp;quot; module of the FMZ Quant Trading Platform has integrated the services of the datadata platform, giving users more advantages in multidimensional data analysis, mining visual data, exploring trading strategies, and other aspects. FMZ&amp;#39;s self-developed datadata platform is a quantitative financial data platform. Using SQL queries to analyze massive amounts of data and configuring them through visual interfaces, generating various charts suitable for data analysis and sharing them with the team, allowing us to easily grasp market trends and seize investment opportunities!&lt;br /&gt;&lt;br /&gt;FMZ Quant Data Exploration Module&lt;br /&gt;First of all, let&amp;#39;s familiarize with the FMZ Quant Data Exploration module, which is used just like on datadata. For each FMZ platform user, we don&amp;#39;t need to register for the datadata platform again, and we can use all the features of the datadata platform directly.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149179
" title="https://stocksharp.com/file/149179
"&gt;https://stocksharp.com/file/149179
&lt;/a&gt;&lt;br /&gt;Data areas&lt;br /&gt;The list on the left side shows the data content that has been supported on-line, currently supporting K-line data (OHLC) and Tick data of each exchange (platform). More types and dimensions of data will be supported in the future.&lt;br /&gt;These data are updated continuously in real time, allowing us to always grasp the market dynamics.&lt;br /&gt;For example, if we select OHLC and then select market-&amp;gt;bitfinex_m1, we can see the field names in this table object after clicking Expand.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149180
" title="https://stocksharp.com/file/149180
"&gt;https://stocksharp.com/file/149180
&lt;/a&gt;&lt;br /&gt;Click on the table chart to preview some of the data.&lt;br /&gt;&lt;br /&gt;The platform also supports uploading your own data by clicking the &amp;quot;Upload Data&amp;quot; button at the bottom of the list.&lt;br /&gt;&lt;br /&gt;Uploading CSV files from your device to the server.&lt;br /&gt;The file size should not exceed 10 MB, with a maximum of 10,000 rows and 128 columns.&lt;br /&gt;&lt;br /&gt;SQL statement edit area&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149181
" title="https://stocksharp.com/file/149181
"&gt;https://stocksharp.com/file/149181
&lt;/a&gt;&lt;br /&gt;Here is the edit box for writing a specific query statement, we will show two interesting examples later, let&amp;#39;s understand the other features first.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149182
" title="https://stocksharp.com/file/149182
"&gt;https://stocksharp.com/file/149182
&lt;/a&gt;&lt;br /&gt;There are two control buttons here, the first one can be used to format the SQL statement easily. The second button is used to insert variables used in the SQL statement, similar to adding a parameter to the SQL query that can be modified in real time (without having to hard-code some of the query conditions into the SQL statement). For example:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149183
" title="https://stocksharp.com/file/149183
"&gt;https://stocksharp.com/file/149183
&lt;/a&gt;&lt;br /&gt;Input &amp;#39;1inch_usd&amp;#39; into the parameter test and click the &amp;quot;Execute&amp;quot; button on the right side, then you can query all the data of the variety 1inch_usd. The queried data can also be exported and downloaded locally:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149184
" title="https://stocksharp.com/file/149184
"&gt;https://stocksharp.com/file/149184
&lt;/a&gt;&lt;br /&gt;It supports JSON, CSV format.&lt;br /&gt;&lt;br /&gt;If we want to save the SQL query, we can click the &amp;quot;Save&amp;quot; button in the upper right corner to record the SQL query in the resource list of the current FMZ account&amp;#39;s &amp;quot;Data Exploration&amp;quot; (the resource list button is on the left side of the save button) for future use.&lt;br /&gt;&lt;br /&gt;At present, the interface we see is simple and the functions are simple, but in practical use, we will experience the powerful use of this tool. Next, let&amp;#39;s take a look at two more complex examples.&lt;br /&gt;&lt;br /&gt;Volatility ranking&lt;br /&gt;```&lt;br /&gt;SELECT &lt;br /&gt;    UPPER(REPLACE(symbol, &amp;#39;_usdt.swap&amp;#39;, &amp;#39;&amp;#39;)) as symbol,&lt;br /&gt;    ((MAX(high) - MIN(low)) / AVG((high + low) / 2)) AS volatility_percentage&lt;br /&gt;FROM &lt;br /&gt;    market.futures_binance_d1&lt;br /&gt;WHERE &lt;br /&gt;    timestamp &amp;gt;= CURRENT_DATE - INTERVAL &amp;#39;{{days}} day&amp;#39; and symbol like &amp;#39;%.swap&amp;#39;&lt;br /&gt;GROUP BY &lt;br /&gt;    symbol&lt;br /&gt;ORDER BY &lt;br /&gt;    volatility_percentage {{rank}}&lt;br /&gt;LIMIT &lt;br /&gt;    {{limit}};&lt;br /&gt;```&lt;br /&gt;This SQL code is used to get the volatility percentage of the trading pair that meets the criteria from the table &amp;quot;market.futures_binance_d1&amp;quot; and sort and limit the quantity output by volatility percentage.&lt;br /&gt;&lt;br /&gt;The explanation of this SQL is given below:&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;1. Two expressions were used for calculation, one was to replace the &amp;#39;_usdt.swap&amp;#39; in the &amp;#39;symbol&amp;#39; column with an empty string and convert the result to uppercase, and the other was to calculate (MAX(high) - MIN(low)) / AVG((high+low) / 2).&lt;br /&gt;The first expression uses the REPLACE function to replace strings that meet the criteria, and then uses the UPPER function to convert the result to uppercase.&lt;br /&gt;The second expression calculates the difference between the highest and lowest prices divided by the average of the highest and lowest prices to calculate the percentage of volatility.&lt;br /&gt;&lt;br /&gt;2. FROM clause:&lt;br /&gt;The specified data table to be queried is &amp;quot;market.futures.binance_d1&amp;quot;.&lt;br /&gt;&lt;br /&gt;3. WHERE clause:&lt;br /&gt;Two filter conditions are used: timestamp &amp;gt;= CURRENT_DATE - INTERVAL &amp;#39;{{days}} day&amp;#39; and symbol like &amp;#39;%.swap&amp;#39;.&lt;br /&gt;The first condition filters out data within the last {{days}} days.&lt;br /&gt;The second condition filters out trading pairs where the &amp;quot;symbol&amp;quot; column ends in &amp;#39;.swap&amp;#39;.&lt;br /&gt;&lt;br /&gt;4. GROUP BY clause:&lt;br /&gt;Group by the &amp;quot;symbol&amp;quot; column.&lt;br /&gt;&lt;br /&gt;5. ORDER BY clause:&lt;br /&gt;Sort by volatility percentage, either ascending (ASC) or descending (DESC), depending on the {{rank}} parameter.&lt;br /&gt;&lt;br /&gt;6. LIMIT clause:&lt;br /&gt;Limit the number of output results, which can be set according to the {{limit}} parameter.&lt;br /&gt;```&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149185
" title="https://stocksharp.com/file/149185
"&gt;https://stocksharp.com/file/149185
&lt;/a&gt;&lt;br /&gt;When we enter the parameters:&lt;br /&gt;days: 10 , rank: DESC , limit: 10, click the &amp;quot;Execute&amp;quot; button to execute the SQL statement and query the result.&lt;br /&gt;&lt;br /&gt;In addition to displaying data in the form of tables, it can also be displayed in a variety of visualization ways. After setting up some relevant settings for visualization, the data will be displayed in a richer and more vivid way.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149186
" title="https://stocksharp.com/file/149186
"&gt;https://stocksharp.com/file/149186
&lt;/a&gt;&lt;br /&gt;The created query can also generate URLs for easy sharing, and we can also modify the parameters to update the query (try modifying the parameters to update the query here in the article). Follwing is a chart of the real-time data generated:&lt;br /&gt;&lt;br /&gt;volatility ranking&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149187
" title="https://stocksharp.com/file/149187
"&gt;https://stocksharp.com/file/149187
&lt;/a&gt;&lt;br /&gt;In-depth Replay&lt;br /&gt;Next we&amp;#39;re going to study an example of studying a market micro-scenario, which is a wonderful tool for studying the details of high-frequency trading.&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;select * from market.binance where symbol = lower(&amp;#39;{{symbol}}&amp;#39;) order by timestamp desc limit 2000&lt;br /&gt;```&lt;br /&gt;Use the above SQL statement to query the tick level tick data for a particular species.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149188
" title="https://stocksharp.com/file/149188
"&gt;https://stocksharp.com/file/149188
&lt;/a&gt;&lt;br /&gt;The SQL query for this example is very simple, just querying the Tick data for a certain variety (specified by the parameter symbol) on the Binance exchange.&lt;br /&gt;&lt;br /&gt;The point is to show the data in the form of a live trading replay, on a time series, with multiple charts:&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149189
" title="https://stocksharp.com/file/149189
"&gt;https://stocksharp.com/file/149189
&lt;/a&gt;&lt;br /&gt;Is it convenient to study the details in the market?&lt;br /&gt;&lt;br /&gt;Next, let&amp;#39;s take a look at how to share our research. We can click on the share icon in the upper right corner.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149190
" title="https://stocksharp.com/file/149190
"&gt;https://stocksharp.com/file/149190
&lt;/a&gt;&lt;br /&gt;These shared codes, links, can be embedded in FMZ platform community posts, articles. They can be embedded in web pages and can be republished in other communities, forums, etc. It can also be shared directly to anyone.&lt;br /&gt;&lt;a href="https://stocksharp.com/file/149191
" title="https://stocksharp.com/file/149191
"&gt;https://stocksharp.com/file/149191
&lt;/a&gt;&lt;br /&gt;What are you waiting for with this powerful quantitative trading tool? Try to mine the data and analyze it.&lt;br /&gt;From: &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAAAezbpL9G-wNBo0jpp0vfUOwHPGoBwiLq1oM9OMAwzPdFM4UM8QeXCxEonXD9GaBcjk-lqekTpv_0LuQCvUnpJsO-jxJPnJNRpb4b03txvGwXl8GRWdlfv1xR3Kmh-GJ5ntf1I45lPMo8FzgkmMDikIAE70TlIimT7dHeGi559UEA9UWqnYtYT5Psub0cdVwmU" title="https://blog.mathquant.com/2024/02/26/an-essential-tool-in-the-field-of-quantitative-trading-fmz-quant-data-exploration-module.html"&gt;https://blog.mathquant.c...-exploration-module.html&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/25218/</id>
    <title type="text">Custom Local Broker Api </title>
    <published>2023-12-03T16:11:47Z</published>
    <updated>2023-12-04T16:00:43Z</updated>
    <author>
      <name>Adem CELIK</name>
      <uri>https://stocksharp.com/users/182886/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">Hi, I have to acces to my broker api with my api key and password. I have also all endpoints and requirements such as headers and payloads in api user guide’s document. How can I create new connector or adaptor in S#?</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/9284/</id>
    <title type="text">Google Feed</title>
    <published>2018-04-06T05:06:09Z</published>
    <updated>2023-10-23T15:32:56Z</updated>
    <author>
      <name>fernando</name>
      <uri>https://stocksharp.com/users/101166/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="Sources" />
    <category term="google" />
    <content type="html">I am having problems to do the setup of the Google on Hydra. Where can I find some tutorial about it?&lt;br /&gt;&lt;br /&gt;After I select the security and select to show the candles like show in this video &lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAACxXAhpkCOAGVeUUeYtluvBHtR5Yo76FfGo0d6fBsqYTvyjewFhckwIAG4IGTaI4wc" title="https://www.youtube.com/watch?v=3F8WvQq_O_E, "&gt;https://www.youtube.com/watch?v=3F8WvQq_O_E, &lt;/a&gt;I receive the message &amp;quot;&lt;span style="color:red"&gt;No data&lt;/span&gt;&amp;quot; </content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/15330/</id>
    <title type="text">Custom Adapter</title>
    <published>2021-02-23T09:43:07Z</published>
    <updated>2023-10-18T05:59:34Z</updated>
    <author>
      <name>dabithhc</name>
      <uri>https://stocksharp.com/users/117088/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">Hi, &lt;br /&gt;&lt;br /&gt;I try to configure my custom created connector by using ConnectorWindow in StockSharp.Xaml.&lt;br /&gt;But I cannot find it in the list of connectors.&lt;br /&gt;I put my dll in the same folder as exe and I also added attributes like DisplayNameLoc, CategoryLoc, DescriptionLoc and MessageAdapterCategory.&lt;br /&gt;So I wonder if it is possible or did I do it wrong.&lt;br /&gt;If not, how can I use my custom connector to work with other product like S# Designer?&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/24963/</id>
    <title type="text">Unable to connect to exchange</title>
    <published>2023-08-12T02:46:21Z</published>
    <updated>2023-08-19T11:10:42Z</updated>
    <author>
      <name>Imperishable</name>
      <uri>https://stocksharp.com/users/180612/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">I just registered with StockSharp and installed the Terminal. I am trying to connect to Binance but it gives me an error -&lt;b&gt; Connector is stub only&lt;/b&gt;.&lt;br /&gt;I believe that one connection is allowed for the free tier, right? I remember selecting Binance when prompted for the 1 free connection during the installation. </content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/24926/</id>
    <title type="text">Does  Ecng.ManagedWinapi support MAUI?</title>
    <published>2023-07-15T09:02:11Z</published>
    <updated>2023-07-15T10:51:36Z</updated>
    <author>
      <name>caianhua</name>
      <uri>https://stocksharp.com/users/179931/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;a target="_blank" rel="nofollow" href="https://stocksharp.com/away/?u=AQAAAAAAAADAA4TGU_jki3l8pb1ggjgCXXd4jeDzDOJ-czvmU55Kg90sFh-w53xRffaGh0dJ-Ej6DY_MrhjZEfuR7aLY9w9ejzwWaSuF6BrNGA61xyRpMDSi6klGqsqGubQGxQK6LfIO4SAIyMe2Soe4dT6RVlDH" title="https://stackoverflow.com/questions/76040581/handle-windows-message-in-maui-windows-using-winapi "&gt;https://stackoverflow.co...ui-windows-using-winapi &lt;/a&gt;    like this article said , support MAUI.</content>
  </entry>
  <entry>
    <id>https://stocksharp.com/topic/10707/</id>
    <title type="text">S#.Designer syllabus.</title>
    <published>2019-05-16T23:12:23Z</published>
    <updated>2023-04-17T20:24:31Z</updated>
    <author>
      <name>Marat</name>
      <uri>https://stocksharp.com/users/101940/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <category term="Edu" />
    <category term="trading" />
    <category term="exchange" />
    <category term="create trading robot" />
    <category term="Trader" />
    <category term="video course" />
    <category term="trading strategy" />
    <category term="learning how to make trading robots" />
    <category term="make robots" />
    <content type="html">All video-lessons are available via the links below.&lt;br /&gt;All samples for lessons can be installed via S#.Installer.&lt;br /&gt;For Basic course you need the packet: &lt;a href="https://stocksharp.com/store/lessons-designer-basic/" title="Edu Designer Basic"&gt;Edu Designer Basic&lt;/a&gt;&lt;br /&gt;For Advanced course you need the packet: &lt;a href="https://stocksharp.com/store/lessons-designer-advanced/" title="Edu Designer Advanced"&gt;Edu Designer Advanced&lt;/a&gt;&lt;br /&gt;&lt;h3&gt;&lt;div align="center"&gt;Basic course.&lt;/div&gt;&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15269/sdesigner-basics-/" title="https://stocksharp.com/forum/15269/sdesigner-basics-/"&gt;1. S#.Designer basics &lt;/a&gt;&lt;/b&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Installing the program&lt;br /&gt;- Configuring the interface of the program windows&lt;br /&gt;- Examines the main sections of the Program menu&lt;br /&gt;- Examines the sections of the strategy tree&lt;br /&gt;- Shows how to download instruments and market data for the first time&lt;br /&gt;- Shows how to start testing a strategy on the built-in SMA strategy.&lt;br /&gt;&lt;br /&gt;(The new version of the designer, like all programs, is installed through the Installer program.&lt;br /&gt;The fifth version of the designer lacks the ability to select the themes of the designer, which was present in the fourth version) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15270/2-visual-editor-and-strategy-designer-blocks---1/" title="https://stocksharp.com/forum/15270/2-visual-editor-and-strategy-designer-blocks---1/"&gt;2. Visual editor and strategy designer blocks - 1.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- General description of strategy cubes&lt;br /&gt;- Examines the sections of the strategy cubes menu&lt;br /&gt;- Examines the cube chart panel&lt;br /&gt;- Examines the construction of candlestick charts&lt;br /&gt;- Examines the construction of charts of the SMA and Bollinger indicator in the same window and in different windows&lt;br /&gt;&lt;br /&gt;(In the fifth version of the program, the location of some cubes in the menu has changed.&lt;br /&gt;In the fifth version, the mathematics section is replaced by a formula cube.) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15271/3-visual-editor-and-strategy-designer-blocks---2/" title="https://stocksharp.com/forum/15271/3-visual-editor-and-strategy-designer-blocks---2/"&gt;3. Visual editor and strategy designer blocks - 2.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Description of the cube Variable and examines examples of the use of the cube&lt;br /&gt;- Examines the Logic cube and an example of its application&lt;br /&gt;- Examines the Previous value cube and an example of its application&lt;br /&gt;- Examines the Mathematics section and the use of cubes that are included in it&lt;br /&gt;- Examines the Converters section (cubes &amp;quot;Indexer&amp;quot; and &amp;quot;Converter&amp;quot;) and an example of sharing the cubes of the section&lt;br /&gt;- Considers the cube &amp;quot;Opening a position&amp;quot;&lt;br /&gt;- Considers the cube &amp;quot;Position&amp;quot; and the scheme in which it is applied&lt;br /&gt;- Considers the cube &amp;quot;Comparison&amp;quot; and an example of its application&lt;br /&gt;- Considered building a simple strategy:&lt;br /&gt;&lt;em&gt;If the closing price of the previous candle is less than the closing price of the current one, then we buy, if not, we sell.&lt;/em&gt;&lt;br /&gt;- Considers the &amp;quot;Comparison&amp;quot; cube and an example of its application&lt;br /&gt;&lt;br /&gt;(In the fifth version, the mathematics section is replaced by one formula cube. In the fifth version of the program, the &amp;quot;Position opening&amp;quot; cube is replaced with &amp;quot;Position registration&amp;quot;) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15273/4-work-with-the-strategy-scheme/" title="https://stocksharp.com/forum/15273/4-work-with-the-strategy-scheme/"&gt;4. Work with the strategy scheme.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Debugger tools&lt;br /&gt;- Working with breakpoints is considered on the example of a circuit&lt;br /&gt;- On an example, the possibility of imposing additional conditions on triggering a breakpoints is considered&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15274/5-visual-editor-and-strategy-designer-blocks---3/" title="https://stocksharp.com/forum/15274/5-visual-editor-and-strategy-designer-blocks---3/"&gt;5. Visual editor and strategy designer blocks - 3.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considers the cube &amp;quot;Position protection&amp;quot;&lt;br /&gt;- A strategy is built using the &amp;quot;Position protection&amp;quot; cube:&lt;br /&gt;&lt;em&gt;If the difference between the closing price and the opening price of the candle is greater than 1, then we buy.&lt;br /&gt;We sell position protection through the cube, provided that:&lt;br /&gt;Take Profit - the price increases by 2%&lt;br /&gt;Stop Loss - the price decreases by 3%&lt;/em&gt;&lt;br /&gt;- An example of constructing the conditions for triggering transactions has been analyzed, in which Buy and Sell transactions go sequentially one after the other (the simplest flag)&lt;br /&gt;- A scheme has been built for obtaining the absolute value of a position and doubling its value&lt;br /&gt;- Using the example of the scheme from lesson three and the scheme for obtaining the absolute value of the position, the following scheme is obtained:&lt;br /&gt;&lt;em&gt;If the closing price of the previous candle is less than the closing price of the current one, then we buy, if, on the contrary, we sell.&lt;br /&gt;If the position is not equal to zero, then the trade is carried out with a double volume &lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15275/6-visual-editor-and-strategy-designer-blocks---4/" title="https://stocksharp.com/forum/15275/6-visual-editor-and-strategy-designer-blocks---4/"&gt;6. Visual editor and strategy designer blocks - 4.&lt;/a&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Examines the cubes of the &amp;quot;Mathematics&amp;quot; section - formulas, including examples of their use&lt;br /&gt;- Considered the construction of the scheme:&lt;br /&gt;&lt;em&gt;If the closing price of the previous candle is greater than the value of the SMA indicator for 20 periods plus 3 standard deviations for 20 periods, then we sell by candle open price.&lt;br /&gt;If the closing price of the previous candle is less than the value of the SMA indicator for 20 periods minus 3 standard deviations for 20 periods, then we make a buy at the opening price of the candle.&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;(In the fifth version of the program there is no section &amp;quot;Mathematics&amp;quot;, all the cubes of this section used in earlier versions of the program are replaced by one cube formula.&lt;br /&gt;In the fifth version of the program, the cube &amp;quot;Position opening&amp;quot; is replaced by the cube &amp;quot;Order registration&amp;quot;.) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15276/7-more-strategies/" title="https://stocksharp.com/forum/15276/7-more-strategies/"&gt;7. More strategies.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- The construction of a diagram based on the Bollinger indicator is considered:&lt;br /&gt;&lt;em&gt;If the candlestick crosses the upper curve of the Bollinger indicator, then we buy.&lt;br /&gt;If the candlestick crosses the lower curve of the Bollinger indicator then we sell.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;- Considered the construction of the scheme based on the MACD indicator:&lt;br /&gt;&lt;em&gt;If the MACD curve changes its sign from minus to plus, then buy.&lt;br /&gt;If the MACD curve changes its sign from plus to minus, then we sell.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;- Considered a visual comparison of the results of two strategies&lt;br /&gt;- Considered exporting test results to a file for subsequent analysis &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15277/8-visual-editor-and-strategy-designer-blocks---5/" title="https://stocksharp.com/forum/15277/8-visual-editor-and-strategy-designer-blocks---5/"&gt;8. Visual editor and strategy designer blocks - 5.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- The construction of a scheme using candles of different TFs is considered:&lt;br /&gt;&lt;em&gt;First branch: The strategy will buy if the closing price of a five-minute candle is greater than the maximum of 20 previous days.&lt;br /&gt;The strategy will sell if the closing price of the 5 minute candle is less than the previous 10 day low.&lt;br /&gt;&lt;br /&gt;The second branch: The strategy will sell if the closing price of the five-minute candle is less than the minimum of the previous 20 days.&lt;br /&gt;The strategy will buy if the closing price of the five-minute candle is greater than the high of the previous 10 days.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;(In the fifth version of the designer, the appearance of the flag cube was changed. Also, in the fifth version of the designer, the strategy was changed in terms of the appearance of 2 sell cubes and 2 buy cubes, due to a different principle of receiving a signal to the trigger.) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15278/9-time-cubes/" title="https://stocksharp.com/forum/15278/9-time-cubes/"&gt;9. Time Cubes.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the &amp;quot;Working time&amp;quot; cube&lt;br /&gt;- Considered the &amp;quot;Variable&amp;quot; cube with the &amp;quot;Strategy&amp;quot; value&lt;br /&gt;- Considered the &amp;quot;Converter&amp;quot; cube with the function of getting time&lt;br /&gt;- Considered the strategy of working with the &amp;quot;Working time&amp;quot; cube with the condition:&lt;br /&gt;&lt;em&gt;Strategy buys a minute before the end working time.&lt;/em&gt;&lt;br /&gt;- Considered an example of working with the &amp;quot;Working hours&amp;quot; cube: &lt;br /&gt;&lt;em&gt;The strategy buys at 18.00.&lt;/em&gt;&lt;br /&gt;- Considered a 7th lesson strategy with additional conditions: &lt;br /&gt;&lt;em&gt;The strategy closes a position 5 minutes before the end of working hours.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;(In the fifth version of the designer, for correct work with the formula that calculates the time and the cube &amp;quot;Working time&amp;quot;, after importing the strategies, it is recommended to recreate them) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15279/10-working-with-market-data-sdata-(hydra)/" title="https://stocksharp.com/forum/15279/10-working-with-market-data-sdata-(hydra)/"&gt;10. Working with market data. S#.Data (Hydra)&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered examples of choosing a market data store&lt;br /&gt;- Considered an example of working with the S#.Data (Hydra) program&lt;br /&gt;- Considered a server mode of working with S#.Data (Hydra) program&lt;br /&gt;- Considered an example of using a market data transmitted through a server mode&lt;br /&gt;&lt;br /&gt;(In the fifth server-mode version does not contain WCF mode.) &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15280/11-backtest-and-optimization/" title="https://stocksharp.com/forum/15280/11-backtest-and-optimization/"&gt;11. Backtest and optimization.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the basics of strategy optimization&lt;br /&gt;- Considered strategy optimization based on changing the indicator parameter used in the strategy&lt;br /&gt;- Considered the principle of portfolio optimization of a strategy on various instruments &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15281/12-live-trading/" title="https://stocksharp.com/forum/15281/12-live-trading/"&gt;12. Live trading.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;-Example of setting up a strategy for connecting to Live mode &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;div align="center"&gt;Advanced course.&lt;/div&gt;&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15310/13-composite-cubes/" title="https://stocksharp.com/forum/15310/13-composite-cubes/"&gt;13. Composite Cubes.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the &amp;quot;Union&amp;quot; cube&lt;br /&gt;- Considered the principle of working with a compound cube using the example of creating a cube for closing a position&lt;br /&gt;- Considered an example of introducing a compound cube &amp;quot;Closing a position&amp;quot; into an existing strategy from lesson 9 &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15311/14-creating-candles-from-ticks/" title="https://stocksharp.com/forum/15311/14-creating-candles-from-ticks/"&gt;14. Creating candles from ticks.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered how to download ticks in the program&lt;br /&gt;- Considered how to build candles from the &amp;quot;Depth of Market&amp;quot;&lt;br /&gt;- Considered the modes &amp;quot;Build&amp;quot;, &amp;quot;Downloads&amp;quot;, &amp;quot;Load and build&amp;quot; candles&lt;br /&gt;- Considered an example of building volume candles&lt;br /&gt;- Considered an example of plotting a Range of candles&lt;br /&gt;- Considered construction of candles from Ticks&lt;br /&gt;- Considered the construction of candles from candles of a smaller TF&lt;br /&gt;- Considered the use of candles built in the S#.Data (Hydra)&lt;br /&gt;- Considered building a volume profile &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15312/15-building-the-flag-component-cube/" title="https://stocksharp.com/forum/15312/15-building-the-flag-component-cube/"&gt;15. Building the Flag component cube&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15313/16-strategy-based-on-finding-the-price-of-the-maximum-volume/" title="https://stocksharp.com/forum/15313/16-strategy-based-on-finding-the-price-of-the-maximum-volume/"&gt;16. Strategy based on finding the price of the maximum volume.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the function of the &amp;quot;Converter&amp;quot; cube. Maximum volume&lt;br /&gt;- A strategy has been built in which candlestick data is built from ticks, with the following conditions: &lt;br /&gt;&lt;em&gt;The strategy buys if the closing price is higher than the opening price of the candle.&lt;br /&gt;The strategy sells at the sixth candlestick.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;(In the fifth version, the Flag cube was changed, as well as the condition for raising the flag. In the fifth version, the formula block cubes were replaced with the formula cube.)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15314/17-indices-and-multiple-security-strategies---1/" title="https://stocksharp.com/forum/15314/17-indices-and-multiple-security-strategies---1/"&gt;17. Indices and multiple security strategies - 1.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered working with stock indices&lt;br /&gt;- Considered working with futures on the example of a strategy with conditions:&lt;br /&gt;&lt;em&gt;If the index calculated by the SBER @ TQBR / SRM9 @ FORTS formula is less than the average value for 10 periods, then Sberbank shares are sold.&lt;br /&gt;If the index calculated by the SBER @ TQBR / SRM9 @ FORTS formula is greater than the average value for 10 periods, then we buy Sberbank shares.&lt;/em&gt;&lt;br /&gt;- The function of constructing a continuous futures is considered&lt;br /&gt;- A strategy with a continuous futures is built with the condition:&lt;br /&gt;&lt;em&gt;If the current value of the SBER @ TQBR / SBER_СF @ FORTS index is 0.005 units above the average, sell the instrument Sberbank Shares and buy the instrument of Sberbank shares.&lt;br /&gt;If the current value of the SBER @ TQBR / SBER_СF @ FORTS index is 0.005 units lower than the average, buy the Sberbank Shares instrument and sell the Sberbank shares instrument.&lt;/em&gt;&lt;br /&gt;- Based on the strategy, an example of building a scheme with cancellation of an order is considered &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15315/18-indices-and-multiple-security-strategies---2/" title="https://stocksharp.com/forum/15315/18-indices-and-multiple-security-strategies---2/"&gt;18. Indices and multiple security strategies - 2.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered a pair trading strategy based on the previous strategy.&lt;br /&gt;&lt;em&gt;If the index calculated by the SBER @ TQBR / GAZP @ TQBR formula grows, then we buy a cheaper asset and sell a more expensive one.&lt;br /&gt;If the index calculated using the SBER @ TQBR / GAZP @ TQBR formula decreases, then we buy a more expensive asset and sell a cheaper one.&lt;/em&gt;&lt;br /&gt;- Considered the round operator - to get an integer value&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15316/19-indices-and-multiple-security-strategies---3/" title="https://stocksharp.com/forum/15316/19-indices-and-multiple-security-strategies---3/"&gt;19. Indices and multiple security strategies - 3.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Lesson highlights:&lt;br /&gt;- Considered a pyramiding strategy based on the previous strategy from the previous lesson. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15317/20-working-with-the-editor-of-the-program-code-1/" title="https://stocksharp.com/forum/15317/20-working-with-the-editor-of-the-program-code-1/"&gt;20. Working with the editor of the program code-1.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the &amp;quot;Source Code&amp;quot; cube&lt;br /&gt;- Considered the principle of creating a cube with a code&lt;br /&gt;- Considered the principle of creating your own unique cube with a code&lt;br /&gt;&lt;br /&gt;(Today the StockSharp website does not have a direct link to Github, so you need to go to it not through the website)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15318/21-work-with-the-program-code-editor---2/" title="https://stocksharp.com/forum/15318/21-work-with-the-program-code-editor---2/"&gt;21. Work with the program code editor - 2.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The lesson covers:&lt;br /&gt;- Considered the creation of cubes on C# in Visual Studio&lt;br /&gt;- Considered the DLL cube&lt;br /&gt;- Considered the principle of working with S#.API libraries in Visual Studio &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="https://stocksharp.com/forum/15319/22-export-and-import-of-strategies-in-the-program/" title="https://stocksharp.com/forum/15319/22-export-and-import-of-strategies-in-the-program/"&gt;22. Export and import of strategies in the program.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="https://stocksharp.com/edu/" title="https://stocksharp.com/edu/"&gt;&lt;span style="font-size:140%"&gt;You can buy any course right now from our site&lt;/span&gt;&lt;/a&gt;</content>
  </entry>
</feed>