Skip to content

Commit e7130ca

Browse files
authored
Merge pull request #2 from usherlabs/test/git-action
Readme Edit
2 parents 970631a + c704802 commit e7130ca

File tree

2 files changed

+141
-36
lines changed

2 files changed

+141
-36
lines changed

README.md

Lines changed: 136 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ A high-performance gRPC-based cryptocurrency exchange broker service that provid
88
- **gRPC Interface**: High-performance RPC communication
99
- **Real-time Pricing**: Optimal price discovery across exchanges
1010
- **Balance Management**: Real-time balance checking
11+
- **Order Management**: Create, track, and cancel orders
12+
- **Transfer Operations**: Withdraw funds to external addresses
13+
- **Token Conversion**: Convert between different tokens
1114
- **Policy Enforcement**: Configurable trading and withdrawal limits
1215
- **IP Authentication**: Security through IP whitelisting
1316
- **Type Safety**: Full TypeScript support with generated protobuf types
1417

1518
## Prerequisites
1619

1720
- [Bun](https://bun.sh) (v1.2.17 or higher)
18-
- Node.js (v18 or higher) - for TypeScript support
1921
- API keys for supported exchanges (Binance, Bybit)
2022

2123
## Installation
@@ -56,6 +58,8 @@ BYBIT_API_SECRET=your_bybit_api_secret
5658
ROOCH_CHAIN_ID=BINANCE,BYBIT
5759
```
5860

61+
**Note**: API keys are only required for the exchanges you plan to use. The system will validate that required keys are provided based on the `ROOCH_CHAIN_ID` configuration.
62+
5963
### Policy Configuration
6064

6165
Configure trading policies in `policy/policy.json`:
@@ -64,22 +68,36 @@ Configure trading policies in `policy/policy.json`:
6468
{
6569
"withdraw": {
6670
"rule": {
67-
"networks": ["ARB"],
71+
"networks": ["BEP20", "ARBITRUM"],
6872
"whitelist": ["0x9d467fa9062b6e9b1a46e26007ad82db116c67cb"],
69-
"amounts": {
70-
"ticker": "USDC",
71-
"max": 100000,
72-
"min": 1
73-
}
73+
"amounts": [
74+
{
75+
"ticker": "USDC",
76+
"max": 100000,
77+
"min": 1
78+
},
79+
{
80+
"ticker": "USDT",
81+
"max": 100000,
82+
"min": 1
83+
}
84+
]
7485
}
7586
},
7687
"deposit": {},
7788
"order": {
7889
"rule": {
79-
"markets": ["BINANCE:ARB/USDT", "BYBIT:ARB/USDC"],
90+
"markets": [
91+
"BINANCE:ARB/USDT",
92+
"BYBIT:ARB/USDC",
93+
"BINANCE:ETH/USDT",
94+
"BINANCE:BTC/ETH"
95+
],
8096
"limits": [
8197
{ "from": "USDT", "to": "ETH", "min": 1, "max": 100000 },
82-
{ "from": "ETH", "to": "USDT", "min": 0.5, "max": 5 }
98+
{ "from": "ETH", "to": "USDT", "min": 0.5, "max": 5 },
99+
{ "from": "ARB", "to": "USDC", "min": 1, "max": 1000 },
100+
{ "from": "USDC", "to": "ARB", "min": 1, "max": 10000 }
83101
]
84102
}
85103
}
@@ -111,11 +129,17 @@ bun run build
111129
# Run tests
112130
bun test
113131

114-
# Run tests with coverage
115-
bun test --coverage
116-
117132
# Generate protobuf types
118133
bun run proto-gen
134+
135+
# Format code
136+
bun run format
137+
138+
# Lint code
139+
bun run lint
140+
141+
# Check code (format + lint)
142+
bun run check
119143
```
120144

121145
## API Reference
@@ -163,24 +187,24 @@ Get available balance for a specific currency on a specific exchange.
163187
**Request:**
164188
```protobuf
165189
message BalanceRequest {
166-
string cex_key = 1; // CEX identifier (e.g., "BINANCE", "BYBIT")
167-
string symbol = 2; // Trading pair symbol, e.g. "ARB/USDT"
190+
string cex = 1; // CEX identifier (e.g., "BINANCE", "BYBIT")
191+
string token = 2; // Token symbol, e.g. "USDT"
168192
}
169193
```
170194

171195
**Response:**
172196
```protobuf
173197
message BalanceResponse {
174-
double balance = 1; // Available balance for the symbol
198+
double balance = 1; // Available balance for the token
175199
string currency = 2; // Currency of the balance
176200
}
177201
```
178202

179203
**Example:**
180204
```typescript
181205
const request = {
182-
cex_key: "BINANCE",
183-
symbol: "ARB/USDT"
206+
cex: "BINANCE",
207+
token: "USDT"
184208
};
185209
```
186210

@@ -201,57 +225,113 @@ message DepositConfirmationRequest {
201225
**Response:**
202226
```protobuf
203227
message DepositConfirmationResponse {
204-
double new_balance = 1;
228+
double newBalance = 1;
205229
}
206230
```
207231

208232
### Transfer
209233

210-
Execute a transfer/withdrawal.
234+
Execute a transfer/withdrawal to an external address.
211235

212236
**Request:**
213237
```protobuf
214238
message TransferRequest {
215-
string chain = 1;
216-
string recipient_address = 2;
217-
double amount = 3;
239+
string chain = 1; // Network chain (e.g., "ARBITRUM", "BEP20")
240+
string recipient_address = 2; // Destination address
241+
double amount = 3; // Amount to transfer
242+
string cex = 4; // CEX identifier
243+
string token = 5; // Token symbol
218244
}
219245
```
220246

221247
**Response:**
222248
```protobuf
223249
message TransferResponse {
224250
bool success = 1;
225-
double new_balance = 2;
251+
string transaction_id = 2;
226252
}
227253
```
228254

229255
### Convert
230256

231-
Convert between different tokens.
257+
Convert between different tokens using limit orders.
232258

233259
**Request:**
234260
```protobuf
235261
message ConvertRequest {
236-
string from_token = 1;
237-
string to_token = 2;
238-
double amount = 3;
262+
string from_token = 1; // Source token
263+
string to_token = 2; // Destination token
264+
double amount = 3; // Amount to convert
265+
double price = 4; // Limit price
266+
string cex = 5; // CEX identifier
239267
}
240268
```
241269

242270
**Response:**
243271
```protobuf
244272
message ConvertResponse {
245-
double received_amount = 1;
246-
double new_balance = 2;
273+
string order_id = 3;
274+
}
275+
```
276+
277+
### GetOrderDetails
278+
279+
Get details of a specific order.
280+
281+
**Request:**
282+
```protobuf
283+
message OrderDetailsRequest {
284+
string order_id = 1; // Unique order identifier
285+
string cex = 2; // CEX identifier
286+
}
287+
```
288+
289+
**Response:**
290+
```protobuf
291+
message OrderDetailsResponse {
292+
string order_id = 1; // Unique order identifier
293+
string status = 2; // Current order status
294+
double original_amount = 3; // Original order amount
295+
double filled_amount = 4; // Amount that has been filled
296+
string symbol = 5; // Trading pair symbol
297+
string mode = 6; // Buy or Sell mode
298+
double price = 7; // Order price
299+
}
300+
```
301+
302+
### CancelOrder
303+
304+
Cancel an existing order.
305+
306+
**Request:**
307+
```protobuf
308+
message CancelOrderRequest {
309+
string order_id = 1; // Unique order identifier
310+
string cex = 2; // CEX identifier
311+
}
312+
```
313+
314+
**Response:**
315+
```protobuf
316+
message CancelOrderResponse {
317+
bool success = 1; // Whether cancellation was successful
318+
string final_status = 2; // Final status of the order
247319
}
248320
```
249321

250322
## Security
251323

252324
### IP Authentication
253325

254-
All API calls require IP authentication. Configure allowed IPs in your policy or security layer.
326+
All API calls require IP authentication. Configure allowed IPs in `helpers/index.ts`:
327+
328+
```typescript
329+
const ALLOWED_IPS = [
330+
"127.0.0.1", // localhost
331+
"::1", // IPv6 localhost
332+
// Add your allowed IP addresses here
333+
];
334+
```
255335

256336
### API Key Management
257337

@@ -279,12 +359,20 @@ fietCexBroker/
279359
│ ├── broker.ts # Exchange broker setup
280360
│ └── index.ts # Environment configuration
281361
├── helpers/ # Utility functions
362+
│ └── index.ts # Core helper functions
282363
├── policy/ # Policy configuration
364+
│ └── policy.json # Trading and withdrawal rules
283365
├── proto/ # Protocol buffer definitions
284366
│ ├── fietCexNode/ # Generated TypeScript types
285-
│ └── node.proto # Service definition
367+
│ ├── node.proto # Service definition
368+
│ └── node.ts # Type exports
369+
├── scripts/ # Build scripts
370+
│ └── patch-protobufjs.js
286371
├── index.ts # Main server file
287372
├── types.ts # TypeScript type definitions
373+
├── proto-gen.sh # Protobuf generation script
374+
├── biome.json # Code formatting/linting config
375+
├── bunfig.toml # Bun configuration
288376
└── package.json # Dependencies and scripts
289377
```
290378

@@ -308,14 +396,30 @@ bun test --watch
308396
bun test --coverage
309397
```
310398

399+
## Dependencies
400+
401+
### Core Dependencies
402+
- `@grpc/grpc-js`: gRPC server implementation
403+
- `@grpc/proto-loader`: Protocol buffer loading
404+
- `ccxt`: Cryptocurrency exchange library
405+
- `dotenv`: Environment variable management
406+
- `joi`: Configuration validation
407+
408+
### Development Dependencies
409+
- `@biomejs/biome`: Code formatting and linting
410+
- `@types/bun`: Bun type definitions
411+
- `bun-types`: Additional Bun types
412+
- `husky`: Git hooks
413+
311414
## Contributing
312415

313416
1. Fork the repository
314417
2. Create a feature branch
315418
3. Make your changes
316419
4. Add tests for new functionality
317420
5. Ensure all tests pass
318-
6. Submit a pull request
421+
6. Run `bun run check` to format and lint code
422+
7. Submit a pull request
319423

320424
## License
321425

index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ function getServer(policy: PolicyConfig) {
208208
}
209209

210210
try {
211-
// Placeholder for actual deposit confirmation logic
212-
const newBalance = 1000; // Example balance update
213-
214-
callback(null, { new_balance: newBalance });
211+
console.log(
212+
`[${new Date().toISOString()}] ` +
213+
`Amount ${amount} at ${transactionHash} on chain ${chain}. Paid to ${recipientAddress}`,
214+
);
215+
callback(null, { newBalance: 0 });
215216
} catch (error) {
216217
console.error({ error });
217218
callback(

0 commit comments

Comments
 (0)