Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
from fastapi.concurrency import run_in_threadpool
async def execute(data: DataRequest) -> DataResponse:
try:
result = await run_in_threadpool(sync_function, data)
return DataResponse(data=result)
except Exception as e:
return DataResponse(
error=str(e),
success=False,
)
В общем работает нормально. Для всех вызовов под капотом используется общий тредпул, всё работает предсказуемо.
Но потребовалось изменить количество запускаемых в пуле потоков (по умолчанию создается 40 воркеров).
Так как дело происходит с FastAPI, делается это через lifespan используя настройки anyio:
import anyio
@asynccontextmanager
async def lifespan(app: FastAPI):
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = 100
yield
# если вдруг нужно вернуть обратно
limiter.total_tokens = 40
Зачем менять количество воркеров?
- уменьшить, если оперативки мало (один тред занимает ~8мб)
- увеличить чтобы выдержать нагрузку
Если есть предложения получше при тех же вводных - предлагайте😉
#async
📉 Bearish Pattern - Tweezer Tops.
A. How to recognise it?
• There must be a preceding uptrend.
• A green candle followed by red candle.
• Both candles have the same high.
B. What is the psychology behind?
• The candles in both sessions form the same high, suggesting that the market refuses to go above that price level. Once the price touches the ceiling, in retreats. That price level may be viewed as a short-term resistance.
• The closing price of the red candle shies away from the high further than the green candle does. It shows that bearish forces are getting stronger.
C. How do we trade it?
• Look for the Tweezer Top at the top of an uptrend.
• Wait for the next candle to close below the low of the two candles to confirm the existence of bearish force.
• Open a short position upon confirmation.
• Place a stop-loss above the high of the two candles.
#patterns#fibonacciacademy
📉 Bearish Pattern - Three Black Crows.
A. How to recognise it?
• There must be a preceding uptrend.
• There consecutive long red candles observed.
• The second and third candle opens within the body of the preceding one but closes lower than the preceding one.
B. What is the psychology behind?
• The first long red candle signals that the bulls are exhausted after the prolonged uptrend and the bears start to take over.
The bears continue the slump with the subsequent two candles closing lower.
C. How do we trade it?
• Look for the Three Black Crows at the top of an uptrend.
• Wait for the fourth candle to close below the low of the third candle to confirm the reversal.
• Open a short position upon confirmation.
• Place a stop-loss above the high of the first red candle.
#patterns#fibonacciacademy
📉Bearish Pattern - Gravestone Doji
A. How to recognise It?
• There must be a preceding uptrend.
• It looks like an inverted T letter.
• The opening, lowest and closing price are same.
• It has no real body but a long upper shadow.
B. What is the psychology behind?
• When the market opens, the bulls push the price all the way up, resulting in a long upper shadow.
• The bears fight strongly and eventually manage to drag the price back down to the opening level.
• The longer the upper shadow, the more effective the bearish signal. It tells us that the bears are strong enough to conquer the bulls who once drove the price so high.
C. How do we trade it?
• Look for the Gravestone Doji at the top of an uptrend.
• Wait for the next candle to close below the low of the Gravestone Doji to confirm the existence of bearish force.
• Open a short position upon confirmation.
• Place a stop-loss above the high of the Gravestone Doji.
#patterns#fibonacciacademy
@fibonaccisyndicate
📈 Bullish pattern - Tweezer bottom.
A. How to recognise it?
• There must be a preceding downtrend.
• A red candle followed by a green candle.
• Both candles have the same low.
B. What is the psychology behind?
• The candles in both sessions form the same low, suggesting that the market refuses to go below that price level. Once the price touches the floor, it bounces back. That price level may be viewed as a short-term support.
• The closing price of the green candle shies away from the low further than the red candle does. It shows that the bullish forces are getting stronger.
C. How do we trade it?
• Look for the Tweezer Bottom at the bottom of a downtrend.
• Wait for the next candle to close above the high of the two candles to confirm the existence of bullish force.
• Open a long position upon confirmation.
• Place a stop-loss below the low of the two candles.
#patterns#fibonacciacademy
📉Bearish Pattern - Dark Cloud Cover.
A. How to recognise it?
• There must be a preceding uptrend.
• A green candle followed by a red candle.
• The red candle opens with a gap-up and closes at 50% or below of the real body of green candle.
B. What is the psychology behind?
• The green candle implies the control of the bulls following a prolonged uptrend.
• In next session, the market opens above the high of the green candle, suggesting continuation of the bullish forces.
• The bulls then lose momentum, the bears conquer and send the price down during the session, and eventually manage to wipe out 50% gains or more from the previous session.
C. How do we trade it?
• Look for the Dark Cloud Cover at the top of an uptrend.
• Wait for the next candle to close below the low of the red candle to confirm the existence of bearish force.
• Open a short position upon confirmation.
• Place a stop-loss above the high of the red candle.
#patterns#fibonacciacademy#trading
📈Bullish Pattern - Three White Soldiers.
A. How to recognise it?
• There must be a preceding downtrend.
• Three consecutive long green candles observed.
• The second and third candle opens within the body of the preceding one but closes higher than the preceding one.
B. What is the psychology behind?
•The first long green candle signals that the bears are exhausted after the prolonged downtrend and the bulls start to take over. The bulls continue the rally with the subsequent two candles closing higher.
C. How do we trade it?
• Look for the Three White Soldiers at the bottom of a downtrend.
•Wait for the fourth candle to close above the high of the third candle to confirm the reversal.
• Open a long position upon confirmation.
• Place a stop-loss below the low of the first green candle.
#patterns
#fibonacciacademy
#bullish
@fibonaccisyndicate.
📉 Bearish Pattern - Shooting Star.
How to recognise it?
• There must be a preceding uptrend.
• It looks like a flying meteor carrying a long tail.
• The closing price is below or near the opening price, forming a tiny body.
• The real body could be green or red.
• It has no or little lower shadow.
• The upper shadow is at least twice of the length of the real body.
What is the psychology behind?
• Similarly to Gravestone Doji, when the market opens, the bulls continuously push the price up during the session, resulting in a long upper shadow.
• The bears fight strongly and conquer the bulls by dragging the price below or near the opening level, forming a little square body.
• The longer the upper shadow, the more effective the bearish signal. It tells us that the bears are strong enough to conquer the bulls who once drove the price so high.
How do we trade it?
• Look for the Shooting Star at the top of an uptrend.
• Wait for the next candle to close below the low of the Shooting Star to confirm the existence of bearish force.
• Open a short position upon confirmation.
• Place a stop-loss above the high of the Shooting Star.
#patterns#fibonacciacademy#cryptocurrency
📈Bullish Pattern - PIERCING
A. How to recognise it?
• There must be a preceding downtrend.
• A red candle followed by a green candle.
• The green candle opens with a gap-down and closes at 50% or above of the real body of red candle.
B. What is the psychology behind?
• The red candle implies the control of the bears following a prolonged downtrend.
• In next session, the market opens below the low of the red candle, suggesting continuation of the bearish forces.
• The bears then lose momentum, the bulls conquer and lead the price up during the session, and eventually manage to cover 50% losses or more from the previous session.
C. How do we trade it?
• Look for the Piercing at the bottom of a downtrend.
• Wait for the next candle to close above the high of the green candle to confirm the existence of bullish force.
• Open a long position upon confirmation.
• Place a stop-loss below the low of the green candle.
#patterns#bullish#trading#fibonacciacademy
@fibonaccisyndicate
📈Bullish Pattern - HAMMER🔨
A. How to recognise it?
• There must be a preceding downtrend
• It looks like a square lollipop with a long stick.
• The closing price is above or near the opening price, forming a tiny body.
• The real body could be green or red. It has no or little upper shadow.
• The lower shadow is at least twice of the length of the real body.
B. What is the psychology behind?
• Similarly to Dragonfly Doji, when the market opens, the bears continuously drag the price down during the session, resulting in a long lower shadow.
• The bulls fight strongly and conquer the bears by pushing the price above or near the opening level, forming a little square body.
• The longer the lower shadow, the more effective the bullish signal. It tells us that the bulls are strong enough to conquer the bears who once dragged the price so low.
C. How do we trade it?
• Look for the Hammer at the bottom of a downtrend.
• Wait for the next candle to close above the high of the Hammer to confirm the existence of bullish force.
• Open a long position upon confirmation.
• Place a stop-loss below the low of the Hammer.
#patterns#bullish#trading#fibonacciacademy
@fibonaccisyndicate
📈Bullish Pattern - Dragonfly Doji
A. How to recognise it?
•There must be a preceding downtrend.
• It looks like a T letter.
• The opening, highest and closing price are same.
• It has no real body but a long lower shadow.
B. What is the psychology behind?
• When the market opens, the bears drag the price all the way down, resulting in a long lower shadow. • The bulls fight strongly and eventually manage to push the price back up to the opening level. • The longer the lower shadow, the more effective the bullish signal. It tells us that the bulls are strong enough to conquer the bears who once dragged the price so low.
C. How do we trade it?
• Look for the Dragonfly Doji at the bottom of a downtrend. • Wait for the next candle to close above the high of the Dragonfly Doji to confirm the existence of bullish force. • Open a long position upon confirmation. • Place a stop-loss below the low of the Dragonfly Doji.
#patterns
#fibonacciacademy
#bullish
#trading
@fibonaccisyndicate
What is a Japanese Candlestick?
• A tool to depict the price movement during the given time period.
What is a Japanese Candlestick Pattern (JCP)?
· A candlestick graphic that is formed by the movement of market price and contains strong predictive power of short-term market direction.
How is a Japanese Candlestick formed?
• By using the opening price, closing price, highest price and lowest price of the given time period.
What are the two types of candlestick?
• Bullish candle and Bearish candle. Bullish candle is formed when the closing price is above the opening price. Bearish candle is formed when the closing price is below the opening price.
How to interpret a bullish and a bearish candle?
• A bullish candle indicates buying pressure while a bearish candle selling pressure.
What is the difference between a long and a short candle?
· A long candle signifies high market volatility and a short candle low market volatility.
What are the advantages of JCPS?
• Contain unprocessed and raw data about the market sentiment.
• Provide unique insights on the relationship between the buyers and sellers.
• Give early signals of potential market turns.
#patterns#fibonacciacademy#trading#cryptocurrency
@fibonaccisyndicate
📈PATTERNS📉
Let's take a look on each pattern, how we can recognize them and how to work with them.
There are bulls and bears in the market, and in order to understand which pattern we need to work with, we need to find these patterns on the chart (1H +) and work with them.
📈Bullish patterns:
- Dragonfly Doji
- Hammer
- Bullish Engulfing
- Piercing
- Tweezer Bottom
- Three White Soldiers
- Morning Star
📉Bearish patterns:
- Gravestone Doji
- Shooting Star
- Bearish Endulfing
- Dark Cloud Cover
- Tweezer Top
- Three Black Crows
- Evening Star
#pattern#fibonacciacademy#bullish#trading