Creating a webhook query
Learn how to create Psyll webhook queries for trading automation. This chapter explains the structure of queries, types of actions, and provides examples of their practical use.
Learn how to create Psyll webhook queries for trading automation. This chapter explains the structure of queries, types of actions, and provides examples of their practical use.
Automate trades and trigger actions by connecting external alerts through fully customizable webhooks.
Webhooks are an extremely flexible and powerful tool for automating trading on the Psyll platform, enabling fast and precise order placement on the exchange using standard HTTP POST requests. This method allows for integration with external systems, such as TradingView, and the creation of fully automated trading strategies.
In this chapter, we will delve into how to construct requests, the types of actions available, and also provide practical examples of usage, potential limitations, and error scenarios.
Each request to a Psyll webhook must be formatted as a JSON object and contain three fundamental fields:
BUY
, SELL
, SET
.BTCUSDC
, ETHBTC
).Example request:
"action": "BUY",
"quantity": 0.0021,
"symbol": "BTCUSDC"
This request instructs the Psyll platform to place a buy order for 0.0021 BTC
on the BTC/USDC
pair.
After receiving a query with the action set to BUY, the system immediately places a buy order for the specified trading pair on the exchange linked to the user's account. The order will be executed provided there is sufficient capital available in the account. In the case of insufficient funds, the exchange may reject the order or execute it partially. Webhooks place market orders, which are executed at the current best price available on the exchange.
We recommend monitoring the order status in the webhook's return response, which contains details about the order (e.g., order ID, status, quantity of units executed).
Example scenario:
We want to buy 0.5 ETH on the ETHUSDT pair.
"action": "BUY"
"quantity": 0.5"
"symbol": "ETHUSDT"
As a result of executing this webhook, a buy order for 0.5 ETH will be placed. If the user's account has enough USDT, the order will be executed immediately.
The operation is analogous to BUY, but it applies to selling assets. The system places a sell order for exactly the number of units specified in the quantity field.
Example scenario:
We want to sell 0.25 BTC on the BTCUSDT pair.
"action": "SELL"
"quantity": 0.25
"symbol": "BTCUSDT"
In response, the system will confirm that the sell order has been placed. Upon its execution, the equivalent of 0.25 BTC in USDT currency will appear in your account.
The SET action is the most advanced and allows for precise control of position size. The system first checks the current balance of a given asset and then calculates the difference between it and the value defined in quantity. Depending on the result, it automatically places a buy or sell order.
This functionality allows you to automatically maintain a position at a predetermined level without the need for manual monitoring or placing separate orders.
If the amount of an asset in your portfolio is less than what you want to sell, the exchange will reject the order.
Your current account balance is 0.023 BTC. We want to maintain a position of 0.01 BTC.
"action": "SET"
"quantity": 0.01
"symbol": "BTCUSDT
The system will automatically calculate that 0.023 - 0.01 = 0.013 BTC needs to be sold. A sell order for 0.013 BTC will be placed, and after it is executed, the account will have exactly 0.01 BTC remaining.
Your current account balance is 0.005 BTC. We want to increase the position to 0.01 BTC.
"action": "SET"
"quantity": 0.01
"symbol": "BTCUSDT"
The system will calculate that the portfolio is short 0.005 BTC (0.01 - 0.005 = 0.005 BTC). A buy order for 0.005 BTC will be placed to bring the balance up to 0.01 BTC.
Webhooks are very flexible, but due to the dynamic nature of the market and different exchange conditions, it's always good to:
The Psyll platform allows for easy integration with TradingView alerts. Simply configure an alert on the TradingView platform and include the appropriate JSON object, which corresponds to the webhook structure, in its message.
This process enables the entire strategy to operate fully automatically, without the need for manual intervention, even in the most volatile market conditions.
More information on the format and interpretation of responses returned by the webhook can be found in our "TradingView alert integration" documentation.
Psyll supports direct integration with your own strategies created in the Pine Script language in TradingView. This makes it possible for signals generated by the strategy - both for opening and closing positions - to be automatically transmitted to Psyll in the form of webhook requests. This allows you to create a fully autonomous trading system that operates 24/7, reacting to signals in real time.
In practice, the integration process involves adding special conditions to the strategy code that generate notifications when specific market criteria are met. Each alert is assigned content in a JSON format compliant with Psyll's requirements (e.g., containing the fields action, quantity, and symbol) and the platform's webhook address. After publishing the strategy on TradingView and enabling alerts, every time a condition in the strategy is met, it automatically results in an HTTP POST request being sent to Psyll, which triggers the appropriate action on the exchange.
Thanks to this integration, you can:
All official repositories, client libraries, supporting tools, and supplementary materials are published on our GitHub profile: https://github.com/psyll. There, you'll find not only the source code but also project documentation, installation instructions, deployment examples, and additional resources for developers.
The repositories are constantly updated and developed to provide users with the latest features and security patches. Each project is released under an open license, so you can freely modify and adapt it to your needs. In the "Issues" section, you can also report bugs, propose new features, or discuss with other developers.
GitHub is the ideal place to start working with Psyll at the code level, track changes in our libraries, and draw inspiration from examples prepared by the community. This allows you to develop your projects faster and fully leverage the possibilities of integration with the Psyll platform.