|
| 1 | +const BASE_URL = 'https://api.hubble.xyz' |
| 2 | + |
| 3 | +export interface HubbleSignalConfig { |
| 4 | + name: string |
| 5 | + callback_url: string |
| 6 | + chain: 'ETH' | 'SOL' |
| 7 | + activity: 'CEX' |
| 8 | + action: 'Inflow' | 'Outflow' |
| 9 | + exchanges: string[] // e.g. ["Binance", "OKX"] or ["All"] |
| 10 | + token_addresses?: string[] // Optional |
| 11 | + wallet_addresses?: string[] // Optional |
| 12 | + min_amount?: string |
| 13 | + max_amount?: string |
| 14 | +} |
| 15 | + |
| 16 | +interface HubbleResponse<T = any> { |
| 17 | + code: number |
| 18 | + message: string |
| 19 | + data?: T |
| 20 | +} |
| 21 | + |
| 22 | +export const hubbleApi = { |
| 23 | + /** |
| 24 | + * Create a new signal configuration |
| 25 | + */ |
| 26 | + async createSignal(config: HubbleSignalConfig) { |
| 27 | + return await this.request('/signal/config', 'POST', config) |
| 28 | + }, |
| 29 | + |
| 30 | + /** |
| 31 | + * Get list of signals |
| 32 | + */ |
| 33 | + async getSignalList(params?: { name?: string, status?: 'ongoing' | 'paused', page?: number, size?: number }) { |
| 34 | + const query = new URLSearchParams() |
| 35 | + if (params?.name) { query.append('name', params.name) } |
| 36 | + if (params?.status) { query.append('status', params.status) } |
| 37 | + if (params?.page) { query.append('page', String(params.page)) } |
| 38 | + if (params?.size) { query.append('size', String(params.size)) } |
| 39 | + |
| 40 | + return await this.request(`/signal/config?${query.toString()}`, 'GET') |
| 41 | + }, |
| 42 | + |
| 43 | + /** |
| 44 | + * Update a signal configuration |
| 45 | + */ |
| 46 | + async updateSignal(webhookId: string, config: Partial<HubbleSignalConfig>) { |
| 47 | + return await this.request(`/signal/config/${webhookId}`, 'PUT', config) |
| 48 | + }, |
| 49 | + |
| 50 | + /** |
| 51 | + * Pause or Activate a signal |
| 52 | + */ |
| 53 | + async setSignalStatus(webhookId: string, status: 'ongoing' | 'paused') { |
| 54 | + return await this.request(`/signal/config/${webhookId}`, 'PATCH', { status }) |
| 55 | + }, |
| 56 | + |
| 57 | + /** |
| 58 | + * Delete a signal |
| 59 | + */ |
| 60 | + async deleteSignal(webhookId: string) { |
| 61 | + return await this.request(`/signal/config/${webhookId}`, 'DELETE') |
| 62 | + }, |
| 63 | + |
| 64 | + /** |
| 65 | + * Internal request helper |
| 66 | + */ |
| 67 | + async request(path: string, method: string, body?: any) { |
| 68 | + const { hubble } = useRuntimeConfig() |
| 69 | + if (!hubble.apiKey) { |
| 70 | + throw new Error('HUBBLE_API_KEY is not configured') |
| 71 | + } |
| 72 | + |
| 73 | + // Replace {YOUR HUBBLE-API-KEY} with actual key |
| 74 | + const headers = { |
| 75 | + 'Content-Type': 'application/json', |
| 76 | + 'HUBBLE-API-KEY': hubble.apiKey, |
| 77 | + } |
| 78 | + |
| 79 | + try { |
| 80 | + const response = await fetch(`${BASE_URL}${path}`, { |
| 81 | + method, |
| 82 | + headers, |
| 83 | + body: body ? JSON.stringify(body) : undefined, |
| 84 | + }) |
| 85 | + |
| 86 | + const data = await response.json() as HubbleResponse |
| 87 | + |
| 88 | + if (!response.ok) { |
| 89 | + throw new Error(`Hubble API Error: ${response.status} ${response.statusText} - ${JSON.stringify(data)}`) |
| 90 | + } |
| 91 | + |
| 92 | + return data |
| 93 | + } |
| 94 | + catch (error) { |
| 95 | + console.error('Hubble API Request Failed:', error) |
| 96 | + throw error |
| 97 | + } |
| 98 | + }, |
| 99 | +} |
0 commit comments