Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,51 +207,33 @@ message ActionResponse {
- `CreateOrder` (3): Create a new order
- `GetOrderDetails` (4): Get order information
- `CancelOrder` (5): Cancel an existing order
- `FetchBalance` (6): Get account balance (free by default, supports balanceType: "free", "used", "total")
- `FetchBalances` (7): Get all account balances (free by default, supports balanceType: "free", "used", "total")
- `FetchDepositAddresses` (8): Get deposit addresses for a token/network
- `FetchTicker` (9): Get ticker information
- `FetchBalances` (6): Get account balances. Supports `balanceType`: "free", "used", "total" (defaults to "total").
- `FetchDepositAddresses` (7): Get deposit addresses for a token/network
- `FetchTicker` (8): Get ticker information
- `FetchCurrency` (9): Get currency metadata (networks, fees, etc.) for a symbol
- `Call` (10): Generic method invocation on the underlying broker instance. Provide `functionName`, optional `args` array, and optional `params` object.
- `FetchCurrency` (11): Get currency metadata (networks, fees, etc.) for a symbol

**Example Usage:**

```typescript
// Fetch balance (free by default)
const balanceRequest = {
action: 6, // FetchBalance
payload: {},
cex: "binance",
symbol: "USDT"
};

// Fetch used balance
const usedBalanceRequest = {
action: 6, // FetchBalance
payload: { balanceType: "used" },
cex: "binance",
symbol: "USDT"
};

// Fetch total balance
const totalBalanceRequest = {
action: 6, // FetchBalance
payload: { balanceType: "total" },
cex: "binance",
symbol: "USDT"
// Fetch total balances (default)
const totalBalancesRequest = {
action: 6, // FetchBalances
payload: { type: "spot" }, // default is spot if omitted
cex: "binance"
};

// Fetch all balances (free by default)
const allBalancesRequest = {
action: 7, // FetchBalances
payload: {},
// Fetch free balances
const freeBalancesRequest = {
action: 6, // FetchBalances
payload: { balanceType: "free", type: "spot" },
cex: "binance"
};

// Fetch all used balances
const allUsedBalancesRequest = {
action: 7, // FetchBalances
payload: { balanceType: "used" },
// Fetch used balances
const usedBalancesRequest = {
action: 6, // FetchBalances
payload: { balanceType: "used", type: "spot" },
cex: "binance"
};

Expand Down Expand Up @@ -281,7 +263,7 @@ const depositAddressRequest = {

// Fetch currency metadata
const fetchCurrencyRequest = {
action: 11, // FetchCurrency
action: 9, // FetchCurrency
payload: {},
cex: "binance",
symbol: "USDT"
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": true,
"includes": ["src/**", "config/**", "policy/**", "test/**", "**/*.ts"]
"includes": ["src/**", "policy/**", "test/**", "scripts/**", "examples/**"]
},
"formatter": {
"enabled": true,
Expand Down
12 changes: 8 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions examples/kraken-orderbook-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import path from "path";
import { SubscriptionType } from "../src/proto/cex_broker/SubscriptionType";
import type { ProtoGrpcType } from "../src/proto/node";
import type { SubscribeResponse__Output } from "../src/proto/cex_broker/SubscribeResponse";

const PROTO_FILE = "../src/proto/node.proto";

Expand All @@ -18,8 +20,10 @@ const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE), {
oneofs: true,
});

const proto = grpc.loadPackageDefinition(packageDef) as any;
const client = new proto.cexBroker.CexService(
const proto = grpc.loadPackageDefinition(
packageDef,
) as unknown as ProtoGrpcType;
const client = new proto.cex_broker.cex_service(
"localhost:8088",
grpc.credentials.createInsecure(),
);
Expand All @@ -38,7 +42,7 @@ console.log("Press Ctrl+C to stop...\n");
const stream = client.Subscribe(subscribeRequest);
let dataCount = 0;

stream.on("data", (response: any) => {
stream.on("data", (response: SubscribeResponse__Output) => {
dataCount++;

console.clear(); // Clear screen for live updates
Expand Down Expand Up @@ -103,7 +107,7 @@ stream.on("data", (response: any) => {
console.log("\n Press Ctrl+C to stop streaming");
});

stream.on("error", (error: any) => {
stream.on("error", (error: grpc.ServiceError) => {
console.error("Stream error:", error.message);
console.log("Code:", error.code);

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@usherlabs/cex-broker",
"version": "0.1.17",
"version": "0.1.18",
"description": "Unified gRPC API to CEXs by Usher Labs.",
"repository": "git@gitlab.com:usherlabs/cex-broker.git",
"homepage": "https://usher.so/",
Expand Down Expand Up @@ -50,11 +50,12 @@
"dependencies": {
"@grpc/grpc-js": "^1.13.4",
"@grpc/proto-loader": "^0.7.15",
"@usherlabs/ccxt": "^0.0.10",
"@usherlabs/ccxt": "^0.0.12",
"@usherlabs/verity-client": "^0.1.1",
"commander": "^14.0.0",
"joi": "^17.13.3",
"tslog": "^4.9.3",
"protobufjs": "^7.4.0"
"protobufjs": "^7.4.0",
"tslog": "^4.9.3"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
15 changes: 6 additions & 9 deletions scripts/patch-protobufjs.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// scripts/patch-protobufjs.js
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";

const file = resolve(
process.cwd(),
'node_modules/protobufjs/src/field.js'
);
const file = resolve(process.cwd(), "node_modules/protobufjs/src/field.js");

let src = readFileSync(file, 'utf8');
src = src.replace(/gitlookupTypeOrEnum/g, 'lookupTypeOrEnum');
let src = readFileSync(file, "utf8");
src = src.replace(/gitlookupTypeOrEnum/g, "lookupTypeOrEnum");
writeFileSync(file, src);
console.log('✓ protobufjs field.js patched');
console.log("✓ protobufjs field.js patched");
12 changes: 12 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const CCXT_METHODS_WITH_VERITY = [
"fetchBalance",
"fetchDepositAddress",
"fetchDepositAddress",
"fetchDepositAddresses",
"fetchDepositAddressesByNetwork",
"fetchDeposits",
"withdraw",
"fetchFundingHistory",
"fetchWithdrawals",
"fetchWithdrawal",
];
Loading