> For the complete documentation index, see [llms.txt](https://magpys-organization.gitbook.io/magpy_v0.1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://magpys-organization.gitbook.io/magpy_v0.1/product/triggers.md).

# Triggers

Triggers are events that activate you Bot and set them in motion.

<figure><img src="https://539303172-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fpr8Os5MDdNLGB70OkMne%2Fuploads%2FeMU2F1n1v0nLRyqvMn3O%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202023-04-14%200.29.26.png?alt=media&amp;token=3e10f8a1-48e8-45df-8f1e-6b4bc1ca3aba" alt=""><figcaption></figcaption></figure>

<figure><img src="https://539303172-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fpr8Os5MDdNLGB70OkMne%2Fuploads%2FjdBzYCIwynAGqBpjI5Gk%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202023-04-24%2014.37.38.png?alt=media&amp;token=52268e7c-af02-4bed-a5ac-a7270fa24765" alt=""><figcaption></figcaption></figure>

First, the user selects an exchange to obtain market data that will trigger the bot. Then, they choose the type of trigger, asset pair, and relationship (price greater than, less than, equal to, etc.). Finally, they set the gas fee that can be used by this bot.&#x20;

This settings screen will be used until it is replaced by a prompt in the future.

## Some Examples:

* Price of an asset crosses a certain value
* Price of an asset moves by a certain percentage in any direction
* TVL crosses a certain value
* The MarketCap of an asset moves by a certain value
* 100-200 EMA Crossover on 4h timeframe, and many more technical analysis triggers

## <mark style="color:purple;">🤖 DEX/AMM</mark>

The following triggers can be used in DEX/AMM. Please check the development status as well. For more details, please contact the team.

<table><thead><tr><th width="166">Function Name</th><th width="200">Category<select><option value="bf58fd22f9bd4fbe82eac1c6b54831d7" label="Market Data" color="blue"></option><option value="2b25c123c8ea467e9f4dafc5d3585bb5" label="Periodic Execution" color="blue"></option><option value="766515807a254ade890f98817a6329f1" label="Account Data" color="blue"></option><option value="21cc25c3d3104f6883f7c8fe537a46e5" label="Position Data" color="blue"></option><option value="90431929796049bcb267b50519734747" label="Math Function" color="blue"></option><option value="9bc7cf671593476095fab7a2bd5ff53e" label="Others" color="blue"></option></select></th><th width="269">Variable</th><th width="271">Explanation</th><th width="296">Example</th><th>Availability<select><option value="fa1d8145006748dcbb74e44d0a05f281" label="⭕️" color="blue"></option><option value="4c1ddf75a87c40ff9e2d4594ebbfbb91" label="❌" color="blue"></option><option value="57245ade3daa4e3794ef9d12e58e8edc" label="🛠" color="blue"></option></select></th></tr></thead><tbody><tr><td>period_exc()</td><td><span data-option="2b25c123c8ea467e9f4dafc5d3585bb5">Periodic Execution</span></td><td>period, unit, n</td><td>Triggers to be executed periodically</td><td>period_exc(1,hour,2) means buy btc 2 times per hour</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName, minutes(optional)</td><td>Takes a market name as an argument and returns the final price of the asset. When user input n, it returns the price n minute before the asset.</td><td>price("ETH/USD",7) returns the price 7 minute before ETH/USD.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>last_trade_price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the last traded price of the asset.</td><td>last_trade_price("LINKBULL/USD") Returns the last trade price for that asset.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>free_collateral</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the amount of collateral not required in U.S. dollars in the Wallet.</td><td>free_collateral>500. This rule is triggered when the collateral-free amount in the wallet exceeds $500.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>total_position_size</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the total account position size (in USD) for all futures.</td><td>total_position_size&#x3C;2*total_collateral This rule is triggered when the total position is less than twice the collateral in the account.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Returns the size of the asset position. Returns a positive value or 0.</td><td>position("BTC-USDC") returns the size of the BTC position in spot.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position_side()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Returns 1 if the position is long, -1 if the position is short, or 0 if the position is neither.</td><td>position_side("ETH-USDC")Returns 1 if ETH bought.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>abs()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric value as an argument and returns its absolute value.</td><td>In the case of abs(-2), 2 is returned.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>max()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x,y</td><td>The two numbers are taken as arguments and return the greater of x and y.</td><td>max(3.2, 10) returns 10</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>min()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x,y</td><td>The two numbers are taken as arguments and return the smaller of x and y.</td><td>min(1, 5), 1 is returned.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>sqrt()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a positive number and returns its square root.</td><td>sqrt(25) returns 5.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>floor()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric argument and returns the largest integer less than or equal to x.</td><td>floor(2.5) returns 2.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>ceil()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric argument and returns the smallest integer greater than or equal to x.</td><td>ceil(2.5) returns 3.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>sign()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>It takes a numeric argument and returns 1 for positive values and 0 for negative values.</td><td>sign(10) returns 1 and sign(-5) returns 0.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>get_variable()</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>name</td><td>It takes a variable name as an argument and returns the value stored in this variable.</td><td>When you store 10 in the variable named myVariable. In that case, get_variable('myVariable') returns 10.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>time</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns the current UNIX time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>minute</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns only the minute of the current time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>hour</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns only the current Universal Standard Time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr></tbody></table>

## <mark style="color:purple;">🤖 Perpetual DEX</mark>

<table><thead><tr><th width="166">Function Name</th><th width="200">Category<select><option value="bf58fd22f9bd4fbe82eac1c6b54831d7" label="Market Data" color="blue"></option><option value="2b25c123c8ea467e9f4dafc5d3585bb5" label="Periodic Execution" color="blue"></option><option value="766515807a254ade890f98817a6329f1" label="Account Data" color="blue"></option><option value="21cc25c3d3104f6883f7c8fe537a46e5" label="Position Data" color="blue"></option><option value="90431929796049bcb267b50519734747" label="Math Function" color="blue"></option><option value="9bc7cf671593476095fab7a2bd5ff53e" label="Others" color="blue"></option></select></th><th width="269">Variable</th><th width="271">Explanation</th><th width="296">Example</th><th>Availability<select><option value="fa1d8145006748dcbb74e44d0a05f281" label="⭕️" color="blue"></option><option value="4c1ddf75a87c40ff9e2d4594ebbfbb91" label="❌" color="blue"></option><option value="57245ade3daa4e3794ef9d12e58e8edc" label="🛠" color="blue"></option></select></th></tr></thead><tbody><tr><td>period_exc()</td><td><span data-option="2b25c123c8ea467e9f4dafc5d3585bb5">Periodic Execution</span></td><td>period, unit, n</td><td>Triggers to be executed periodically</td><td>period_exc(1,hour,2) means buy btc 2 times per hour</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName, minutes(optional)</td><td>Takes a market name as an argument and returns the final price of the asset. When user input n, it returns the price n minute before the asset.</td><td>price("ETH-PERP",7) returns the price 7 minute before ETH/USD.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>bid_price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the highest bid price for the asset.</td><td>bid_price("ETH-PERP") returns the highest bid price for ETH/USD.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>offer_price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the highest offer price for the asset.</td><td>offer_price("XRP-PERP") returns the highest offer price for XRP-PERP.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>bid_volume()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the highest bid volume for the asset.</td><td>bid_price("ETH-PERP") returns the highest bid volume for ETH/USD.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>offer_volume()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the highest offer volume for the asset.</td><td>offer_price("XRP-PERP") returns the highest offer volume for XRP-PERP.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>last_trade_price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the last traded price of the asset.</td><td>last_trade_price("LINKBULL/USD") Returns the last trade price for that asset.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>index_price()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName, minutes(optional)</td><td>Returns the index price "n" minutes ago for that asset.</td><td>index_price("LINK-PERP", 33) returns the index price 33 minutes before LINK-PERP.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>premium()</td><td><span data-option="bf58fd22f9bd4fbe82eac1c6b54831d7">Market Data</span></td><td>marketName</td><td>Returns the asset's futures premium (mark price divided by index price).</td><td>premium("ETH-PERP") returns the ETH-PERP premium.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>collateral</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the total amount of collateral in U.S. dollars in the wallet.</td><td>collateral>500 This rule is triggered when the total amount of collateral in the wallet exceeds $500.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>free_collateral</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the amount of collateral not required in U.S. dollars in the Wallet.</td><td>free_collateral>500. This rule is triggered when the collateral-free amount in the wallet exceeds $500.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>total_position_size</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the total account position size (in USD) for all futures.</td><td>total_position_size&#x3C;2*total_collateral This rule is triggered when the total position is less than twice the collateral in the account.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>margin_fraction</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the account margin ratio, i.e., the ratio of the total position size in the account to the collateral.</td><td>margin_fraction>1</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>open_margin_fraction</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the margin percentage including open orders.</td><td>open_margin_fraction>1</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>leverage</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the approximate account leverage multiplier, which is the rate of collateral and total position size for the course.</td><td>leverage&#x3C;10 This rule is triggered when leverage is below 10x.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>initial_mfr</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the initial margin requirement.</td><td>-</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>Maintenance_mfr</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the account maintenance margin percentage requirement.</td><td>-</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>Liquidation_distance:</td><td><span data-option="766515807a254ade890f98817a6329f1">Account Data</span></td><td>-</td><td>Returns the approximate status of how close your account is to liquidation.</td><td>-</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName,side</td><td>Returns the size of the asset position. Returns a positive value or 0.</td><td>position("ALGO-PERP". buy") returns the size of the ALGO-PERP long.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position_side()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Returns 1 if the position is long, -1 if the position is short, or 0 if the position is neither.</td><td>position_side("ETH-PERP")Returns 1 if ETH bought.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position_net()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Returns the net size of the position. Positive for long, negative for short.</td><td>position_net("BTC-PERP") returns the net size of BTC-PERP.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position_leverage()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Returns the approximate leverage of the position.</td><td>position_leverage("EOS-PERP") returns the approximate leverage of an EOS-PERP position.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>position_notional()</td><td><span data-option="21cc25c3d3104f6883f7c8fe537a46e5">Position Data</span></td><td>marketName</td><td>Return the notional amount of the position in U.S. dollars for risk.</td><td>position_notional("ALT-PERP") returns the notional principal of the ALT-PERP position.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>abs()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric value as an argument and returns its absolute value.</td><td>In the case of abs(-2), 2 is returned.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>max()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x,y</td><td>The two numbers are taken as arguments and return the greater of x and y.</td><td>max(3.2, 10) returns 10</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>min()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x,y</td><td>The two numbers are taken as arguments and return the smaller of x and y.</td><td>min(1, 5), 1 is returned.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>sqrt()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a positive number and returns its square root.</td><td>sqrt(25) returns 5.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>floor()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric argument and returns the largest integer less than or equal to x.</td><td>floor(2.5) returns 2.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>ceil()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>Takes a numeric argument and returns the smallest integer greater than or equal to x.</td><td>ceil(2.5) returns 3.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>sign()</td><td><span data-option="90431929796049bcb267b50519734747">Math Function</span></td><td>x</td><td>It takes a numeric argument and returns 1 for positive values and 0 for negative values.</td><td>sign(10) returns 1 and sign(-5) returns 0.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>get_variable()</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>name</td><td>It takes a variable name as an argument and returns the value stored in this variable.</td><td>When you store 10 in the variable named myVariable. In that case, get_variable('myVariable') returns 10.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>perpetual()</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>coin</td><td>Takes a coin name as an argument and returns the name of the indefinite futures market associated with this coin.</td><td>Since perpetual('ETH') returns ETH-PERP, price(perpetual('ETH')) returns the price of ETH-PERP.</td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>time</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns the current UNIX time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>minute</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns only the minute of the current time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr><tr><td>hour</td><td><span data-option="9bc7cf671593476095fab7a2bd5ff53e">Others</span></td><td>Returns only the current Universal Standard Time.</td><td></td><td></td><td><span data-option="57245ade3daa4e3794ef9d12e58e8edc">🛠</span></td></tr></tbody></table>
