@usherlabs/cex-broker 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/cli.js +122 -6
- package/dist/index.js +123 -7
- package/dist/index.js.map +4 -4
- package/dist/schemas/action-payloads.d.ts +5 -0
- package/package.json +1 -1
package/dist/commands/cli.js
CHANGED
|
@@ -327896,6 +327896,23 @@ var CancelOrderPayloadSchema = exports_external.object({
|
|
|
327896
327896
|
orderId: exports_external.string().min(1),
|
|
327897
327897
|
params: exports_external.preprocess(parseJsonString, stringNumberRecordSchema).default({})
|
|
327898
327898
|
});
|
|
327899
|
+
var booleanLikeSchema = exports_external.preprocess((value) => {
|
|
327900
|
+
if (typeof value !== "string") {
|
|
327901
|
+
return value;
|
|
327902
|
+
}
|
|
327903
|
+
const normalized = value.trim().toLowerCase();
|
|
327904
|
+
if (["true", "1", "yes"].includes(normalized)) {
|
|
327905
|
+
return true;
|
|
327906
|
+
}
|
|
327907
|
+
if (["false", "0", "no"].includes(normalized)) {
|
|
327908
|
+
return false;
|
|
327909
|
+
}
|
|
327910
|
+
return value;
|
|
327911
|
+
}, exports_external.boolean());
|
|
327912
|
+
var FetchFeesPayloadSchema = exports_external.object({
|
|
327913
|
+
includeAllFees: booleanLikeSchema.optional().default(false),
|
|
327914
|
+
includeFundingFees: booleanLikeSchema.optional()
|
|
327915
|
+
});
|
|
327899
327916
|
|
|
327900
327917
|
// src/server.ts
|
|
327901
327918
|
var packageDef = protoLoader.fromJSON(node_descriptor_default);
|
|
@@ -328078,17 +328095,116 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
328078
328095
|
message: `ValidationError: Symbol required`
|
|
328079
328096
|
}, null);
|
|
328080
328097
|
}
|
|
328098
|
+
const parsedPayload = parsePayload(FetchFeesPayloadSchema, call.request.payload);
|
|
328099
|
+
if (!parsedPayload.success) {
|
|
328100
|
+
return wrappedCallback({
|
|
328101
|
+
code: grpc.status.INVALID_ARGUMENT,
|
|
328102
|
+
message: parsedPayload.message
|
|
328103
|
+
}, null);
|
|
328104
|
+
}
|
|
328105
|
+
const includeAllFees = parsedPayload.data.includeAllFees || parsedPayload.data.includeFundingFees === true;
|
|
328081
328106
|
try {
|
|
328082
328107
|
await broker.loadMarkets();
|
|
328083
|
-
const
|
|
328084
|
-
|
|
328085
|
-
|
|
328086
|
-
|
|
328087
|
-
|
|
328108
|
+
const fetchFundingFees = async (currencyCodes) => {
|
|
328109
|
+
let fundingFeeSource2 = "unavailable";
|
|
328110
|
+
const fundingFeesByCurrency2 = {};
|
|
328111
|
+
if (broker.has.fetchDepositWithdrawFees) {
|
|
328112
|
+
try {
|
|
328113
|
+
const feeMap = await broker.fetchDepositWithdrawFees(currencyCodes);
|
|
328114
|
+
for (const code of currencyCodes) {
|
|
328115
|
+
const feeInfo = feeMap[code];
|
|
328116
|
+
if (!feeInfo) {
|
|
328117
|
+
continue;
|
|
328118
|
+
}
|
|
328119
|
+
const fallbackFee = feeInfo.fee !== undefined || feeInfo.percentage !== undefined ? {
|
|
328120
|
+
fee: feeInfo.fee ?? null,
|
|
328121
|
+
percentage: feeInfo.percentage ?? null
|
|
328122
|
+
} : null;
|
|
328123
|
+
fundingFeesByCurrency2[code] = {
|
|
328124
|
+
deposit: feeInfo.deposit ?? fallbackFee,
|
|
328125
|
+
withdraw: feeInfo.withdraw ?? fallbackFee,
|
|
328126
|
+
networks: feeInfo.networks ?? {}
|
|
328127
|
+
};
|
|
328128
|
+
}
|
|
328129
|
+
if (Object.keys(fundingFeesByCurrency2).length > 0) {
|
|
328130
|
+
fundingFeeSource2 = "fetchDepositWithdrawFees";
|
|
328131
|
+
}
|
|
328132
|
+
} catch (error48) {
|
|
328133
|
+
safeLogError(`Error fetching deposit/withdraw fee map for ${symbol2} from ${cex3}`, error48);
|
|
328134
|
+
}
|
|
328135
|
+
}
|
|
328136
|
+
if (fundingFeeSource2 === "unavailable") {
|
|
328137
|
+
try {
|
|
328138
|
+
const currencies = await broker.fetchCurrencies();
|
|
328139
|
+
for (const code of currencyCodes) {
|
|
328140
|
+
const currency = currencies[code];
|
|
328141
|
+
if (!currency) {
|
|
328142
|
+
continue;
|
|
328143
|
+
}
|
|
328144
|
+
fundingFeesByCurrency2[code] = {
|
|
328145
|
+
deposit: {
|
|
328146
|
+
enabled: currency.deposit ?? null
|
|
328147
|
+
},
|
|
328148
|
+
withdraw: {
|
|
328149
|
+
enabled: currency.withdraw ?? null,
|
|
328150
|
+
fee: currency.fee ?? null,
|
|
328151
|
+
limits: currency.limits?.withdraw ?? null
|
|
328152
|
+
},
|
|
328153
|
+
networks: currency.networks ?? {}
|
|
328154
|
+
};
|
|
328155
|
+
}
|
|
328156
|
+
if (Object.keys(fundingFeesByCurrency2).length > 0) {
|
|
328157
|
+
fundingFeeSource2 = "currencies";
|
|
328158
|
+
}
|
|
328159
|
+
} catch (error48) {
|
|
328160
|
+
safeLogError(`Error fetching currency metadata for fees for ${symbol2} from ${cex3}`, error48);
|
|
328161
|
+
}
|
|
328162
|
+
}
|
|
328163
|
+
return { fundingFeeSource: fundingFeeSource2, fundingFeesByCurrency: fundingFeesByCurrency2 };
|
|
328164
|
+
};
|
|
328165
|
+
const isMarketSymbol = symbol2.includes("/");
|
|
328166
|
+
if (isMarketSymbol) {
|
|
328167
|
+
const market = await broker.market(symbol2);
|
|
328168
|
+
const generalFee = broker.fees ?? null;
|
|
328169
|
+
const feeStatus = broker.fees ? "available" : "unknown";
|
|
328170
|
+
if (!broker.fees) {
|
|
328171
|
+
log.warn(`Fee metadata unavailable for ${cex3}`, { symbol: symbol2 });
|
|
328172
|
+
}
|
|
328173
|
+
if (!includeAllFees) {
|
|
328174
|
+
return wrappedCallback(null, {
|
|
328175
|
+
proof: verityProof,
|
|
328176
|
+
result: JSON.stringify({
|
|
328177
|
+
feeScope: "market",
|
|
328178
|
+
generalFee,
|
|
328179
|
+
feeStatus,
|
|
328180
|
+
market
|
|
328181
|
+
})
|
|
328182
|
+
});
|
|
328183
|
+
}
|
|
328184
|
+
const currencyCodes = Array.from(new Set([market.base, market.quote]));
|
|
328185
|
+
const { fundingFeeSource: fundingFeeSource2, fundingFeesByCurrency: fundingFeesByCurrency2 } = await fetchFundingFees(currencyCodes);
|
|
328186
|
+
return wrappedCallback(null, {
|
|
328187
|
+
proof: verityProof,
|
|
328188
|
+
result: JSON.stringify({
|
|
328189
|
+
feeScope: "market+funding",
|
|
328190
|
+
generalFee,
|
|
328191
|
+
feeStatus,
|
|
328192
|
+
market,
|
|
328193
|
+
fundingFeeSource: fundingFeeSource2,
|
|
328194
|
+
fundingFeesByCurrency: fundingFeesByCurrency2
|
|
328195
|
+
})
|
|
328196
|
+
});
|
|
328088
328197
|
}
|
|
328198
|
+
const tokenCode = symbol2.toUpperCase();
|
|
328199
|
+
const { fundingFeeSource, fundingFeesByCurrency } = await fetchFundingFees([tokenCode]);
|
|
328089
328200
|
return wrappedCallback(null, {
|
|
328090
328201
|
proof: verityProof,
|
|
328091
|
-
result: JSON.stringify({
|
|
328202
|
+
result: JSON.stringify({
|
|
328203
|
+
feeScope: "token",
|
|
328204
|
+
symbol: tokenCode,
|
|
328205
|
+
fundingFeeSource,
|
|
328206
|
+
fundingFeesByCurrency
|
|
328207
|
+
})
|
|
328092
328208
|
});
|
|
328093
328209
|
} catch (error48) {
|
|
328094
328210
|
safeLogError(`Error fetching fees for ${symbol2} from ${cex3}`, error48);
|
package/dist/index.js
CHANGED
|
@@ -290849,6 +290849,23 @@ var CancelOrderPayloadSchema = exports_external.object({
|
|
|
290849
290849
|
orderId: exports_external.string().min(1),
|
|
290850
290850
|
params: exports_external.preprocess(parseJsonString, stringNumberRecordSchema).default({})
|
|
290851
290851
|
});
|
|
290852
|
+
var booleanLikeSchema = exports_external.preprocess((value) => {
|
|
290853
|
+
if (typeof value !== "string") {
|
|
290854
|
+
return value;
|
|
290855
|
+
}
|
|
290856
|
+
const normalized = value.trim().toLowerCase();
|
|
290857
|
+
if (["true", "1", "yes"].includes(normalized)) {
|
|
290858
|
+
return true;
|
|
290859
|
+
}
|
|
290860
|
+
if (["false", "0", "no"].includes(normalized)) {
|
|
290861
|
+
return false;
|
|
290862
|
+
}
|
|
290863
|
+
return value;
|
|
290864
|
+
}, exports_external.boolean());
|
|
290865
|
+
var FetchFeesPayloadSchema = exports_external.object({
|
|
290866
|
+
includeAllFees: booleanLikeSchema.optional().default(false),
|
|
290867
|
+
includeFundingFees: booleanLikeSchema.optional()
|
|
290868
|
+
});
|
|
290852
290869
|
|
|
290853
290870
|
// src/server.ts
|
|
290854
290871
|
var packageDef = protoLoader.fromJSON(node_descriptor_default);
|
|
@@ -291031,17 +291048,116 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl, ot
|
|
|
291031
291048
|
message: `ValidationError: Symbol required`
|
|
291032
291049
|
}, null);
|
|
291033
291050
|
}
|
|
291051
|
+
const parsedPayload = parsePayload(FetchFeesPayloadSchema, call.request.payload);
|
|
291052
|
+
if (!parsedPayload.success) {
|
|
291053
|
+
return wrappedCallback({
|
|
291054
|
+
code: grpc.status.INVALID_ARGUMENT,
|
|
291055
|
+
message: parsedPayload.message
|
|
291056
|
+
}, null);
|
|
291057
|
+
}
|
|
291058
|
+
const includeAllFees = parsedPayload.data.includeAllFees || parsedPayload.data.includeFundingFees === true;
|
|
291034
291059
|
try {
|
|
291035
291060
|
await broker.loadMarkets();
|
|
291036
|
-
const
|
|
291037
|
-
|
|
291038
|
-
|
|
291039
|
-
|
|
291040
|
-
|
|
291061
|
+
const fetchFundingFees = async (currencyCodes) => {
|
|
291062
|
+
let fundingFeeSource2 = "unavailable";
|
|
291063
|
+
const fundingFeesByCurrency2 = {};
|
|
291064
|
+
if (broker.has.fetchDepositWithdrawFees) {
|
|
291065
|
+
try {
|
|
291066
|
+
const feeMap = await broker.fetchDepositWithdrawFees(currencyCodes);
|
|
291067
|
+
for (const code of currencyCodes) {
|
|
291068
|
+
const feeInfo = feeMap[code];
|
|
291069
|
+
if (!feeInfo) {
|
|
291070
|
+
continue;
|
|
291071
|
+
}
|
|
291072
|
+
const fallbackFee = feeInfo.fee !== undefined || feeInfo.percentage !== undefined ? {
|
|
291073
|
+
fee: feeInfo.fee ?? null,
|
|
291074
|
+
percentage: feeInfo.percentage ?? null
|
|
291075
|
+
} : null;
|
|
291076
|
+
fundingFeesByCurrency2[code] = {
|
|
291077
|
+
deposit: feeInfo.deposit ?? fallbackFee,
|
|
291078
|
+
withdraw: feeInfo.withdraw ?? fallbackFee,
|
|
291079
|
+
networks: feeInfo.networks ?? {}
|
|
291080
|
+
};
|
|
291081
|
+
}
|
|
291082
|
+
if (Object.keys(fundingFeesByCurrency2).length > 0) {
|
|
291083
|
+
fundingFeeSource2 = "fetchDepositWithdrawFees";
|
|
291084
|
+
}
|
|
291085
|
+
} catch (error48) {
|
|
291086
|
+
safeLogError(`Error fetching deposit/withdraw fee map for ${symbol2} from ${cex3}`, error48);
|
|
291087
|
+
}
|
|
291088
|
+
}
|
|
291089
|
+
if (fundingFeeSource2 === "unavailable") {
|
|
291090
|
+
try {
|
|
291091
|
+
const currencies = await broker.fetchCurrencies();
|
|
291092
|
+
for (const code of currencyCodes) {
|
|
291093
|
+
const currency = currencies[code];
|
|
291094
|
+
if (!currency) {
|
|
291095
|
+
continue;
|
|
291096
|
+
}
|
|
291097
|
+
fundingFeesByCurrency2[code] = {
|
|
291098
|
+
deposit: {
|
|
291099
|
+
enabled: currency.deposit ?? null
|
|
291100
|
+
},
|
|
291101
|
+
withdraw: {
|
|
291102
|
+
enabled: currency.withdraw ?? null,
|
|
291103
|
+
fee: currency.fee ?? null,
|
|
291104
|
+
limits: currency.limits?.withdraw ?? null
|
|
291105
|
+
},
|
|
291106
|
+
networks: currency.networks ?? {}
|
|
291107
|
+
};
|
|
291108
|
+
}
|
|
291109
|
+
if (Object.keys(fundingFeesByCurrency2).length > 0) {
|
|
291110
|
+
fundingFeeSource2 = "currencies";
|
|
291111
|
+
}
|
|
291112
|
+
} catch (error48) {
|
|
291113
|
+
safeLogError(`Error fetching currency metadata for fees for ${symbol2} from ${cex3}`, error48);
|
|
291114
|
+
}
|
|
291115
|
+
}
|
|
291116
|
+
return { fundingFeeSource: fundingFeeSource2, fundingFeesByCurrency: fundingFeesByCurrency2 };
|
|
291117
|
+
};
|
|
291118
|
+
const isMarketSymbol = symbol2.includes("/");
|
|
291119
|
+
if (isMarketSymbol) {
|
|
291120
|
+
const market = await broker.market(symbol2);
|
|
291121
|
+
const generalFee = broker.fees ?? null;
|
|
291122
|
+
const feeStatus = broker.fees ? "available" : "unknown";
|
|
291123
|
+
if (!broker.fees) {
|
|
291124
|
+
log.warn(`Fee metadata unavailable for ${cex3}`, { symbol: symbol2 });
|
|
291125
|
+
}
|
|
291126
|
+
if (!includeAllFees) {
|
|
291127
|
+
return wrappedCallback(null, {
|
|
291128
|
+
proof: verityProof,
|
|
291129
|
+
result: JSON.stringify({
|
|
291130
|
+
feeScope: "market",
|
|
291131
|
+
generalFee,
|
|
291132
|
+
feeStatus,
|
|
291133
|
+
market
|
|
291134
|
+
})
|
|
291135
|
+
});
|
|
291136
|
+
}
|
|
291137
|
+
const currencyCodes = Array.from(new Set([market.base, market.quote]));
|
|
291138
|
+
const { fundingFeeSource: fundingFeeSource2, fundingFeesByCurrency: fundingFeesByCurrency2 } = await fetchFundingFees(currencyCodes);
|
|
291139
|
+
return wrappedCallback(null, {
|
|
291140
|
+
proof: verityProof,
|
|
291141
|
+
result: JSON.stringify({
|
|
291142
|
+
feeScope: "market+funding",
|
|
291143
|
+
generalFee,
|
|
291144
|
+
feeStatus,
|
|
291145
|
+
market,
|
|
291146
|
+
fundingFeeSource: fundingFeeSource2,
|
|
291147
|
+
fundingFeesByCurrency: fundingFeesByCurrency2
|
|
291148
|
+
})
|
|
291149
|
+
});
|
|
291041
291150
|
}
|
|
291151
|
+
const tokenCode = symbol2.toUpperCase();
|
|
291152
|
+
const { fundingFeeSource, fundingFeesByCurrency } = await fetchFundingFees([tokenCode]);
|
|
291042
291153
|
return wrappedCallback(null, {
|
|
291043
291154
|
proof: verityProof,
|
|
291044
|
-
result: JSON.stringify({
|
|
291155
|
+
result: JSON.stringify({
|
|
291156
|
+
feeScope: "token",
|
|
291157
|
+
symbol: tokenCode,
|
|
291158
|
+
fundingFeeSource,
|
|
291159
|
+
fundingFeesByCurrency
|
|
291160
|
+
})
|
|
291045
291161
|
});
|
|
291046
291162
|
} catch (error48) {
|
|
291047
291163
|
safeLogError(`Error fetching fees for ${symbol2} from ${cex3}`, error48);
|
|
@@ -291877,4 +291993,4 @@ export {
|
|
|
291877
291993
|
CEXBroker as default
|
|
291878
291994
|
};
|
|
291879
291995
|
|
|
291880
|
-
//# debugId=
|
|
291996
|
+
//# debugId=BDBB1E5C42AF2C5464756E2164756E21
|