A Perpetual Futures Trading Bot for X10 Exchange (Extended) - Showcase for ask-starknet
This software is provided as-is, without any guarantees or warranty. By using this software, you accept all risks associated with automated trading.
- NO PROFIT GUARANTEE: This bot does NOT guarantee profits. You can and likely will lose money.
- EDUCATIONAL PURPOSE: This is a showcase/demonstration project, not production-ready trading software.
- NOT A REAL GRID BOT: This is NOT a traditional grid bot because perpetual futures platforms like Extended don't allow you to own actual tokens - you only have positions. This is better described as a perpetual futures trading bot with grid-like behavior.
- HIGH RISK: Trading perpetual futures with leverage involves substantial risk of loss.
- NO FINANCIAL ADVICE: This software does not provide financial advice. Do your own research.
- TEST FIRST: Always test with small amounts you can afford to lose.
- Works with perpetual positions, not spot trading
- You don't own the underlying assets
- Leverage amplifies both gains and losses
- Market volatility can lead to rapid losses
- The bot may not perform as expected in all market conditions
Grid Bot Extended is a perpetual futures trading bot built for the X10 Exchange (Extended) on Starknet. It implements a grid-like trading strategy on perpetual futures markets.
This project is a showcase of what can be built using ask-starknet, an AI-powered toolkit for Starknet development.
Traditional grid bots work by:
- Buying assets at lower prices
- Selling assets at higher prices
- Profiting from market oscillations
However, on perpetual futures platforms like Extended:
- You don't own actual tokens
- You only hold leveraged positions (long/short)
- The bot creates a grid of orders to open/close positions
The bot creates a neutral grid strategy designed to profit from small market variations:
- Grid Setup: Divides a price range into multiple levels (grid)
- Order Placement: Places buy and sell orders at each grid level
- Position Management: Opens long positions when price falls, short positions when price rises
- Profit Target: Aims to capture small profits from price oscillations within the grid
Strategy Modes:
- Neutral: Mixed long/short positions to profit from volatility in both directions
- Long: Bias towards long positions (bullish)
- Short: Bias towards short positions (bearish)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Grid Bot Extended β
β β
β ββββββββββββββ ββββββββββββββββ βββββββββββ β
β β API βββββββΆβ Grid Bot βββββββΆβ X10 β β
β β Server β β Manager β βExchange β β
β β (Express) β β β β API β β
β ββββββββββββββ ββββββββββββββββ βββββββββββ β
β β β β
β β ββββββββΌβββββββ β
β β β Starknet β β
β β β Integration β β
β β βββββββββββββββ β
β β β
β βββββββΌβββββββ ββββββββββββββββ β
β βAuth & β β AI Provider β β
β βRate Limit β β (Optional) β β
β ββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 18+
- npm or pnpm
- X10 Exchange account with API access
- Starknet wallet with private key
- API secret for server authentication
-
Clone the repository
git clone https://github.com/KasarLabs/grid-bot-extended.git cd grid-bot-extended -
Install dependencies
npm install # or pnpm install -
Configure environment variables
cp .env.example .env
-
Edit
.envfile with your configuration:# Required PORT=5050 API_SECRET=your_secure_random_secret_here EXTENDED_API_URL=https://api.x10.exchange EXTENDED_API_KEY=your_x10_api_key EXTENDED_PRIVATE_KEY=your_starknet_private_key STARKNET_RPC_URL=https://starknet-mainnet.public.blastapi.io # Optional NODE_ENV=development CORS_ORIGIN=*
Security Tip: Generate a strong API_SECRET using:
openssl rand -hex 32
-
Build the project
npm run build
-
Start the server
npm start
The server will start on
http://localhost:5050
All /api/* endpoints require authentication using the X-API-Secret header:
X-API-Secret: your_api_secret_from_envRate Limiting:
- General endpoints: 100 requests per 15 minutes
- Authentication attempts: 5 failed attempts per 15 minutes (brute force protection)
- Trade history: 20 requests per minute
No authentication required
GET /healthResponse:
{
"success": true,
"message": "Service is healthy",
"data": {
"status": "ok",
"uptime": 123.456,
"timestamp": "2025-11-17T12:00:00.000Z"
}
}Requires authentication
POST /api/start-grid-bot
Content-Type: application/json
X-API-Secret: your_api_secretRequest Body:
{
"gridBotTokens": [
{
"symbol": "EUR-USD",
"priceRange": {
"upperPrice": 1.163,
"lowerPrice": 1.161
},
"gridSpacing": {
"levelsMax": 4
},
"investment": 1.5,
"leverage": 10,
"strategy": "neutral"
}
]
}Configuration Fields:
| Field | Type | Required | Description |
|---|---|---|---|
symbol |
string | β | Trading pair (e.g., "EUR-USD", "BTC-USD", "ETH-USD") |
priceRange.upperPrice |
number | β | Upper bound of the grid (must be > lowerPrice) |
priceRange.lowerPrice |
number | β | Lower bound of the grid (must be > 0) |
gridSpacing.levelsMax |
number | β | Number of grid levels (1-1000) |
investment |
number | β | Investment amount per grid level in USD |
leverage |
number | β | Leverage multiplier (e.g., 10 = 10x leverage) |
strategy |
string | β | Trading strategy: "neutral" |
Strategy Types:
neutral: Balanced approach - profits from price oscillations in both directionslong: Bullish bias - more long positions, expects price to rise overall (not implemented for now)short: Bearish bias - more short positions, expects price to fall overall (not implemented for now)
Response (Success):
{
"success": true,
"message": "Grid bot manager started successfully with 1 bot(s)"
}Response (Error):
{
"success": false,
"message": "Invalid grid bot configuration",
"error": {
"code": "VALIDATION_ERROR",
"message": "Upper price must be greater than lower price",
"details": {}
}
}Requires authentication
POST /api/stop-grid-bot
Content-Type: application/json
X-API-Secret: your_api_secretRequest Body:
{}Response:
{
"success": true,
"message": "Grid bot stopped successfully"
}Requires authentication
GET /api/trade-history
X-API-Secret: your_api_secretResponse:
{
"success": true,
"message": "Trade history retrieved successfully",
"data": {
"trades": [],
"totalTrades": 0,
"totalProfit": 0
}
}Notes:
- Results are cached for 60 seconds for performance
- Rate limited to 20 requests per minute
A Postman collection is included: postman_collection.json
- Open Postman
- Click Import
- Select
postman_collection.json - Update the
API_SECRETvariable to match your.envfile
BASE_URL:http://localhost:5050API_SECRET: Your API secret from.env
{
"gridBotTokens": [
{
"symbol": "EUR-USD",
"priceRange": {
"upperPrice": 1.163,
"lowerPrice": 1.161
},
"gridSpacing": {
"levelsMax": 4
},
"investment": 1.5,
"leverage": 10,
"strategy": "neutral"
}
]
}What this does:
- Creates 4 grid levels between $1.161 and $1.163
- Invests $1.50 per level with 10x leverage
- Uses neutral strategy for balanced trading
{
"gridBotTokens": [
{
"symbol": "BTC-USD",
"priceRange": {
"upperPrice": 50000,
"lowerPrice": 45000
},
"gridSpacing": {
"levelsMax": 10
},
"investment": 100,
"leverage": 5,
"strategy": "long"
},
{
"symbol": "ETH-USD",
"priceRange": {
"upperPrice": 3000,
"lowerPrice": 2500
},
"gridSpacing": {
"levelsMax": 8
},
"investment": 50,
"leverage": 3,
"strategy": "neutral"
}
]
}What this does:
- Runs 2 bots simultaneously
- BTC bot: 10 levels, $100/level, 5x leverage, long bias
- ETH bot: 8 levels, $50/level, 3x leverage, neutral
- API Authentication: Required for all trading endpoints
- Rate Limiting: Prevents brute force and DDoS attacks
- Brute Force Protection: Progressive lockout after failed auth attempts
- CORS: Configurable origin restrictions
- Helmet: Security headers enabled
- Input Validation: Zod schema validation for all requests
grid-bot-extended/
βββ src/
β βββ config/ # Configuration loaders
β βββ manager/ # Grid bot manager logic
β βββ middleware/ # Auth & rate limiting
β βββ server/ # Express server
β βββ types/ # TypeScript types
β βββ index.ts # Entry point
βββ postman_collection.json
βββ .env.example
βββ package.json
βββ README.md
npm run build # Build TypeScript to JavaScript
npm start # Start production server
npm run dev # Development mode with watch
npm run format # Format code with PrettierThis is a showcase project. Contributions are welcome but please understand:
- This is NOT production-ready
- Use at your own risk
- No warranty or guarantees
ISC
- ask-starknet: https://github.com/KasarLabs/ask-starknet
- X10 Exchange: https://x10.exchange
- Starknet: https://starknet.io
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE AUTHORS AND KASAR LABS ARE NOT RESPONSIBLE FOR ANY LOSSES, DAMAGES, OR OTHER LIABILITIES THAT MAY RESULT FROM USING THIS SOFTWARE.
TRADING CRYPTOCURRENCIES AND PERPETUAL FUTURES INVOLVES SIGNIFICANT RISK. ONLY TRADE WITH MONEY YOU CAN AFFORD TO LOSE.
Made with β€οΈ by KasarLabs