import requests
api_url = "https://data.infoway.io/crypto/v2/batch_kline"
headers = {
"User-Agent": "Mozilla/5.0",
"Accept": "application/json",
"Content-Type": "application/json",
"apiKey": "yourApikey",
}
payload = {
"klineType": 1,
"klineNum": 10,
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
}
response = requests.post(api_url, headers=headers, json=payload)
print(f"HTTP code: {response.status_code}")
print(f"message: {response.text}")
import requests
api_url = "https://data.infoway.io/crypto/batch_trade/BTCUSDT,ETHUSDT,SOLUSDT"
headers = {
"User-Agent": "Mozilla/5.0",
"Accept": "application/json",
"apiKey": "yourApikey",
}
response = requests.get(api_url, headers=headers)
print(f"HTTP code: {response.status_code}")
print(f"message: {response.text}")
import requests
api_url = "https://data.infoway.io/crypto/batch_depth/BTCUSDT,ETHUSDT,SOLUSDT"
headers = {
"User-Agent": "Mozilla/5.0",
"Accept": "application/json",
"apiKey": "yourApikey",
}
response = requests.get(api_url, headers=headers)
print(f"HTTP code: {response.status_code}")
print(f"message: {response.text}")
import asyncio
import json
import uuid
import websockets
WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey"
async def send_heartbeat(websocket):
while True:
await asyncio.sleep(30)
ping_message = {
"code": 10010,
"trace": str(uuid.uuid4()),
}
await websocket.send(json.dumps(ping_message))
async def connect_and_receive():
async with websockets.connect(WS_URL) as websocket:
print("Connection opened")
init_message = {
"code": 10006,
"trace": str(uuid.uuid4()),
"data": {
"arr": [
{
"type": 1,
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
}
]
},
}
await websocket.send(json.dumps(init_message))
heartbeat_task = asyncio.create_task(send_heartbeat(websocket))
try:
while True:
message = await websocket.recv()
print(f"Message received: {message}")
except websockets.exceptions.ConnectionClosedOK:
print("Connection closed normally")
except websockets.exceptions.ConnectionClosed as error:
print(f"Connection closed: {error}")
finally:
heartbeat_task.cancel()
asyncio.run(connect_and_receive())
import asyncio
import json
import uuid
import websockets
WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey"
async def send_heartbeat(websocket):
while True:
await asyncio.sleep(30)
ping_message = {
"code": 10010,
"trace": str(uuid.uuid4()),
}
await websocket.send(json.dumps(ping_message))
async def connect_and_receive():
async with websockets.connect(WS_URL) as websocket:
print("Connection opened")
init_message = {
"code": 10000,
"trace": str(uuid.uuid4()),
"data": {
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
},
}
await websocket.send(json.dumps(init_message))
heartbeat_task = asyncio.create_task(send_heartbeat(websocket))
try:
while True:
message = await websocket.recv()
print(f"Message received: {message}")
except websockets.exceptions.ConnectionClosedOK:
print("Connection closed normally")
except websockets.exceptions.ConnectionClosed as error:
print(f"Connection closed: {error}")
finally:
heartbeat_task.cancel()
asyncio.run(connect_and_receive())
import asyncio
import json
import uuid
import websockets
WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey"
async def send_heartbeat(websocket):
while True:
await asyncio.sleep(30)
ping_message = {
"code": 10010,
"trace": str(uuid.uuid4()),
}
await websocket.send(json.dumps(ping_message))
async def connect_and_receive():
async with websockets.connect(WS_URL) as websocket:
print("Connection opened")
init_message = {
"code": 10003,
"trace": str(uuid.uuid4()),
"data": {
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
},
}
await websocket.send(json.dumps(init_message))
heartbeat_task = asyncio.create_task(send_heartbeat(websocket))
try:
while True:
message = await websocket.recv()
print(f"Message received: {message}")
except websockets.exceptions.ConnectionClosedOK:
print("Connection closed normally")
except websockets.exceptions.ConnectionClosed as error:
print(f"Connection closed: {error}")
finally:
heartbeat_task.cancel()
asyncio.run(connect_and_receive())
package org.example.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class HttpExample {
public static void main(String[] args) {
try {
String apiUrl = "https://data.infoway.io/crypto/v2/batch_kline";
String payload = "{\"klineType\":1,\"klineNum\":10,\"codes\":\"BTCUSDT,ETHUSDT,SOLUSDT\"}";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("apiKey", "yourApikey");
try (OutputStream os = connection.getOutputStream()) {
byte[] input = payload.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = connection.getResponseCode();
System.out.println("HTTP code: " + responseCode);
BufferedReader reader;
if (responseCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
}
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("message: " + response);
} catch (IOException e) {
e.printStackTrace();
}
}
}package org.example.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpExample {
public static void main(String[] args) {
try {
String apiUrl = "https://data.infoway.io/crypto/batch_trade/BTCUSDT,ETHUSDT,SOLUSDT";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("apiKey", "yourApikey");
int responseCode = connection.getResponseCode();
System.out.println("HTTP code: " + responseCode);
BufferedReader reader;
if (responseCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
}
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("message: " + response);
} catch (IOException e) {
e.printStackTrace();
}
}
}package org.example.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpExample {
public static void main(String[] args) {
try {
String apiUrl = "https://data.infoway.io/crypto/batch_depth/BTCUSDT,ETHUSDT,SOLUSDT";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("apiKey", "yourApikey");
int responseCode = connection.getResponseCode();
System.out.println("HTTP code: " + responseCode);
BufferedReader reader;
if (responseCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
}
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("message: " + response);
} catch (IOException e) {
e.printStackTrace();
}
}
}package org.example.ws;
import com.alibaba.fastjson2.JSONObject;
import jakarta.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class WebsocketExample {
private static Session session;
private static final String WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
public static void main(String[] args) throws Exception {
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
session = container.connectToServer(WebsocketExample.MyClientEndpoint.class, URI.create(WS_URL));
session.getBasicRemote().sendText("{\"code\":10006,\"trace\":\"01213e9d-90a0-426e-a380-ebed633cba7a\",\"data\":{\"arr\":[{\"type\":1,\"codes\":\"BTCUSDT,ETHUSDT,SOLUSDT\"}]}}");
ScheduledExecutorService pingExecutor = Executors.newScheduledThreadPool(1);
pingExecutor.scheduleAtFixedRate(WebsocketExample::ping, 30, 30, TimeUnit.SECONDS);
Thread.sleep(600 * 1000);
session.close();
} catch (DeploymentException | IOException | InterruptedException e) {
e.printStackTrace();
}
}
@ClientEndpoint
public static class MyClientEndpoint {
@OnOpen
public void onOpen(Session session) {
System.out.println("Connection opened: " + session.getId());
}
@OnMessage
public void onMessage(String message, Session session) {
System.out.println("Message received: " + message);
}
@OnClose
public void onClose(Session session, CloseReason reason) {
System.out.println("Connection closed: " + session.getId() + ", reason: " + reason);
}
@OnError
public void onError(Throwable error) {
error.printStackTrace();
}
}
public static void ping() {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", 10010);
jsonObject.put("trace", "01213e9d-90a0-426e-a380-ebed633cba7a");
session.getBasicRemote().sendText(jsonObject.toJSONString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}package org.example.ws;
import com.alibaba.fastjson2.JSONObject;
import jakarta.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class WebsocketExample {
private static Session session;
private static final String WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
public static void main(String[] args) throws Exception {
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
session = container.connectToServer(WebsocketExample.MyClientEndpoint.class, URI.create(WS_URL));
session.getBasicRemote().sendText("{\"code\":10000,\"trace\":\"01213e9d-90a0-426e-a380-ebed633cba7a\",\"data\":{\"codes\":\"BTCUSDT,ETHUSDT,SOLUSDT\"}}");
ScheduledExecutorService pingExecutor = Executors.newScheduledThreadPool(1);
pingExecutor.scheduleAtFixedRate(WebsocketExample::ping, 30, 30, TimeUnit.SECONDS);
Thread.sleep(600 * 1000);
session.close();
} catch (DeploymentException | IOException | InterruptedException e) {
e.printStackTrace();
}
}
@ClientEndpoint
public static class MyClientEndpoint {
@OnOpen
public void onOpen(Session session) {
System.out.println("Connection opened: " + session.getId());
}
@OnMessage
public void onMessage(String message, Session session) {
System.out.println("Message received: " + message);
}
@OnClose
public void onClose(Session session, CloseReason reason) {
System.out.println("Connection closed: " + session.getId() + ", reason: " + reason);
}
@OnError
public void onError(Throwable error) {
error.printStackTrace();
}
}
public static void ping() {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", 10010);
jsonObject.put("trace", "01213e9d-90a0-426e-a380-ebed633cba7a");
session.getBasicRemote().sendText(jsonObject.toJSONString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}package org.example.ws;
import com.alibaba.fastjson2.JSONObject;
import jakarta.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class WebsocketExample {
private static Session session;
private static final String WS_URL = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
public static void main(String[] args) throws Exception {
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
session = container.connectToServer(WebsocketExample.MyClientEndpoint.class, URI.create(WS_URL));
session.getBasicRemote().sendText("{\"code\":10003,\"trace\":\"01213e9d-90a0-426e-a380-ebed633cba7a\",\"data\":{\"codes\":\"BTCUSDT,ETHUSDT,SOLUSDT\"}}");
ScheduledExecutorService pingExecutor = Executors.newScheduledThreadPool(1);
pingExecutor.scheduleAtFixedRate(WebsocketExample::ping, 30, 30, TimeUnit.SECONDS);
Thread.sleep(600 * 1000);
session.close();
} catch (DeploymentException | IOException | InterruptedException e) {
e.printStackTrace();
}
}
@ClientEndpoint
public static class MyClientEndpoint {
@OnOpen
public void onOpen(Session session) {
System.out.println("Connection opened: " + session.getId());
}
@OnMessage
public void onMessage(String message, Session session) {
System.out.println("Message received: " + message);
}
@OnClose
public void onClose(Session session, CloseReason reason) {
System.out.println("Connection closed: " + session.getId() + ", reason: " + reason);
}
@OnError
public void onError(Throwable error) {
error.printStackTrace();
}
}
public static void ping() {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", 10010);
jsonObject.put("trace", "01213e9d-90a0-426e-a380-ebed633cba7a");
session.getBasicRemote().sendText(jsonObject.toJSONString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}<?php
$apiUrl = 'https://data.infoway.io/crypto/v2/batch_kline';
$payload = json_encode([
'klineType' => 1,
'klineNum' => 10,
'codes' => 'BTCUSDT,ETHUSDT,SOLUSDT',
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'User-Agent: Mozilla/5.0',
'Accept: application/json',
'Content-Type: application/json',
'apiKey: yourApikey'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP code: $httpCode\n";
echo "message: $response";
<?php
$apiUrl = 'https://data.infoway.io/crypto/batch_trade/BTCUSDT,ETHUSDT,SOLUSDT';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'User-Agent: Mozilla/5.0',
'Accept: application/json',
'apiKey: yourApikey'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP code: $httpCode\n";
echo "message: $response";
<?php
$apiUrl = 'https://data.infoway.io/crypto/batch_depth/BTCUSDT,ETHUSDT,SOLUSDT';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'User-Agent: Mozilla/5.0',
'Accept: application/json',
'apiKey: yourApikey'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP code: $httpCode\n";
echo "message: $response";
<?php
require __DIR__ . '/vendor/autoload.php';
use Ratchet\Client\WebSocket;
use Ratchet\Client\Connector;
use React\EventLoop\Factory;
$loop = Factory::create();
$connector = new Connector($loop);
$wsUrl = 'wss://data.infoway.io/ws?business=crypto&apikey=yourApikey';
$connector($wsUrl)->then(
function (WebSocket $conn) use ($loop) {
echo "Connection opened\n";
$conn->send('{"code":10006,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"arr":[{"type":1,"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}]}}');
$loop->addPeriodicTimer(30, function () use ($conn) {
$conn->send(json_encode([
'code' => 10010,
'trace' => '01213e9d-90a0-426e-a380-ebed633cba7a',
]));
});
$conn->on('message', function ($msg) {
echo "Message received: {$msg}\n";
});
$conn->on('close', function ($code = null, $reason = null) {
echo "Connection closed ({$code}): {$reason}\n";
});
},
function (\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
}
);
$loop->run();
<?php
require __DIR__ . '/vendor/autoload.php';
use Ratchet\Client\WebSocket;
use Ratchet\Client\Connector;
use React\EventLoop\Factory;
$loop = Factory::create();
$connector = new Connector($loop);
$wsUrl = 'wss://data.infoway.io/ws?business=crypto&apikey=yourApikey';
$connector($wsUrl)->then(
function (WebSocket $conn) use ($loop) {
echo "Connection opened\n";
$conn->send('{"code":10000,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}}');
$loop->addPeriodicTimer(30, function () use ($conn) {
$conn->send(json_encode([
'code' => 10010,
'trace' => '01213e9d-90a0-426e-a380-ebed633cba7a',
]));
});
$conn->on('message', function ($msg) {
echo "Message received: {$msg}\n";
});
$conn->on('close', function ($code = null, $reason = null) {
echo "Connection closed ({$code}): {$reason}\n";
});
},
function (\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
}
);
$loop->run();
<?php
require __DIR__ . '/vendor/autoload.php';
use Ratchet\Client\WebSocket;
use Ratchet\Client\Connector;
use React\EventLoop\Factory;
$loop = Factory::create();
$connector = new Connector($loop);
$wsUrl = 'wss://data.infoway.io/ws?business=crypto&apikey=yourApikey';
$connector($wsUrl)->then(
function (WebSocket $conn) use ($loop) {
echo "Connection opened\n";
$conn->send('{"code":10003,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}}');
$loop->addPeriodicTimer(30, function () use ($conn) {
$conn->send(json_encode([
'code' => 10010,
'trace' => '01213e9d-90a0-426e-a380-ebed633cba7a',
]));
});
$conn->on('message', function ($msg) {
echo "Message received: {$msg}\n";
});
$conn->on('close', function ($code = null, $reason = null) {
echo "Connection closed ({$code}): {$reason}\n";
});
},
function (\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
}
);
$loop->run();
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
apiUrl := "https://data.infoway.io/crypto/v2/batch_kline"
payload := strings.NewReader("{\"klineType\":1,\"klineNum\":10,\"codes\":\"BTCUSDT,ETHUSDT,SOLUSDT\"}")
client := &http.Client{}
req, err := http.NewRequest("POST", apiUrl, payload)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("User-Agent", "Mozilla/5.0")
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("apiKey", "yourApikey")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("HTTP code:", resp.StatusCode)
fmt.Println("message:", string(body))
}package main
import (
"fmt"
"io"
"net/http"
)
func main() {
apiUrl := "https://data.infoway.io/crypto/batch_trade/BTCUSDT,ETHUSDT,SOLUSDT"
client := &http.Client{}
req, err := http.NewRequest("GET", apiUrl, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("User-Agent", "Mozilla/5.0")
req.Header.Set("Accept", "application/json")
req.Header.Set("apiKey", "yourApikey")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("HTTP code:", resp.StatusCode)
fmt.Println("message:", string(body))
}package main
import (
"fmt"
"io"
"net/http"
)
func main() {
apiUrl := "https://data.infoway.io/crypto/batch_depth/BTCUSDT,ETHUSDT,SOLUSDT"
client := &http.Client{}
req, err := http.NewRequest("GET", apiUrl, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("User-Agent", "Mozilla/5.0")
req.Header.Set("Accept", "application/json")
req.Header.Set("apiKey", "yourApikey")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("HTTP code:", resp.StatusCode)
fmt.Println("message:", string(body))
}package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/gorilla/websocket"
)
func main() {
u := url.URL{
Scheme: "wss",
Host: "data.infoway.io",
Path: "/ws",
RawQuery: "business=crypto&apikey=yourApikey",
}
log.Printf("Connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
initMsg := []byte(`{"code":10006,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"arr":[{"type":1,"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}]}}`)
if err := c.WriteMessage(websocket.TextMessage, initMsg); err != nil {
log.Fatal("write:", err)
}
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
done := make(chan struct{})
go func() {
defer close(done)
for {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
fmt.Println("Message received:", string(message))
}
}()
go func() {
for range ticker.C {
pingMsg := map[string]interface{}{
"code": 10010,
"trace": "01213e9d-90a0-426e-a380-ebed633cba7a",
}
pingMsgJSON, _ := json.Marshal(pingMsg)
if err := c.WriteMessage(websocket.TextMessage, pingMsgJSON); err != nil {
log.Println("ping error:", err)
return
}
}
}()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
select {
case <-done:
log.Println("WebSocket connection closed by server")
case <-interrupt:
log.Println("Interrupted by user")
}
}package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/gorilla/websocket"
)
func main() {
u := url.URL{
Scheme: "wss",
Host: "data.infoway.io",
Path: "/ws",
RawQuery: "business=crypto&apikey=yourApikey",
}
log.Printf("Connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
initMsg := []byte(`{"code":10000,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}}`)
if err := c.WriteMessage(websocket.TextMessage, initMsg); err != nil {
log.Fatal("write:", err)
}
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
done := make(chan struct{})
go func() {
defer close(done)
for {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
fmt.Println("Message received:", string(message))
}
}()
go func() {
for range ticker.C {
pingMsg := map[string]interface{}{
"code": 10010,
"trace": "01213e9d-90a0-426e-a380-ebed633cba7a",
}
pingMsgJSON, _ := json.Marshal(pingMsg)
if err := c.WriteMessage(websocket.TextMessage, pingMsgJSON); err != nil {
log.Println("ping error:", err)
return
}
}
}()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
select {
case <-done:
log.Println("WebSocket connection closed by server")
case <-interrupt:
log.Println("Interrupted by user")
}
}package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/gorilla/websocket"
)
func main() {
u := url.URL{
Scheme: "wss",
Host: "data.infoway.io",
Path: "/ws",
RawQuery: "business=crypto&apikey=yourApikey",
}
log.Printf("Connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
initMsg := []byte(`{"code":10003,"trace":"01213e9d-90a0-426e-a380-ebed633cba7a","data":{"codes":"BTCUSDT,ETHUSDT,SOLUSDT"}}`)
if err := c.WriteMessage(websocket.TextMessage, initMsg); err != nil {
log.Fatal("write:", err)
}
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
done := make(chan struct{})
go func() {
defer close(done)
for {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
fmt.Println("Message received:", string(message))
}
}()
go func() {
for range ticker.C {
pingMsg := map[string]interface{}{
"code": 10010,
"trace": "01213e9d-90a0-426e-a380-ebed633cba7a",
}
pingMsgJSON, _ := json.Marshal(pingMsg)
if err := c.WriteMessage(websocket.TextMessage, pingMsgJSON); err != nil {
log.Println("ping error:", err)
return
}
}
}()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
select {
case <-done:
log.Println("WebSocket connection closed by server")
case <-interrupt:
log.Println("Interrupted by user")
}
}const https = require("https");
const apiUrl = "https://data.infoway.io/crypto/v2/batch_kline";
const payload = JSON.stringify({
"klineType": 1,
"klineNum": 10,
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
});
const options = {
method: "POST",
headers: {
"User-Agent": "Mozilla/5.0",
Accept: "application/json",
"Content-Type": "application/json",
apiKey: "yourApikey",
},
};
const req = https.request(apiUrl, options, (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
console.log("HTTP code:", res.statusCode);
console.log("message:", data);
});
});
req.on("error", (error) => {
console.error("Error:", error);
});
req.write(payload);
req.end();
const https = require("https");
const apiUrl = "https://data.infoway.io/crypto/batch_trade/BTCUSDT,ETHUSDT,SOLUSDT";
const options = {
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0",
Accept: "application/json",
apiKey: "yourApikey",
},
};
const req = https.request(apiUrl, options, (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
console.log("HTTP code:", res.statusCode);
console.log("message:", data);
});
});
req.on("error", (error) => {
console.error("Error:", error);
});
req.end();
const https = require("https");
const apiUrl = "https://data.infoway.io/crypto/batch_depth/BTCUSDT,ETHUSDT,SOLUSDT";
const options = {
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0",
Accept: "application/json",
apiKey: "yourApikey",
},
};
const req = https.request(apiUrl, options, (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
console.log("HTTP code:", res.statusCode);
console.log("message:", data);
});
});
req.on("error", (error) => {
console.error("Error:", error);
});
req.end();
const WebSocket = require("ws");
const { randomUUID } = require("crypto");
const wsUrl = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
const ws = new WebSocket(wsUrl);
ws.on("open", () => {
console.log("Connection opened");
const initMessage = JSON.stringify({
code: 10006,
trace: randomUUID(),
data: {
"arr": [
{
"type": 1,
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
}
]
},
});
ws.send(initMessage);
const heartbeat = setInterval(() => {
if (ws.readyState !== WebSocket.OPEN) return;
ws.send(JSON.stringify({
code: 10010,
trace: randomUUID(),
}));
}, 30000);
ws.on("close", () => clearInterval(heartbeat));
});
ws.on("message", (data) => {
console.log("Message received:", data.toString());
});
ws.on("close", (code, reason) => {
console.log("Connection closed (" + code + "): " + reason);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
process.on("SIGINT", () => {
ws.close();
process.exit(0);
});
const WebSocket = require("ws");
const { randomUUID } = require("crypto");
const wsUrl = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
const ws = new WebSocket(wsUrl);
ws.on("open", () => {
console.log("Connection opened");
const initMessage = JSON.stringify({
code: 10000,
trace: randomUUID(),
data: {
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
},
});
ws.send(initMessage);
const heartbeat = setInterval(() => {
if (ws.readyState !== WebSocket.OPEN) return;
ws.send(JSON.stringify({
code: 10010,
trace: randomUUID(),
}));
}, 30000);
ws.on("close", () => clearInterval(heartbeat));
});
ws.on("message", (data) => {
console.log("Message received:", data.toString());
});
ws.on("close", (code, reason) => {
console.log("Connection closed (" + code + "): " + reason);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
process.on("SIGINT", () => {
ws.close();
process.exit(0);
});
const WebSocket = require("ws");
const { randomUUID } = require("crypto");
const wsUrl = "wss://data.infoway.io/ws?business=crypto&apikey=yourApikey";
const ws = new WebSocket(wsUrl);
ws.on("open", () => {
console.log("Connection opened");
const initMessage = JSON.stringify({
code: 10003,
trace: randomUUID(),
data: {
"codes": "BTCUSDT,ETHUSDT,SOLUSDT"
},
});
ws.send(initMessage);
const heartbeat = setInterval(() => {
if (ws.readyState !== WebSocket.OPEN) return;
ws.send(JSON.stringify({
code: 10010,
trace: randomUUID(),
}));
}, 30000);
ws.on("close", () => clearInterval(heartbeat));
});
ws.on("message", (data) => {
console.log("Message received:", data.toString());
});
ws.on("close", (code, reason) => {
console.log("Connection closed (" + code + "): " + reason);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
process.on("SIGINT", () => {
ws.close();
process.exit(0);
});
REST WebSocket