repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Imperial Perps Bot — natural language Telegram interface for the Imperial agent. |
| #3 | * |
| #4 | * Features: |
| #5 | * - Persistent session: JWT, positions, last signals, conversation context |
| #6 | * - Natural language NLP: regex + Claude fallback |
| #7 | * - Full order lifecycle: scan, long, short, close, cancel, update, collateral |
| #8 | * - Live market data: funding rates, mark prices, depth, route recommendation |
| #9 | * - Account: balances, positions, orders, deposit/withdraw |
| #10 | * - Browser-use Clawd capabilities (external research via fetch) |
| #11 | * - WebSocket subscription for live market push to Telegram |
| #12 | * |
| #13 | * Environment (beyond ImperialConfig): |
| #14 | * TELEGRAM_BOT_TOKEN — required |
| #15 | * TELEGRAM_ALLOWED_CHATS — comma-separated chat IDs (empty = open) |
| #16 | * CLAWD_CLAUDE_API_KEY — optional: Claude API key for NLP fallback |
| #17 | * IMPERIAL_STATE_FILE — path to persist state JSON (default ./imperial-state.json) |
| #18 | */ |
| #19 | import { type ImperialConfig, type AgentSignal, type ExecutionRecord } from "./imperialAgent.js"; |
| #20 | export interface BotState { |
| #21 | jwt: string; |
| #22 | jwtExpiresAt: string; |
| #23 | lastSignals: AgentSignal[]; |
| #24 | lastScanTs: number; |
| #25 | executionHistory: ExecutionRecord[]; |
| #26 | conversationCtx: Record<string, string[]>; |
| #27 | } |
| #28 | export type BotIntent = { |
| #29 | kind: "scan"; |
| #30 | symbols?: string[]; |
| #31 | } | { |
| #32 | kind: "long"; |
| #33 | symbol: string; |
| #34 | sizeUsd?: number; |
| #35 | venue?: number; |
| #36 | tpPrice?: number; |
| #37 | slPrice?: number; |
| #38 | } | { |
| #39 | kind: "short"; |
| #40 | symbol: string; |
| #41 | sizeUsd?: number; |
| #42 | venue?: number; |
| #43 | } | { |
| #44 | kind: "close"; |
| #45 | symbol: string; |
| #46 | sizeUsd?: number; |
| #47 | } | { |
| #48 | kind: "cancel"; |
| #49 | orderPda: string; |
| #50 | } | { |
| #51 | kind: "positions"; |
| #52 | } | { |
| #53 | kind: "balances"; |
| #54 | } | { |
| #55 | kind: "funding"; |
| #56 | symbol?: string; |
| #57 | } | { |
| #58 | kind: "marks"; |
| #59 | symbol?: string; |
| #60 | } | { |
| #61 | kind: "depth"; |
| #62 | symbol: string; |
| #63 | } | { |
| #64 | kind: "route"; |
| #65 | symbol: string; |
| #66 | side: "long" | "short"; |
| #67 | notional: number; |
| #68 | } | { |
| #69 | kind: "health"; |
| #70 | } | { |
| #71 | kind: "orders"; |
| #72 | } | { |
| #73 | kind: "history"; |
| #74 | } | { |
| #75 | kind: "deposit"; |
| #76 | amount: number; |
| #77 | } | { |
| #78 | kind: "withdraw"; |
| #79 | amount: number; |
| #80 | } | { |
| #81 | kind: "help"; |
| #82 | } | { |
| #83 | kind: "unknown"; |
| #84 | raw: string; |
| #85 | }; |
| #86 | export declare function parseIntent(text: string): BotIntent; |
| #87 | export declare class ImperialBot { |
| #88 | private client; |
| #89 | private token; |
| #90 | private allowedChats; |
| #91 | private claudeApiKey; |
| #92 | private stateFile; |
| #93 | private state; |
| #94 | private updateOffset; |
| #95 | private running; |
| #96 | constructor(opts?: { |
| #97 | imperialConfig?: Partial<ImperialConfig>; |
| #98 | telegramToken?: string; |
| #99 | allowedChats?: string[]; |
| #100 | claudeApiKey?: string; |
| #101 | stateFile?: string; |
| #102 | }); |
| #103 | private isAllowed; |
| #104 | private addCtx; |
| #105 | private pushRecord; |
| #106 | /** Parse intent: regex first, Claude fallback if available and unknown. */ |
| #107 | private parseIntent; |
| #108 | /** Browser-use: fetch a URL and return text content (Clawd capability). */ |
| #109 | browse(url: string): Promise<string>; |
| #110 | /** Handle a single incoming message. */ |
| #111 | handleMessage(chatId: string | number, text: string): Promise<string>; |
| #112 | /** Poll Telegram for updates and dispatch. */ |
| #113 | poll(): Promise<void>; |
| #114 | /** Subscribe to Imperial /ws/market and push updates to a Telegram chat. */ |
| #115 | subscribeMarketWs(chatId: string | number, symbols?: string[]): Promise<void>; |
| #116 | stop(): void; |
| #117 | } |
| #118 | /** Quick start: create and run the bot. */ |
| #119 | export declare function startImperialBot(opts?: ConstructorParameters<typeof ImperialBot>[0]): Promise<ImperialBot>; |
| #120 |