Skip to content

Commit 23887d7

Browse files
Merge pull request #20 from usherlabs/FIET-440
Fiet-440
2 parents 4423f70 + a66c405 commit 23887d7

6 files changed

Lines changed: 92 additions & 17 deletions

File tree

bun.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@usherlabs/cex-broker",
3-
"version": "0.1.18",
3+
"version": "0.1.19",
44
"description": "Unified gRPC API to CEXs by Usher Labs.",
55
"repository": "git@gitlab.com:usherlabs/cex-broker.git",
66
"homepage": "https://usher.so/",
@@ -50,7 +50,7 @@
5050
"dependencies": {
5151
"@grpc/grpc-js": "^1.13.4",
5252
"@grpc/proto-loader": "^0.7.15",
53-
"@usherlabs/ccxt": "^0.0.12",
53+
"@usherlabs/ccxt": "^0.0.13",
5454
"@usherlabs/verity-client": "^0.1.1",
5555
"commander": "^14.0.0",
5656
"joi": "^17.13.3",

src/client.dev.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,37 @@ function onClientReady() {
6868
},
6969
);
7070

71-
// Test ExecuteAction for balance
71+
// Test ExecuteAction for Account ID
7272
client.executeAction(
7373
{
74-
cex: "binance",
75-
symbol: "USDT,BTC,ETH",
76-
payload: { type: "spot" },
77-
action: Action.FetchBalances,
74+
cex: "mexc",
75+
action: Action.FetchAccountId,
7876
},
7977
metadata,
8078
(err, result) => {
8179
if (err) {
8280
log.error({ err });
8381
return;
8482
}
85-
log.info("ExecuteAction Balance Result:", { result });
83+
log.info("ExecuteAction Result:", { result: result?.result });
8684
},
8785
);
86+
87+
// // Test ExecuteAction for balance
88+
// client.executeAction(
89+
// {
90+
// cex: "binance",
91+
// symbol: "USDT,BTC,ETH",
92+
// payload: { type: "spot" },
93+
// action: Action.FetchBalances,
94+
// },
95+
// metadata,
96+
// (err, result) => {
97+
// if (err) {
98+
// log.error({ err });
99+
// return;
100+
// }
101+
// log.info("ExecuteAction Balance Result:", { result });
102+
// },
103+
// );
88104
}

src/helpers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const CCXT_METHODS_WITH_VERITY = [
99
"fetchFundingHistory",
1010
"fetchWithdrawals",
1111
"fetchWithdrawal",
12+
"fetchAccountId",
1213
];

src/proto/node.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ enum Action {
5555
FetchTicker=8;
5656
FetchCurrency=9;
5757
Call=10;
58+
FetchAccountId=11;
5859
}

src/server.ts

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,62 @@ export function getServer(
212212
}
213213
break;
214214
}
215+
case Action.FetchAccountId: {
216+
try {
217+
let accountId: string | undefined;
218+
let uid: string | undefined;
219+
220+
const temp_broker = broker as any;
221+
222+
// 1. Bybit-style method?
223+
if (typeof temp_broker.privateGetV5UserQueryApi === "function") {
224+
const query = await temp_broker.privateGetV5UserQueryApi();
225+
if (!query?.id || !query?.userID) {
226+
throw new Error("Invalid response structure from privateGetV5UserQueryApi");
227+
}
228+
accountId = query.id;
229+
uid = query.userID;
230+
// 2. MEXC-style method?
231+
} else if (typeof temp_broker.spotPrivateGetUid === "function") {
232+
const query = await temp_broker.spotPrivateGetUid();
233+
accountId = query.uid;
234+
uid = query.uid;
235+
236+
// 3. Binance-style method?
237+
} else if (typeof temp_broker.privateGetAccount === "function") {
238+
const query = await temp_broker.privateGetAccount();
239+
accountId = query.uid;
240+
uid = query.uid;
241+
242+
// 4. None matched → unsupported exchange
243+
} else {
244+
return callback(
245+
{
246+
code: grpc.status.INTERNAL,
247+
message:
248+
"Error: fetching account ID not supported for this broker",
249+
},
250+
null,
251+
);
252+
}
253+
254+
// Return normalized response
255+
return callback(null, {
256+
proof: verityProof,
257+
result: JSON.stringify({ accountId, uid }),
258+
});
259+
} catch (error) {
260+
log.error(`Error fetching account ID ${cex}:`, error);
261+
callback(
262+
{
263+
code: grpc.status.INTERNAL,
264+
message: `Error fetching account ID from ${cex}`,
265+
},
266+
null,
267+
);
268+
}
269+
break;
270+
}
215271

216272
case Action.Call: {
217273
const callSchema = Joi.object({
@@ -374,15 +430,15 @@ export function getServer(
374430
const depositAddresses =
375431
broker.has.fetchDepositAddress === true
376432
? [
377-
await broker.fetchDepositAddress(symbol, {
378-
network: fetchDepositAddresses.chain,
379-
...(fetchDepositAddresses.params ?? {}),
380-
}),
381-
]
382-
: await broker.fetchDepositAddressesByNetwork(symbol, {
433+
await broker.fetchDepositAddress(symbol, {
383434
network: fetchDepositAddresses.chain,
384435
...(fetchDepositAddresses.params ?? {}),
385-
});
436+
}),
437+
]
438+
: await broker.fetchDepositAddressesByNetwork(symbol, {
439+
network: fetchDepositAddresses.chain,
440+
...(fetchDepositAddresses.params ?? {}),
441+
});
386442

387443
if (depositAddresses.length > 0) {
388444
return callback(null, {

0 commit comments

Comments
 (0)