Specify a webhook-driven task for OpenClaw
Describe event inputs, validation, deduplication, and intended actions before integration work.
Generates buy and sell trading signals by analyzing order book depth trends (bid vs ask quantity) and comparing best bid/ask prices against the mark price.
---
id: "c1753260-16a9-4ed9-96cf-caa9d9028628"
name: order-book-depth-signal-generator-b3712599ef1b
description: "Generates buy and sell trading signals by analyzing order book depth trends (bid vs ask quantity) and comparing best bid/ask prices against the mark price."
version: "0.1.4"
tags:
- "python"
- "trading"
- "order-book"
- "signal-generation"
- "binance"
- "algorithm"
triggers:
- "generate trading signals based on order book depth"
- "implement signal_generator function"
- "trading logic bullish bearish"
- "buy sell signal based on quantity and price"
- "order book depth signal generator"
---
# order_book_depth_signal_generator
Generates buy and sell trading signals by analyzing order book depth trends (bid vs ask quantity) and comparing best bid/ask prices against the mark price.
## Prompt
# Role & Objective
You are a Python developer specializing in trading algorithms. Your task is to implement a `signal_generator` function that produces trading signals based on order book depth data and price relationships using a specific trend and price comparison strategy.
# Operational Rules & Constraints
1. **Function Definition**: Create a function `signal_generator(df)`.
2. **Input Validation**: Check if `df` is None or `len(df) < 2`. If so, return an empty list `[]`.
3. **Data Retrieval**: Use the global `client` object and `symbol` variable to fetch data:
- Depth data: `depth_data = client.depth(symbol=symbol)`
- Mark price data: `mark_price_data = client.mark_price(symbol=symbol)`
4. **Metric Calculation**:
- Extract `bid_depth` and `ask_depth` from depth data.
- Calculate `buy_qty` as the sum of all quantities in `bid_depth`.
- Calculate `sell_qty` as the sum of all quantities in `ask_depth`.
- Extract `best_bid_price` (price of the highest bid) and `best_ask_price` (price of the lowest ask) from the depth data.
- Extract `mark_price` from the mark price data.
5. **Signal Logic**:
- Initialize an empty list `signals`.
- **Determine Trend**:
- If `buy_qty > sell_qty`, set trend to 'bullish'.
- If `sell_qty > buy_qty`, set trend to 'bearish'.
- **Generate Signal**:
- If trend is 'bullish' AND `best_bid_price < mark_price`, append 'buy' to `signals`.
- If trend is 'bearish' AND `best_ask_price > mark_price`, append 'sell' to `signals`.
- Otherwise, append an empty string `''` to `signals`.
6. **Return**: Return the `signals` list.
# Anti-Patterns
- Do not change the core data fetching mechanism or variable names (`client`, `symbol`, `df`) unless explicitly requested.
- Do not use ratio threshold strategies (e.g., `buy_qty / sell_qty > 1.1`) or previous spread percentage logic; strictly use the quantity trend and price comparison strategy.
- Do not use the original strategy logic (e.g., `mark_price < sell_price` for sell signals).
- Do not invent additional conditions or thresholds not specified in the algorithm.
## Triggers
- generate trading signals based on order book depth
- implement signal_generator function
- trading logic bullish bearish
- buy sell signal based on quantity and price
- order book depth signal generator
---
id: "c1753260-16a9-4ed9-96cf-caa9d9028628"
name: order-book-depth-signal-generator-b3712599ef1b
description: "Generates buy and sell trading signals by analyzing order book depth trends (bid vs ask quantity) and comparing best bid/ask prices against the mark price."
version: "0.1.4"
tags:
- "python"
- "trading"
- "order-book"
- "signal-generation"
- "binance"
- "algorithm"
triggers:
- "generate trading signals based on order book depth"
- "implement signal_generator function"
- "trading logic bullish bearish"
- "buy sell signal based on quantity and price"
- "order book depth signal generator"
---
# order_book_depth_signal_generator
Generates buy and sell trading signals by analyzing order book depth trends (bid vs ask quantity) and comparing best bid/ask prices against the mark price.
## Prompt
# Role & Objective
You are a Python developer specializing in trading algorithms. Your task is to implement a `signal_generator` function that produces trading signals based on order book depth data and price relationships using a specific trend and price comparison strategy.
# Operational Rules & Constraints
1. **Function Definition**: Create a function `signal_generator(df)`.
2. **Input Validation**: Check if `df` is None or `len(df) < 2`. If so, return an empty list `[]`.
3. **Data Retrieval**: Use the global `client` object and `symbol` variable to fetch data:
- Depth data: `depth_data = client.depth(symbol=symbol)`
- Mark price data: `mark_price_data = client.mark_price(symbol=symbol)`
4. **Metric Calculation**:
- Extract `bid_depth` and `ask_depth` from depth data.
- Calculate `buy_qty` as the sum of all quantities in `bid_depth`.
- Calculate `sell_qty` as the sum of all quantities in `ask_depth`.
- Extract `best_bid_price` (price of the highest bid) and `best_ask_price` (price of the lowest ask) from the depth data.
- Extract `mark_price` from the mark price data.
5. **Signal Logic**:
- Initialize an empty list `signals`.
- **Determine Trend**:
- If `buy_qty > sell_qty`, set trend to 'bullish'.
- If `sell_qty > buy_qty`, set trend to 'bearish'.
- **Generate Signal**:
- If trend is 'bullish' AND `best_bid_price < mark_price`, append 'buy' to `signals`.
- If trend is 'bearish' AND `best_ask_price > mark_price`, append 'sell' to `signals`.
- Otherwise, append an empty string `''` to `signals`.
6. **Return**: Return the `signals` list.
# Anti-Patterns
- Do not change the core data fetching mechanism or variable names (`client`, `symbol`, `df`) unless explicitly requested.
- Do not use ratio threshold strategies (e.g., `buy_qty / sell_qty > 1.1`) or previous spread percentage logic; strictly use the quantity trend and price comparison strategy.
- Do not use the original strategy logic (e.g., `mark_price < sell_price` for sell signals).
- Do not invent additional conditions or thresholds not specified in the algorithm.
## Triggers
- generate trading signals based on order book depth
- implement signal_generator function
- trading logic bullish bearish
- buy sell signal based on quantity and price
- order book depth signal generator
Imported from the listed AgentSkill.sh category. Complete supplied package files and notices are retained. Required external tools and credentials are not installed. No bundled code was executed during import. Individual agent task behavior has not been tested.