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
83 changes: 74 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A high-performance gRPC-based cryptocurrency exchange broker service that provid
1. **Clone the repository:**
```bash
git clone <repository-url>
cd fietCexBroker
cd cex-broker
```

2. **Install dependencies:**
Expand Down Expand Up @@ -147,7 +147,14 @@ Options:
# Start the server
bun run start

# Start broker server (development)
bun run start-broker

# Start broker server with Verity
bun run start-broker-server-with-verity

# Build for production
bun run build
bun run build:ts

# Run tests
Expand All @@ -161,9 +168,11 @@ bun run format

# Lint code
bun run lint
bun run lint:fix

# Check code (format + lint)
bun run check
bun run check:fix
```

## 📡 API Reference
Expand Down Expand Up @@ -194,24 +203,58 @@ message ActionResponse {
**Available Actions:**
- `NoAction` (0): No operation
- `Deposit` (1): Confirm deposit transaction
- `Transfer` (2): Transfer/withdraw funds
- `Withdraw` (2): Withdraw funds
- `CreateOrder` (3): Create a new order
- `GetOrderDetails` (4): Get order information
- `CancelOrder` (5): Cancel an existing order
- `FetchBalance` (6): Get account balance
- `FetchDepositAddresses` (7): Get deposit addresses for a token/network
- `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
- `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
// 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 all balances (free by default)
const allBalancesRequest = {
action: 7, // FetchBalances
payload: {},
cex: "binance"
};

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

// Create order
const orderRequest = {
action: 3, // CreateOrder
Expand All @@ -235,6 +278,14 @@ const depositAddressRequest = {
cex: "binance",
symbol: "USDT"
};

// Fetch currency metadata
const fetchCurrencyRequest = {
action: 11, // FetchCurrency
payload: {},
cex: "binance",
symbol: "USDT"
};
```

### Subscribe (Streaming)
Expand Down Expand Up @@ -366,26 +417,40 @@ const response = await client.ExecuteAction(request, metadata);
### Project Structure

```
fietCexBroker/
cex-broker/
├── src/ # Source code
│ ├── cli.ts # CLI entry point
│ ├── client.dev.ts # Development client
│ ├── commands/ # CLI commands
│ │ └── start-broker.ts # Broker startup command
│ ├── helpers/ # Utility functions
│ │ ├── index.ts # Policy validation helpers
│ │ ├── index.test.ts # Helper tests
│ │ └── logger.ts # Logging configuration
│ ├── index.ts # Main broker class
│ ├── proto/ # Generated protobuf types
│ │ ├── cex_broker/ # Generated broker types
│ │ ├── node.proto # Service definition
│ │ └── node.ts # Type exports
│ ├── server.ts # gRPC server implementation
│ ├── cli.ts # CLI entry point
│ └── types.ts # TypeScript type definitions
├── proto/ # Protocol buffer definitions
│ ├── node.proto # Service definition
│ └── node.ts # Type exports
│ ├── cexBroker/ # Legacy generated types
│ └── node.proto # Service definition
├── policy/ # Policy configuration
│ └── policy.json # Trading and withdrawal rules
├── scripts/ # Build scripts
│ └── patch-protobufjs.js # Protobuf patching script
├── test/ # Test files
├── patches/ # Dependency patches
├── examples/ # Example usage
│ └── kraken-orderbook-demo.ts
├── build.ts # Build configuration
├── proto-gen.sh # Proto generation script
├── test-setup.ts # Test setup
├── tsconfig.json # TypeScript configuration
├── biome.json # Code formatting/linting
├── bunfig.toml # Bun configuration
└── package.json # Dependencies and scripts
```

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/**"]
"includes": ["src/**", "config/**", "policy/**", "test/**", "**/*.ts"]
},
"formatter": {
"enabled": true,
Expand Down
55 changes: 37 additions & 18 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import dts from 'bun-plugin-dts'

import dts from "bun-plugin-dts";

await Bun.build({
entrypoints: ["./src/cli.ts"],
outdir: './dist/commands',
target:"node",
plugins: [
dts()
],
})
entrypoints: ["./src/cli.ts"],
outdir: "./dist/commands",
target: "node",
plugins: [dts()],
});

await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target:"bun",
sourcemap:"external",
plugins: [
// dts()
],
})
entrypoints: ["./src/index.ts"],
outdir: "./dist",
target: "bun",
external: [
"fs",
"path",
"url",
"util",
"stream",
"buffer",
"os",
"events",
"@grpc/grpc-js",
"@grpc/proto-loader",
"protobufjs",
"long",
"@protobufjs/inquire",
],
sourcemap: "external",
plugins: [
// dts()
],
});

// Copy descriptor alongside dist output for runtime import
await Bun.spawn({ cmd: ["mkdir", "-p", "./dist/proto"] }).exited;
await Bun.write(
"./dist/proto/node.descriptor.ts",
await Bun.file("./src/proto/node.descriptor.ts").text(),
);

// Generates `dist/index.d.ts` and `dist/other/foo.d.ts`

console.log('Build complete.')
console.log("Build complete.");
Loading