bitkub-client is a TypeScript wrapper for selected Bitkub API v3 and v4 endpoints. It handles API request signing for authenticated methods and returns Axios responses.
npm install bitkub-client
# or
yarn add bitkub-client
Create an API key and secret in your Bitkub account. Keep the secret private; load credentials from environment variables or another secrets manager instead of committing them to source control.
import BitkubClient, { BitkubEnvironment } from "bitkub-client";
const client = new BitkubClient(
process.env.BITKUB_API_KEY!,
process.env.BITKUB_API_SECRET!,
BitkubEnvironment.TEST
);
async function main() {
const time = await client.getServerTime();
console.log("Server time:", time.data);
const symbols = await client.getSymbols();
console.log("Symbols:", symbols.data.result);
const balances = await client.getBalances();
console.log("Balances:", balances.data.data);
const assets = await client.getWalletAssets();
console.log("Assets:", assets.data.data);
}
main().catch(console.error);
The constructor defaults to BitkubEnvironment.TEST. In this environment, placeBid and placeAsk call Bitkub's test-order endpoints. Set BitkubEnvironment.PRODUCTION to send those orders to the live endpoints. Check the environment before placing a live order.
const client = new BitkubClient(
process.env.BITKUB_API_KEY!,
process.env.BITKUB_API_SECRET!,
BitkubEnvironment.PRODUCTION
);
| Method | Purpose |
|---|---|
getServerTime() |
Get Bitkub server time. |
getSymbols() |
List market symbols. |
getBalances(params?) |
Get funding wallet balances from v4. Amounts are decimal strings in response.data.data. |
getWalletAssets(params?) |
Get funding wallet assets from v4. |
getBids(symbol, limit?) |
Get bids for a market; limit defaults to 1. |
getAsks(symbol, limit?) |
Get asks for a market; limit defaults to 1. |
placeBid(symbol, amount, rate, orderType?, clientId?) |
Place a buy order. Order type defaults to BitkubOrderType.MARKET. |
placeAsk(symbol, amount, rate, orderType?, clientId?) |
Place a sell order. Order type defaults to BitkubOrderType.MARKET. |
cancelOrder(hash, symbol?, orderId?, orderSide?) |
Cancel by order hash, or provide null for the hash and identify the order with symbol, ID, and side. |
Methods return an Axios response. The Bitkub response body is in .data; for example, const { data } = await client.getSymbols().
import { BitkubOrderType } from "bitkub-client";
// On the TEST environment this uses Bitkub's test-order endpoint.
const order = await client.placeBid(
"BTC_THB",
1, // amount
500000, // rate
BitkubOrderType.LIMIT
);
// Cancel using the order hash returned by Bitkub.
const cancellation = await client.cancelOrder(order.data.result.hash);
You can also cancel with cancelOrder(null, symbol, orderId, orderSide) when you do not have the order hash. The side is "buy" or "sell".
placeAsk takes the same arguments as placeBid. Review Bitkub's API documentation for symbol formats, order requirements, and response fields.
For a secured API v3 or v4 endpoint that this package does not wrap, use buildRequestHeaders() to create the API key, timestamp, and signature headers. Pass the path relative to /api; for GET requests, include the query string in that path or pass query parameters as the third argument. Send the request using the same method, path, and payload you signed.
import axios from "axios";
const path = "/v3/market/cancel-order";
const payload = { hash: "ORDER_HASH" };
const headers = await client.buildRequestHeaders("POST", path, payload);
const response = await axios.post(
`https://api.bitkub.com/api${path}`,
payload,
{ headers }
);
buildRequestHeaders() calls Bitkub's v3 server-time endpoint to create the timestamp used in the signature. Market data, orders, and server time use v3; wallet balances and assets use v4. See the v3 and v4 documentation for endpoint requirements.
This package uses endpoint-specific Bitkub API versions. API keys need the permissions required by the endpoints you call. If you are upgrading from an API key created for version 1.x or 2.x, create a new API key in Bitkub before using this client.
See the bitkub-client API documentation for TypeScript types and further details.
Install dependencies and run the integration tests:
yarn install
yarn test
Tests use nock to mock Bitkub API requests. Add or update mocks in src/BitkubClient.test.ts so tests do not depend on live requests or change account data. Pull requests are welcome.