khazars-quant
v1.1.0
Published
Working crypto quant trading js
Readme
Khazars Quant
Khazars Quant is a Node.js SDK that provides a unified interface for crypto trading adapters across CEX and DeFi venues.
The SDK focuses on account queries, balances, order placement, cancellation, open orders, order history, positions, leverage controls, DEX quote/swap helpers, and consistent error handling.
Current status: the SDK is usable for local development, adapter integration, public market/account wrapper work, and testnet or simulated trading validation. Before using it for live trading, run the private account/order/cancel flow against each target exchange with real testnet or simulated credentials.
Supported Adapters
CEX
- [x] Binance spot
- [x] Binance USD-M futures
- [x] OKX spot
- [x] OKX swap/futures
- [x] Bybit spot
- [x] Bybit USDT perpetuals
- [x] Hyperliquid spot
- [x] Hyperliquid perpetuals
DeFi
- [x] 1inch swap API
- [x] Uniswap V2 Router02
Install
From npm:
npm install khazars-quantFrom this repository:
npm installFor production Hyperliquid access, install the official SDK. If it is unavailable, Khazars falls back to the local test stub.
npm install @nktkas/hyperliquid1inch production calls require an API key from the 1inch developer portal. Pass it in the chain options or set ONEINCH_API_KEY.
Quick Start
const { quant } = require("./khazars");
const binance = new quant("binance_spot", ["apiKey", "apiSecret"]);
const account = await binance.account();
const hyper = new quant("hyperliquid_perp", ["apiKey", "apiSecret"], {
defaultLeverage: 5
});
const order = await hyper.placeOrder({
symbol: "BTC-USDC",
side: "long",
price: 25000,
size: 0.1
});Unified Response Shape
All documented adapter methods return the same high-level shape.
{ status: true, data: {} }{
status: false,
error: {
name: "KhazarsError",
message: "Missing credential field(s): KEY, SEC",
code: "MISSING_CREDENTIALS",
exchange: "binance_spot"
}
}The SDK catches local validation errors, missing credentials, HTTP failures, invalid JSON responses, network errors, and exchange business errors where the exchange returns a non-success code.
Adapter Construction
new quant(type, keys, options)type: adapter name, such asbinance_spot,okx_future,bybit_u_future,uniswap, or1inch.keys: API key tuple. CEX adapters use[apiKey, apiSecret]; OKX uses[apiKey, apiSecret, passphrase]; DeFi uses[privateKey].options: string base URL or an object. CEX adapters accept common options such as{ baseUrl, timeout }plus exchange-specific options such as OKX{ passphrase, simulated }, Bybit{ testnet, recvWindow, accountType, category }, and Hyperliquid{ account, defaultLeverage }. DeFi adapters accept{ chainId, rpc, router, apiKey }.
See interface.md for the full method reference.
Method availability is adapter-specific. The interface guide includes a method matrix so callers can distinguish spot-only, futures-only, and DeFi-only methods.
Tests
npm testThe test suite uses local validation and the Hyperliquid stub, so it can run without real exchange credentials.
On Windows PowerShell, if npm is blocked by execution policy, run:
npm.cmd testSecurity Notes
- Never commit API keys, secrets, private keys, or
.envfiles. - Prefer exchange API keys scoped to the minimum required permissions.
- For DeFi swaps, use
execute: falsefirst to inspect the generated transaction before signing. - 1inch and Uniswap transactions consume gas and may fail because of slippage, allowance, liquidity, or RPC issues. Handle failed responses before retrying.
