# Cryfi API

Cryfi API allows any trading automation strategy to share signals automatically. If you want to connect your trading bot to Cryfi you need to:\
\
1\) If you channel/group is paid - Create a private Channel, if free - Create a public channel

2\) Add [<mark style="color:blue;">**@CryfiBot**</mark>](https://t.me/CryfiBot) to the channel (you can press « <mark style="color:purple;">start</mark> » —> « <mark style="color:purple;">I’m a signal provider</mark> » on [<mark style="color:blue;">**@CryfiBot**</mark>](https://t.me/CryfiBot) and it will guide you through this step or check our [step-by-step guide](/cryfi/overview/how-cryfi-works/for-signal-providers-create-and-share-signals.md))

3\) If your channel is paid - You should setup your subscription price, wallet address & free trial period on the app (<mark style="color:orange;">/app</mark> command on [<mark style="color:blue;">**@CryfiBot**</mark>](https://t.me/CryfiBot))

4\) Then we’ll need to properly identify you in the backend so we’ll need to know the quoted data given by the <mark style="color:orange;">/init\_data</mark> command on [<mark style="color:blue;">**@CryfiBot**</mark>](https://t.me/CryfiBot)

5\) Integrate our API:

```
import requests

def assert_response_success(response, url):
	if response.status_code != 200:
		print(f"[-] An error occurred while reaching {url}")
		print(response)
		print(response.text)
		exit()

"""
Returns the list of pairs listed on Cryfi
These are all the binance future pairs

Response format:
[{
	'symbol': 'BTCUSDT',
	'base_asset': 'BTC',
	'quote_asset': 'USDT',
	'leverages': [125, 100, 50, 20, 10, 5, 4, 3, 2, 1] # The maximum of this list is the maximum allowed leverage
}]
"""
def get_pairs():
	url = "https://api.cryfi.app/api/pairs/getPairs"
	response = requests.get(url)
	assert_response_success(response, url)
	return response.json()

pairs = get_pairs()
print(f"[+] {len(pairs)} pairs available")

def create_signal(pair_symbol, leverage, portfolio_size, sl, sl_size, entries, entries_size, targets, targets_size, description, screenshot = None):
	# The length of the positions should equal the length of the sizes
	assert len(sl) == len(sl_size) and len(entries) == len(entries_size) and len(targets) == len(targets_size)
	# The sizes should add up to 100%
	assert sum(sl_size) == 100 and sum(entries_size) == 100 and sum(targets_size) == 100
	# The pair_symbol should be in the result of get_pairs()
	pair = next((pair for pair in pairs if pair["symbol"] == pair_symbol), None)
	assert pair
	# The leverage should not be more than the maximum allowed
	assert leverage <= max(pair["leverages"])

	json_data = {
		# To get your init_data send the /init_data command to the Cryfi Telegram Bot (https://t.me/CryfiBot)
		"init_data": "<your init_data goes here>",
		"signal": {
			"pair": pair_symbol,
			"leverage": leverage,
			"portfolio_size": portfolio_size,
			"sl": sl,
			"sl_size": sl_size,
			"entries": entries,
			"entries_size": entries_size,
			"targets": targets,
			"targets_size": targets_size,
			"description": description,
			"screenshot": screenshot,
		},
	}
	url = "https://telegram.cryfi.app/create-signal"
	response = requests.post(url, json=json_data)
	assert_response_success(response, url)
	print(f"[+] {response.json()['message']}")


pair_symbol = "ETHUSDT"
leverage = 5
portfolio_size = 10 # Optional position size of portfolio (here 10 is 10%). If not specified, default value is 100%
sl = [3050] # Prices of the stop losses
sl_size = [100] # Position size of each stop loss in %
entries = [3100, 3150] # Prices of the entries
entries_size = [50, 50] # Position size of each entry in %
targets = [3200, 3250] # Prices of the targets
targets_size = [35, 65] # Position size of each targets in %
description = "This signal makes sense because..." # Optional signal description
screenshot = "https://www.tradingview.com/x/9ql06UmW/" # Optional image URL

create_signal(pair_symbol, leverage, portfolio_size, sl, sl_size, entries, entries_size, targets, targets_size, description, screenshot)
```

6\) If you have any troubles with the integration or want to ask questions feel free to tag the Admin in the [Cryfi Chat](https://t.me/cryfi_official) or write in the chat about your desire to integrate Cryfi API. Our team members will contact you shortly.


---

# 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://cryfi.gitbook.io/cryfi/overview/cryfi-api.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.
