circle-exclamation
This documentation page is currently under development and may be updated frequently.

Code Reaction

A Code Reaction lets you write custom JavaScript code that runs whenever a Data Webhook receives a request.

It works like a Code Strategy, but instead of running on market ticks or on a schedule, it executes event‑driven — triggered by incoming webhook data. The webhook’s request data is injected into your code so you can react to it, trigger trading actions, store state, and perform HTTP requests.


🧩 Request Data Object

For each webhook request, Towerflow makes the incoming request available inside your reaction as a Request object:

Field
Description

$.Request.ip

Sender’s IP address (if available)

$.Request.headers

All incoming HTTP headers

$.Request.data

Full payload as a string

You can parse $.Request.data into JSON if needed:

const payload = JSON.parse($.Request.data);

circle-info

Code Reactions share the same execution environment and capabilities as Code Strategies, extended with the $.Request object.


🧠 Example Code Reaction

Here’s a sample that reacts to incoming webhook data and triggers trades:

// Parse the incoming payload
const payload = JSON.parse($.Request.data);

// Load persistent state
const state = await $.Storage.get() || { triggers: 0 };
state.triggers++;

// Logic based on external signal
if (payload.signal === "BUY" && payload.confidence > 0.8) {
    await $.Strategy.action($.Action.LONG);
} else if (payload.signal === "SELL") {
    await $.Strategy.action($.Action.EXIT);
}

// Save state
await $.Storage.set(state);

This shows:

  • Parsing $.Request.data

  • Using persistent storage

  • Applying custom logic

  • Triggering trading actions


🔍 Typical Use Cases

Code Reactions are ideal for:

  • Validating and normalizing external webhook data

  • Filtering incoming signals before acting

  • Coordinating multiple webhook sources

  • Building safety layers for automated bots

  • Custom preprocessing for downstream logic


🚫 Limitations

  • No chart or image input

  • No AI reasoning

  • One execution per webhook event

  • Deterministic output only



🧠 Summary

Code Reactions extend the flexibility of Code Strategies into the event‑driven world. They let you run custom JavaScript logic whenever external systems send data — enabling highly customizable automated workflows with full control over data, state, and trade actions.

Last updated