Skip to content

Commit f0065a9

Browse files
committed
include a FetchCurrency, but is more of a test - as a direct call provides full currency list supported by the exchange.
1 parent f0e5bfd commit f0065a9

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ message ActionResponse {
212212
- `FetchDepositAddresses` (8): Get deposit addresses for a token/network
213213
- `FetchTicker` (9): Get ticker information
214214
- `Call` (10): Generic method invocation on the underlying broker instance. Provide `functionName`, optional `args` array, and optional `params` object.
215+
- `FetchCurrency` (11): Get currency metadata (networks, fees, etc.) for a symbol
215216

216217
**Example Usage:**
217218

@@ -277,6 +278,14 @@ const depositAddressRequest = {
277278
cex: "binance",
278279
symbol: "USDT"
279280
};
281+
282+
// Fetch currency metadata
283+
const fetchCurrencyRequest = {
284+
action: 11, // FetchCurrency
285+
payload: {},
286+
cex: "binance",
287+
symbol: "USDT"
288+
};
280289
```
281290

282291
### Subscribe (Streaming)

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
FetchDepositAddresses=8;
5656
FetchTicker=9;
5757
Call=10;
58+
FetchCurrency=11;
5859
}

src/server.ts

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,45 @@ export function getServer(
166166
break;
167167
}
168168

169+
case Action.FetchCurrency: {
170+
if (!symbol) {
171+
return callback(
172+
{
173+
code: grpc.status.INVALID_ARGUMENT,
174+
message: `ValidationError: Symbol requied`,
175+
},
176+
null,
177+
);
178+
}
179+
try {
180+
const currencies = await broker.fetchCurrencies(symbol);
181+
const currencyInfo = currencies[symbol];
182+
if (!currencyInfo) {
183+
return callback(
184+
{
185+
code: grpc.status.NOT_FOUND,
186+
message: `Currency not found for ${symbol}`,
187+
},
188+
null,
189+
);
190+
}
191+
callback(null, {
192+
proof: broker.last_proof || "",
193+
result: JSON.stringify(currencyInfo),
194+
});
195+
} catch (error) {
196+
log.error(`Error fetching currency ${symbol} from ${cex}:`, error);
197+
callback(
198+
{
199+
code: grpc.status.INTERNAL,
200+
message: `Failed to fetch currency for ${symbol} from ${cex}`,
201+
},
202+
null,
203+
);
204+
}
205+
break;
206+
}
207+
169208
case Action.Call: {
170209
const callSchema = Joi.object({
171210
functionName: Joi.string()
@@ -187,14 +226,19 @@ export function getServer(
187226

188227
// Normalise payload coming from protobuf map<string, string>
189228
// to support JSON-encoded complex types for args/params
190-
const rawPayload = (call.request.payload ?? {}) as Record<string, unknown>;
229+
const rawPayload = (call.request.payload ?? {}) as Record<
230+
string,
231+
unknown
232+
>;
191233
const preparedPayload: Record<string, unknown> = { ...rawPayload };
192234
try {
193235
if (typeof preparedPayload.args === "string") {
194236
preparedPayload.args = JSON.parse(preparedPayload.args as string);
195237
}
196238
if (typeof preparedPayload.params === "string") {
197-
preparedPayload.params = JSON.parse(preparedPayload.params as string);
239+
preparedPayload.params = JSON.parse(
240+
preparedPayload.params as string,
241+
);
198242
}
199243
} catch {
200244
return callback(
@@ -207,9 +251,8 @@ export function getServer(
207251
);
208252
}
209253

210-
const { value: callValue, error: callError } = callSchema.validate(
211-
preparedPayload,
212-
);
254+
const { value: callValue, error: callError } =
255+
callSchema.validate(preparedPayload);
213256

214257
if (callError) {
215258
return callback(
@@ -226,7 +269,10 @@ export function getServer(
226269
const fn = (broker as unknown as Record<string, unknown>)[
227270
callValue.functionName
228271
];
229-
if (typeof fn !== "function" || !broker.has[callValue.functionName]) {
272+
if (
273+
typeof fn !== "function" ||
274+
!broker.has[callValue.functionName]
275+
) {
230276
return callback(
231277
{
232278
code: grpc.status.INVALID_ARGUMENT,
@@ -797,13 +843,11 @@ export function getServer(
797843
const subscriptionType =
798844
type !== undefined ? type : SubscriptionType.ORDERBOOK;
799845

800-
log.info(
801-
`Request - Subscribe:`, {
802-
cex: request.cex,
803-
symbol: request.symbol,
804-
type: subscriptionType,
805-
}
806-
);
846+
log.info(`Request - Subscribe:`, {
847+
cex: request.cex,
848+
symbol: request.symbol,
849+
type: subscriptionType,
850+
});
807851

808852
// Validate required fields
809853
if (!cex || !symbol) {

0 commit comments

Comments
 (0)