Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/gateio-api/llms.txt
Use this file to discover all available pages before exploring further.
The gateio-api SDK ships with a lightweight built-in logger that prints to the Node.js console. In production environments you will almost certainly want to route those logs to your own logging infrastructure, silence noisy levels, or integrate with a library such as winston or pino. All of this is supported through a simple logger interface.
The DefaultLogger
The SDK exports a DefaultLogger object from src/lib/logger.ts. Its complete definition is:
export type LogParams = null | any;
export const DefaultLogger = {
trace: (..._params: LogParams): void => {
// silent by default
},
info: (...params: LogParams): void => {
console.info(params);
},
error: (...params: LogParams): void => {
console.error(params);
},
};
export type DefaultLogger = typeof DefaultLogger;
Out of the box, only info and error produce output. The trace level is a no-op so that internal SDK diagnostics remain silent until you explicitly enable them.
DefaultLogger has exactly three methods: trace, info, and error. These are the only log-level methods the SDK calls internally. When you pass a custom logger object you only need to implement these three methods — any additional methods will never be invoked by the SDK.
Log Levels
The following log levels are called by the SDK internally (listed from most verbose to least verbose):
| Level | DefaultLogger behaviour | Purpose |
|---|
trace | Silent (no-op) | Low-level execution tracing — WebSocket ping/pong cycles, message routing, connection events |
info | console.info(...) | General informational messages — connection open/close, reconnection attempts |
error | console.error(...) | Errors that require attention — failed sends, parse failures, auth errors |
Passing a Logger to the WebSocket Client
The WebsocketClient constructor accepts an optional second argument: any object that implements the logger interface.
import { WebsocketClient, DefaultLogger } from 'gateio-api';
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
DefaultLogger, // pass the default logger explicitly, or swap in your own
);
If the second argument is omitted, DefaultLogger is used automatically.
Silencing Specific Log Levels
The easiest way to reduce log noise is to override individual methods on DefaultLogger before passing it to any client. Because DefaultLogger is a plain mutable object, you can replace any method with a no-op:
import { WebsocketClient, DefaultLogger } from 'gateio-api';
// Silence trace-level logs (already silent by default, shown for clarity)
DefaultLogger.trace = () => {};
// Silence info-level logs
DefaultLogger.info = () => {};
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
DefaultLogger,
);
DefaultLogger is a module-level singleton. Mutating it affects every client instance that references it in the same Node.js process. If you need different log levels per client, create a separate custom logger object instead of modifying DefaultLogger.
Enabling Full Verbose Output
During active debugging, enable all levels to see everything the SDK does internally:
import { WebsocketClient, DefaultLogger } from 'gateio-api';
// Enable trace output (silent by default)
DefaultLogger.trace = (...params: unknown[]) => console.log('[TRACE]', ...params);
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
DefaultLogger,
);
You can also set the GATETRACE environment variable to enable detailed HTTP request/response logging at the axios interceptor level:
GATETRACE=1 node ./myBot.js
Creating a Fully Custom Logger
To route logs to a different destination or format, create an object that implements the three log level methods and pass it directly to any client constructor:
import { WebsocketClient } from 'gateio-api';
const myLogger = {
trace: (...params: unknown[]) => console.debug('[gateio:trace]', ...params),
info: (...params: unknown[]) => console.info('[gateio:info]', ...params),
error: (...params: unknown[]) => console.error('[gateio:error]', ...params),
};
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
myLogger,
);
Integrating with Popular Logging Libraries
winston
pino
console (minimal)
import winston from 'winston';
import { WebsocketClient } from 'gateio-api';
const winstonLogger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
transports: [new winston.transports.Console()],
});
const gateLogger = {
trace: (...p: unknown[]) => winstonLogger.debug(String(p[0]), p.slice(1)),
info: (...p: unknown[]) => winstonLogger.info(String(p[0]), p.slice(1)),
error: (...p: unknown[]) => winstonLogger.error(String(p[0]), p.slice(1)),
};
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
gateLogger,
);
import pino from 'pino';
import { WebsocketClient } from 'gateio-api';
const pinoLogger = pino({ level: 'info' });
const gateLogger = {
trace: (...p: unknown[]) => pinoLogger.trace({ data: p }, String(p[0])),
info: (...p: unknown[]) => pinoLogger.info({ data: p }, String(p[0])),
error: (...p: unknown[]) => pinoLogger.error({ data: p }, String(p[0])),
};
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
gateLogger,
);
import { WebsocketClient } from 'gateio-api';
// Minimal logger — only errors reach the console
const quietLogger = {
trace: (..._p: unknown[]) => {},
info: (..._p: unknown[]) => {},
error: (...p: unknown[]) => console.error('[gateio]', ...p),
};
const ws = new WebsocketClient(
{ apiKey: 'KEY', apiSecret: 'SECRET' },
quietLogger,
);
Quick Reference
import { WebsocketClient, DefaultLogger } from 'gateio-api';
// Option 1 — Silence a single level on the default logger
DefaultLogger.info = () => {};
// Option 2 — Pass the (possibly mutated) default logger
const ws1 = new WebsocketClient({ apiKey: 'KEY', apiSecret: 'SECRET' }, DefaultLogger);
// Option 3 — Pass a fully custom logger object
const ws2 = new WebsocketClient({ apiKey: 'KEY', apiSecret: 'SECRET' }, {
trace: (...p) => console.debug(...p),
info: (...p) => console.info(...p),
error: (...p) => console.error(...p),
});