
Using asyncio and WebSocket to Retrieve and Record Binance K-Line Market Data
As we know, Binance offers two methods to obtain K-line data: REST API and WebSocket. Among these, WebSocket is the preferred method recommended by Binance for obtaining real-time data. This guide will show you how to use Python asyncio to subscribe to Binance K-line data via WebSocket, and asynchronously record Binance K-line market data as Pandas DataFrame in Parquet format.Connecting to Binance Market Data WebSocketTo get market data via WebSocket, we first need to implement a robust WebSo...

Switching from iTerm2 to Ghostty
I've been using iTerm2 for years, but recently switched to Ghostty — and I'm not going back...

Quant Trader / HODLER

This article summarizes Ray Dalio’s video How The Economic Machine Works
The economy operates like a simple machine, yet many people are unaware or disagree with this perspective, leading to unnecessary economic losses.
Here is an analysis framework that may not perfectly align with traditional economics but is highly useful:
The economy appears complex but functions in a straightforward and mechanical way.
It is composed of a few simple parts and countless simple transactions, driven by human nature.
Three main economic forces:
Productivity growth
Short-term debt cycle
Long-term debt cycle
An exchange between a buyer and a seller is called a transaction, which occurs constantly.
The economy is the sum total of numerous transactions.
In each transaction: Buyers pay money or credit to obtain goods, services, or financial assets from sellers.
The sum of money and credit paid by the buyer is the total spending, which is the driving force of the economy, i.e., Total Spending = Money + Credit.
Dividing the total spending by the seller's product sales volume gives the price, i.e., Price = Total Spending / Sales Volume.
Transactions are the fundamental components of the economic machine; all economic cycles and forces are caused by transactions. Thus, understanding transactions is to understand the economy.
A market consists of sellers and buyers trading the same type of goods, such as wheat markets, car markets, stock markets, etc.
The economy is made up of all transactions within all markets. Adding up all the markets' total spending and sales volumes gives us all the information needed to understand the economy.
Individuals, companies, banks, and governments all engage in transactions.
The government is the largest seller and buyer, consisting of the central government and the central bank:
Central government: Responsible for taxation and spending.
Central bank: Unlike other buyers and sellers, the central bank controls the amount of money and credit in the economy by influencing interest rates and issuing currency, playing a crucial role in the circulation of credit.
Credit is the most important and most volatile part of the economy.
Participants in credit include borrowers and lenders:
Lenders: Desire to earn interest on their money by lending it to borrowers.
Borrowers: Wish to purchase something they currently cannot afford and borrow money from lenders, repaying the principal and interest at a later date.
The impact of interest rates on borrowing: High interest rates mean more interest to pay, reducing borrowing; low interest rates encourage borrowing due to lower interest expenses.
As long as borrowers can assure repayment and lenders trust their promise, credit is created; thus, any two people can create credit out of thin air.
Debt comes with the creation of credit; it is an asset to the lender and a liability to the borrower. When the loan is repaid, these assets and liabilities disappear simultaneously.
A borrower's creditworthiness includes two aspects:
A higher ratio of income to debt indicates good repayment capacity.
Sufficient collateral that can be used to repay the debt if unable to pay back in cash.
The significance of credit: When borrowers obtain credit, they can increase spending, which in turn increases someone else's income; the increase in income can lead to more borrowing and credit, causing the economy to rise, but also leading to economic cycles.
Over the long term, productivity improvements lead to income growth, but productivity does not fluctuate sharply and is not a significant driver of short-term economic fluctuations.
In the short term, credit is most crucial because borrowing leads to consumption exceeding output, and repayment causes consumption to fall below output.
Fluctuations in debt levels create two major cycles:
Short-term debt cycle: Lasts approximately 5-8 years.
Long-term debt cycle: Lasts approximately 75-100 years.
The rise and fall of the economy depend mainly on the total amount of credit. Without credit, the economy would grow solely in line with productivity.
Due to the existence of credit, the economy experiences cyclical fluctuations, determined by human nature.
A cycle that applies both to individuals and the overall economy:
Currently, consumption exceeds income through borrowing.
In the future, consumption must be less than spending to repay debts.
Transactions completed with money are settled immediately.
Transactions completed with credit, such as buying on credit, create liabilities and assets, and are only concluded once the debt is repaid, with liabilities and assets disappearing simultaneously.
In reality, most money is actually credit. For example, in the United States, the total credit is approximately $50 trillion, while the total money supply is about $3 trillion.
In a credit system, increasing credit can boost income growth in the short term, but not necessarily in the long term.
Credit is not inherently bad, but it does cause cyclical changes in the economy:
Bad credit: Credit leads to consumption that exceeds the ability to repay.
Good credit: Efficiently allocates resources and generates income that can repay debts.
Borrowing creates cycles that rise and fall.
The first phase: Expansion occurs as economic activity increases; during this stage, credit is created out of thin air, spending increases, but total sales volume does not keep up with the increase in spending, leading to rising prices and inflation.
The second phase: The central bank, not wanting high inflation, raises interest rates, making fewer people borrow and increasing repayments, which reduces spending and income. Prices drop, causing deflation and economic recession.
The next cycle: The central bank lowers interest rates, leading to another economic expansion.
Thus, in the short-term debt cycle, the economy moves mechanically with interest rate changes: low interest rates lead to expansion, high interest rates lead to contraction.
The short-term debt cycles repeat, but after each cycle, economic growth and debt exceed the previous cycle (driven by human nature), forming the long-term debt cycle.
Prosperity period:
During this period, incomes rise, and asset prices increase simultaneously, allowing more borrowing and consumption, creating a cycle. However, economic bubbles also form.
If debt growth matches the growth rate of income and asset prices, the debt burden remains manageable, but this situation cannot last forever.
Peak of long-term debt: As the debt burden increases and the cost of debt grows faster than income, people are forced to cut spending, further reducing income and increasing debt costs, forming a vicious cycle, reaching the peak of long-term debt, and reversing the cycle (e.g., the 2008 subprime mortgage crisis, the 1929 Great Depression).
Deleveraging period: People cut spending, income falls, credit disappears, asset prices drop, banks face runs, creating a negative spiral. As interest rates are already low, the central bank cannot reverse the situation by lowering rates, and the entire economy loses credibility.
Deleveraging can occur in four ways, some leading to deflation, others to inflation. Policymakers need to carefully balance the two to deleverage harmoniously:
Cut spending:
During deleveraging, individuals, companies, and governments reduce spending to repay debts, leading to decreased income and an increased debt burden, causing deflation.
Companies cut costs, raising unemployment rates.
Reduce debt:
With falling incomes and rising unemployment rates, borrowers cannot repay loans, banks face runs, and individuals, companies, and banks default, leading to severe economic contraction—depression. The main characteristic is that much of the wealth supported by credit vanishes due to defaults.
Some lenders may allow debt restructuring to prevent total loss from defaults, including reducing repayments, extending terms, lowering interest rates, etc. These measures also reduce debt but cause asset prices to fall, resulting in deflation.
Combining productivity growth, the short-term debt cycle, and the long-term debt cycle provides a useful model.
Although the real economy is much more complex than this model, it helps us clearly understand past and present situations and anticipate potential future developments.
Do not let debt growth exceed income growth.
Do not let income growth exceed productivity growth.
Strive to increase productivity by all means possible.

