> For the complete documentation index, see [llms.txt](https://docs.symm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.symm.io/trader-documentation/building-a-trading-bot-1/monitoring-price.md). Agents can also search and read this documentation through its [MCP server](https://docs.symm.io/~gitbook/mcp).

# Monitoring Price

The sample trading bot makes decisions based on price movements. Because the asset being traded is hedged with Binance it's appropriate to monitor the price using their endpoints. In our sample, we are executing a basic strategy: longing when price is below or equal to our defined `ENTRY_PRICE` and closing our position when the price is equal or above our `EXIT_PRICE`.

#### Setting Up Price Monitoring

We define entry and exit prices in the configuration:

```python
CONFIG = {
    "SYMBOL": "XRPUSDT",
    "ENTRY_PRICE": "3.05",  # Enter when price falls below this
    "EXIT_PRICE": "3.1",    # Exit when price rises above this
    "QUANTITY": "6",
    # ... other configuration options
}
```

#### Monitoring Loop

The bot continuously monitors the price and compares it to our thresholds:

```python
# Main trading loop
while True:
    # Get current price from Binance
    current_price = get_binance_price(CONFIG["SYMBOL"])
    
    # Check for entry conditions
    if not in_position and current_price <= entry_price:
        # Open a position
        
    # Check for exit conditions
    elif in_position and current_price >= exit_price:
        # Close the position
    
    time.sleep(CONFIG["POLL_INTERVAL"])
```

The `get_binance_price` function fetches the current price from Binance's API:

```python
def get_binance_price(symbol):
    """Get the current price of a symbol from Binance."""
    try:
        params = {"symbol": symbol}
        response = requests.get(BINANCE_API_URL, params=params)
        response.raise_for_status()
        data = response.json()
        price = Decimal(data["price"])
        print(f"[PRICE] Current {symbol} price: {price}")
        return price
    except Exception as e:
        print(f"[ERROR] Failed to get Binance price: {e}")
        return None
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.symm.io/trader-documentation/building-a-trading-bot-1/monitoring-price.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
