# Functions

## `signal(ex, pair)`

This function must return `None`, `False`, or `True`.

* `ex`
  * Exchange
* `pair`
  * Name of the pair being traded

### Return

1. Return `None` if the symbol is not handled by the script. If all scripts return `None` for the symbol then it will trade based on your settings.
2. Return `False` if the signal is not present.
3. Return `True` if the signal is present. This will allow the bot to place trades based on your settings.

## `update(ex, pair, last, avg, size, target)`

Since `v1.2.2`, this function can be used to force the bot to exit its current position and start over.

* `ex`
  * Exchange
* `pair`
  * Name of the pair being traded
* `last`
  * Last price of the pair
* `avg`
  * Average price of all entries
* `size`
  * Current position size
* `target`
  * Current target price

### Return

1. Return `True` to stay in the position.
2. Return `False` (or anything else) to exit the position.

This function should return `True` by default if you just want status updates sent to Python.

## `finished()`

This function is called when the bot is exiting. Depending on how the bot is closed, it may not be called.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://crypto.phbot.org/python/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