Using asyncio and WebSocket to Retrieve and Record Binance K-Line Market Data
As we know, Binance offers two methods to obtain K-line data: REST API and WebSocket. Among these, WebSocket is the preferred method recommended by Binance for obtaining real-time data. This guide will show you how to use Python asyncio to subscribe to Binance K-line data via WebSocket, and asynchronously record Binance K-line market data as Pandas DataFrame in Parquet format.Connecting to Binance Market Data WebSocketTo get market data via WebSocket, we first need to implement a robust WebSo...

Switching from iTerm2 to Ghostty
I've been using iTerm2 for years, but recently switched to Ghostty — and I'm not going back...
This article summarizes Ray Dalio’s video How The Economic Machine Works
The economy operates like a simple machine, yet many people are unaware or disagree with this perspective, leading to unnecessary economic losses.
Here is an analysis framework that may not perfectly align with traditional economics but is highly useful:
The economy appears complex but functions in a straightforward and mechanical way.
It is composed of a few simple parts and countless simple transactions, driven by human nature.
Three main economic forces:
Productivity growth
Short-term debt cycle
Long-term debt cycle
An exchange between a buyer and a seller is called a transaction, which occurs constantly.
The economy is the sum total of numerous transactions.
In each transaction: Buyers pay money or credit to obtain goods, services, or financial assets from sellers.
The sum of money and credit paid by the buyer is the total spending, which is the driving force of the economy, i.e., Total Spending = Money + Credit.
Dividing the total spending by the seller's product sales volume gives the price, i.e., Price = Total Spending / Sales Volume.
Transactions are the fundamental components of the economic machine; all economic cycles and forces are caused by transactions. Thus, understanding transactions is to understand the economy.
A market consists of sellers and buyers trading the same type of goods, such as wheat markets, car markets, stock markets, etc.
The economy is made up of all transactions within all markets. Adding up all the markets' total spending and sales volumes gives us all the information needed to understand the economy.
Individuals, companies, banks, and governments all engage in transactions.
The government is the largest seller and buyer, consisting of the central government and the central bank:
Central government: Responsible for taxation and spending.
Central bank: Unlike other buyers and sellers, the central bank controls the amount of money and credit in the economy by influencing interest rates and issuing currency, playing a crucial role in the circulation of credit.
Credit is the most important and most volatile part of the economy.
Participants in credit include borrowers and lenders:
Lenders: Desire to earn interest on their money by lending it to borrowers.
Borrowers: Wish to purchase something they currently cannot afford and borrow money from lenders, repaying the principal and interest at a later date.
The impact of interest rates on borrowing: High interest rates mean more interest to pay, reducing borrowing; low interest rates encourage borrowing due to lower interest expenses.
As long as borrowers can assure repayment and lenders trust their promise, credit is created; thus, any two people can create credit out of thin air.
Debt comes with the creation of credit; it is an asset to the lender and a liability to the borrower. When the loan is repaid, these assets and liabilities disappear simultaneously.
A borrower's creditworthiness includes two aspects:
A higher ratio of income to debt indicates good repayment capacity.
Sufficient collateral that can be used to repay the debt if unable to pay back in cash.
The significance of credit: When borrowers obtain credit, they can increase spending, which in turn increases someone else's income; the increase in income can lead to more borrowing and credit, causing the economy to rise, but also leading to economic cycles.
Over the long term, productivity improvements lead to income growth, but productivity does not fluctuate sharply and is not a significant driver of short-term economic fluctuations.
In the short term, credit is most crucial because borrowing leads to consumption exceeding output, and repayment causes consumption to fall below output.
Fluctuations in debt levels create two major cycles:
Short-term debt cycle: Lasts approximately 5-8 years.
Long-term debt cycle: Lasts approximately 75-100 years.
The rise and fall of the economy depend mainly on the total amount of credit. Without credit, the economy would grow solely in line with productivity.
Due to the existence of credit, the economy experiences cyclical fluctuations, determined by human nature.
A cycle that applies both to individuals and the overall economy:
Currently, consumption exceeds income through borrowing.
In the future, consumption must be less than spending to repay debts.
Transactions completed with money are settled immediately.
Transactions completed with credit, such as buying on credit, create liabilities and assets, and are only concluded once the debt is repaid, with liabilities and assets disappearing simultaneously.
In reality, most money is actually credit. For example, in the United States, the total credit is approximately $50 trillion, while the total money supply is about $3 trillion.
In a credit system, increasing credit can boost income growth in the short term, but not necessarily in the long term.
Credit is not inherently bad, but it does cause cyclical changes in the economy:
Bad credit: Credit leads to consumption that exceeds the ability to repay.
Good credit: Efficiently allocates resources and generates income that can repay debts.
Borrowing creates cycles that rise and fall.
The first phase: Expansion occurs as economic activity increases; during this stage, credit is created out of thin air, spending increases, but total sales volume does not keep up with the increase in spending, leading to rising prices and inflation.
The second phase: The central bank, not wanting high inflation, raises interest rates, making fewer people borrow and increasing repayments, which reduces spending and income. Prices drop, causing deflation and economic recession.
The next cycle: The central bank lowers interest rates, leading to another economic expansion.
Thus, in the short-term debt cycle, the economy moves mechanically with interest rate changes: low interest rates lead to expansion, high interest rates lead to contraction.
The short-term debt cycles repeat, but after each cycle, economic growth and debt exceed the previous cycle (driven by human nature), forming the long-term debt cycle.
Prosperity period:
During this period, incomes rise, and asset prices increase simultaneously, allowing more borrowing and consumption, creating a cycle. However, economic bubbles also form.
If debt growth matches the growth rate of income and asset prices, the debt burden remains manageable, but this situation cannot last forever.
Peak of long-term debt: As the debt burden increases and the cost of debt grows faster than income, people are forced to cut spending, further reducing income and increasing debt costs, forming a vicious cycle, reaching the peak of long-term debt, and reversing the cycle (e.g., the 2008 subprime mortgage crisis, the 1929 Great Depression).
Deleveraging period: People cut spending, income falls, credit disappears, asset prices drop, banks face runs, creating a negative spiral. As interest rates are already low, the central bank cannot reverse the situation by lowering rates, and the entire economy loses credibility.
Deleveraging can occur in four ways, some leading to deflation, others to inflation. Policymakers need to carefully balance the two to deleverage harmoniously:
Cut spending:
During deleveraging, individuals, companies, and governments reduce spending to repay debts, leading to decreased income and an increased debt burden, causing deflation.
Companies cut costs, raising unemployment rates.
Reduce debt:
With falling incomes and rising unemployment rates, borrowers cannot repay loans, banks face runs, and individuals, companies, and banks default, leading to severe economic contraction—depression. The main characteristic is that much of the wealth supported by credit vanishes due to defaults.
Some lenders may allow debt restructuring to prevent total loss from defaults, including reducing repayments, extending terms, lowering interest rates, etc. These measures also reduce debt but cause asset prices to fall, resulting in deflation.
Combining productivity growth, the short-term debt cycle, and the long-term debt cycle provides a useful model.
Although the real economy is much more complex than this model, it helps us clearly understand past and present situations and anticipate potential future developments.
Do not let debt growth exceed income growth.
Do not let income growth exceed productivity growth.
Strive to increase productivity by all means possible.
Share Dialog
Share Dialog
Quant Trader / HODLER
Wealth redistribution:
With falling incomes and rising unemployment, government tax revenues decrease, while governments need to increase spending on stimulus programs and relief efforts, leading to increased fiscal deficits. Governments must finance from the wealthy.
Governments might need to tax the wealthy to transfer wealth to the poor to stimulate consumption and the economy, but income disparity leads to social tensions and increased conflict.
Similar tensions exist between debtor and creditor nations. In the 1930s, such tensions led to World War II and the Great Depression in the United States.
Print money:
The central bank can print money to compensate for the lack of credit, stimulating the economy, but this can lead to inflation. Hyperinflation like that of 1920s Germany must be avoided.
The central bank can use newly printed money to purchase financial assets and government bonds, as was done during the Great Depression and the 2008 crisis in the US. This helps raise asset prices and bolsters the credit of those with financial assets.
Central bank purchases of government bonds help the government finance, distribute relief funds, and implement stimulus plans. Government debt may rise, but the total debt burden decreases.
Reflation: When income levels exceed debt, spending increases, and the economy grows again, entering the reflation phase.
The lost decade: Depressions and reflation typically last about ten years, hence the term "the lost decade."
Wealth redistribution:
With falling incomes and rising unemployment, government tax revenues decrease, while governments need to increase spending on stimulus programs and relief efforts, leading to increased fiscal deficits. Governments must finance from the wealthy.
Governments might need to tax the wealthy to transfer wealth to the poor to stimulate consumption and the economy, but income disparity leads to social tensions and increased conflict.
Similar tensions exist between debtor and creditor nations. In the 1930s, such tensions led to World War II and the Great Depression in the United States.
Print money:
The central bank can print money to compensate for the lack of credit, stimulating the economy, but this can lead to inflation. Hyperinflation like that of 1920s Germany must be avoided.
The central bank can use newly printed money to purchase financial assets and government bonds, as was done during the Great Depression and the 2008 crisis in the US. This helps raise asset prices and bolsters the credit of those with financial assets.
Central bank purchases of government bonds help the government finance, distribute relief funds, and implement stimulus plans. Government debt may rise, but the total debt burden decreases.
Reflation: When income levels exceed debt, spending increases, and the economy grows again, entering the reflation phase.
The lost decade: Depressions and reflation typically last about ten years, hence the term "the lost decade."

Subscribe to lostleaf.eth

Subscribe to lostleaf.eth
<100 subscribers
<100 subscribers
No activity yet