Trading bots execute transactions 24/7, but what if you need to restrict when they can operate? TIME_RESTRICTION policies in WAIaaS let you set specific hours when your automated trading strategies can execute transactions, giving you control over when your bot is active in the markets.
Why Trading Hours Matter
Market conditions change dramatically across time zones and sessions. Your DeFi arbitrage bot might perform well during high-volume hours but struggle during low-liquidity periods. MEV opportunities cluster around specific times. Gas prices fluctuate predictably throughout the day.
Without time controls, your bot burns gas on suboptimal trades during dead hours, potentially erasing profits from peak trading periods. TIME_RESTRICTION policies solve this by enforcing trading windows at the wallet level — your bot can't accidentally execute during blackout periods, even if your strategy logic has bugs.
How TIME_RESTRICTION Policies Work
TIME_RESTRICTION policies use a simple hour-based schedule with timezone support. When a transaction falls outside allowed hours, WAIaaS denies it before hitting the blockchain, saving you gas on rejected trades.
The policy enforces a daily window using start/end hours (0-23) in your specified timezone. Your bot's session tokens remain valid, but transaction requests outside the window get blocked with a clear error message.
Setting Up Trading Hours
Create a TIME_RESTRICTION policy using the master password (system admin level):
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
"type": "TIME_RESTRICTION",
"rules": {
"allowedHours": {
"start": 9,
"end": 17
},
"timezone": "UTC"
}
}'
This restricts trading to 9 AM - 5 PM UTC. During off-hours, any transaction from your bot gets this response:
{
"error": {
"code": "POLICY_DENIED",
"message": "Transaction denied by TIME_RESTRICTION policy",
"domain": "POLICY",
"retryable": false
}
}
Multi-Timezone Trading Strategies
For global arbitrage bots, you might want different schedules for different wallets:
# Asian markets wallet (JST timezone)
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "asian-markets-wallet-id",
"type": "TIME_RESTRICTION",
"rules": {
"allowedHours": {"start": 8, "end": 16},
"timezone": "Asia/Tokyo"
}
}'
# US markets wallet (EST timezone)
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "us-markets-wallet-id",
"type": "TIME_RESTRICTION",
"rules": {
"allowedHours": {"start": 9, "end": 16},
"timezone": "America/New_York"
}
}'
Your bot can hold sessions for multiple wallets and route trades to the appropriate one based on the current time and market conditions.
Combining with Gas Conditional Execution
TIME_RESTRICTION works seamlessly with WAIaaS's gas conditional execution. Your bot can specify both time windows and gas price thresholds:
# Execute Jupiter swap only during allowed hours AND when gas is reasonable
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wai_sess_<token>" \
-d '{
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"amount": "1000000000",
"gasCondition": {
"maxGasPrice": "0.000005",
"timeout": 300
}
}'
The transaction waits for both conditions: current time in allowed window AND gas price below threshold.
Bot Implementation Patterns
Pattern 1: Fail Fast
Let TIME_RESTRICTION policies block off-hours transactions immediately:
import { WAIaaSClient, WAIaaSError } from '@waiaas/sdk';
const client = new WAIaaSClient({
baseUrl: 'http://127.0.0.1:3100',
sessionToken: process.env.WAIAAS_SESSION_TOKEN,
});
try {
const tx = await client.executeAction('jupiter-swap', 'swap', {
inputMint: 'So11111111111111111111111111111111111111112',
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
amount: '1000000000'
});
console.log(`Swap executed: ${tx.id}`);
} catch (error) {
if (error instanceof WAIaaSError && error.code === 'POLICY_DENIED') {
console.log('Outside trading hours, skipping opportunity');
return;
}
throw error;
}
Pattern 2: Queue for Trading Hours
Cache opportunities and execute when the window opens:
interface PendingTrade {
action: string;
params: any;
discoveredAt: number;
maxAge: number;
}
class TradingBot {
private pendingTrades: PendingTrade[] = [];
async executeTradesInWindow() {
const now = Date.now();
const validTrades = this.pendingTrades.filter(
trade => now - trade.discoveredAt < trade.maxAge
);
for (const trade of validTrades) {
try {
const tx = await client.executeAction(trade.action, 'swap', trade.params);
console.log(`Queued trade executed: ${tx.id}`);
} catch (error) {
if (error.code === 'POLICY_DENIED') {
console.log('Still outside trading hours');
break; // Stop trying, wait for next cycle
}
}
}
this.pendingTrades = this.pendingTrades.filter(
trade => now - trade.discoveredAt < trade.maxAge
);
}
}
Advanced: Dynamic Trading Hours
For strategies that need to adapt to market conditions, you can update TIME_RESTRICTION policies programmatically:
# Extend trading hours during high volatility
curl -X PUT http://localhost:3100/v1/policies/<policy-id> \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"rules": {
"allowedHours": {"start": 6, "end": 20},
"timezone": "UTC"
}
}'
Your bot can monitor volatility indicators and request trading hour extensions during major market events.
Integration with Other Policies
TIME_RESTRICTION works alongside WAIaaS's 21 policy types. Common combinations for trading bots:
- SPENDING_LIMIT: Limit trade sizes during specific hours
- RATE_LIMIT: Reduce transaction frequency during low-volume periods
- ALLOWED_TOKENS: Restrict assets during experimental hours
- LENDING_LTV_LIMIT: Tighten leverage during overnight sessions
The 4-tier security system (INSTANT/NOTIFY/DELAY/APPROVAL) still applies within allowed hours, giving you granular control over execution speed and monitoring.
Quick Start Guide
- Install WAIaaS CLI and start daemon:
npm install -g @waiaas/cli
waiaas init
waiaas start
- Create a wallet and session for your bot:
waiaas quickset --mode mainnet
- Set TIME_RESTRICTION policy for trading hours:
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: <your-password>' \
-d '{
"walletId": "<wallet-id>",
"type": "TIME_RESTRICTION",
"rules": {
"allowedHours": {"start": 9, "end": 17},
"timezone": "UTC"
}
}'
- Test with a simple transaction:
curl -X POST http://127.0.0.1:3100/v1/transactions/send \
-H "Authorization: Bearer <session-token>" \
-d '{"type": "TRANSFER", "to": "test-address", "amount": "0.001"}'
- Install the SDK and integrate with your trading logic:
npm install @waiaas/sdk
What's Next
TIME_RESTRICTION policies give you precise control over when your trading bot can execute transactions, helping optimize performance during profitable hours while preventing costly mistakes during dead periods. Combined with gas conditional execution and WAIaaS's 15 DeFi protocol integrations, you have the infrastructure to build sophisticated, risk-managed trading strategies.
Ready to add time-based controls to your trading bot? Check out the full documentation at https://waiaas.ai or explore the open-source code at https://github.com/minhoyoo-iotrust/WAIaaS.
Top comments (0)