# pip install websocket-client
import websocket
import json
api_key = 'your_api_key_here'
ws_url = f'wss://api.tickdb.ai/v1/realtime?api_key={api_key}'
def on_open(ws):
ws.send(json.dumps({
'cmd': 'subscribe',
'data': {
'channel': 'ticker',
'symbols': ['IF8888', 'RB8888', 'HSI8888']
}
}))
def on_message(ws, message):
data = json.loads(message)
print('Received:', data)
ws = websocket.WebSocketApp(ws_url, on_open=on_open, on_message=on_message)
ws.run_forever()
// npm install ws
const WebSocket = require('ws');
const apiKey = 'your_api_key_here';
const ws = new WebSocket(`wss://api.tickdb.ai/v1/realtime?api_key=${apiKey}`);
ws.on('open', () => {
ws.send(JSON.stringify({
cmd: 'subscribe',
data: {
channel: 'ticker',
symbols: ['IF8888', 'RB8888', 'HSI8888']
}
}));
});
ws.on('message', (data) => {
const message = JSON.parse(data);
console.log('Received:', message);
});
const apiKey = 'your_api_key_here';
const ws = new WebSocket(`wss://api.tickdb.ai/v1/realtime?api_key=${apiKey}`);
ws.onopen = () => {
ws.send(JSON.stringify({
cmd: 'subscribe',
data: {
channel: 'ticker',
symbols: ['IF8888', 'RB8888', 'HSI8888']
}
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message);
};
import org.java_websocket.client.WebSocketClient;
import com.google.gson.Gson;
import java.net.URI;
import java.util.*;
public class TickDBClient extends WebSocketClient {
private Gson gson = new Gson();
public TickDBClient(String apiKey) throws Exception {
super(new URI("wss://api.tickdb.ai/v1/realtime?api_key=" + apiKey));
}
@Override
public void onOpen(ServerHandshake handshake) {
Map<String, Object> msg = new HashMap<>();
msg.put("cmd", "subscribe");
Map<String, Object> data = new HashMap<>();
data.put("channel", "ticker");
data.put("symbols", Arrays.asList("IF8888", "RB8888", "HSI8888"));
msg.put("data", data);
send(gson.toJson(msg));
}
@Override
public void onMessage(String message) {
System.out.println("Received: " + message);
}
}
// go get github.com/gorilla/websocket
package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"github.com/gorilla/websocket"
)
func main() {
apiKey := "your_api_key_here"
u := url.URL{Scheme: "wss", Host: "api.tickdb.ai", Path: "/v1/realtime", RawQuery: "api_key=" + apiKey}
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
msg := map[string]interface{}{
"cmd": "subscribe",
"data": map[string]interface{}{
"channel": "ticker",
"symbols": []string{"IF8888", "RB8888", "HSI8888"},
},
}
c.WriteJSON(msg)
for {
var resp map[string]interface{}
c.ReadJSON(&resp)
fmt.Printf("Received: %v\n", resp)
}
}
// tokio-tungstenite, tokio, serde_json, futures-util
use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
use serde_json::json;
use futures_util::{SinkExt, StreamExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = "your_api_key_here";
let url = format!("wss://api.tickdb.ai/v1/realtime?api_key={}", api_key);
let (ws_stream, _) = connect_async(&url).await?;
let (mut write, mut read) = ws_stream.split();
let subscribe_msg = json!({
"cmd": "subscribe",
"data": {
"channel": "ticker",
"symbols": ["IF8888", "RB8888", "HSI8888"]
}
});
write.send(Message::Text(subscribe_msg.to_string())).await?;
while let Some(message) = read.next().await {
if let Ok(Message::Text(text)) = message {
println!("Received: {}", text);
}
}
Ok(())
}