@davoodmehraban89 / VELYQOR / commits / de580fe
Fork 0

Intelligence, Advanced Charting & Trading Platform

feat(feed): explicit provider capability registry and bounded REST request builders

davoodmehraban89 committed Oct 12, 2026 at 00:22 UTC de580fe1f775b86034d186ac136d0e747588e287
1 file changed +44
packages/market-feed/src/providers.mjs new
+44
@@ -0,0 +1,44 @@
1 +// Provider capabilities are intentionally advisory; a provider being named here
2 +// does not authorize commercial storage or redistribution.
3 +export const PROVIDERS=Object.freeze({
4 + coingecko:Object.freeze({region:"crypto",history:"reference_point",live:"poll",permission:"review_required",status:"not_connected"}),
5 + binance:Object.freeze({region:"crypto",history:"source_ohlc",live:"exchange_websocket",permission:"review_required",status:"network_blocked_prior_451"}),
6 + yfinance:Object.freeze({region:"global",history:"source_ohlc",live:"none",permission:"research_only",status:"research_adapter_only"}),
7 + polygon:Object.freeze({region:"global",history:"licensed_contract",live:"vendor_websocket",permission:"subscription_required",status:"not_connected"}),
8 + navasan:Object.freeze({region:"iran",history:"source_ohlc",live:"rest_poll",permission:"commercial_rights_unverified",status:"adapter_exists_not_licensed_for_publication"}),
9 + bonbast:Object.freeze({region:"iran",history:"unverified",live:"unverified",permission:"contract_required",status:"api_not_verified"}),
10 +});
11 +function int(x,label){if(!Number.isSafeInteger(x)||x<=0)throw Error(label+" must be positive integer")}
12 +function utcWindow(startMs,endMs){
13 + int(startMs,"startMs");int(endMs,"endMs");
14 + if(startMs>=endMs||endMs>Date.now()+60_000)throw Error("invalid historical time window");
15 +}
16 +export function coinGeckoRangeRequest({coinId,quote="usd",startMs,endMs}){
17 + utcWindow(startMs,endMs);
18 + if(typeof coinId!=="string"||!/^[a-z0-9-]{2,80}$/.test(coinId))throw Error("invalid CoinGecko id");
19 + if(!["usd","eur","btc"].includes(quote))throw Error("unsupported CoinGecko quote");
20 + // 90d slices reduce huge responses; actual coverage/granularity depends on API plan.
21 + if(endMs-startMs>90*86_400_000)throw Error("request exceeds 90-day slice");
22 + const url=new URL("https://api.coingecko.com/api/v3/coins/"+encodeURIComponent(coinId)+"/market_chart/range");
23 + url.searchParams.set("vs_currency",quote);
24 + url.searchParams.set("from",String(Math.floor(startMs/1000)));
25 + url.searchParams.set("to",String(Math.floor(endMs/1000)));
26 + return Object.freeze({url:url.toString(),method:"GET",providerCode:"coingecko",dataKind:"reference_point",
27 + expectedFields:["prices","market_caps","total_volumes"],notCandles:true,requiresServerKey:true,permission:"review_required"});
28 +}
29 +export function binanceKlinesRequest({symbol,interval,startMs,endMs,limit=1000}){
30 + utcWindow(startMs,endMs);
31 + if(typeof symbol!=="string"||!/^[A-Z0-9]{5,24}$/.test(symbol))throw Error("invalid Binance pair");
32 + if(!["1h","1d"].includes(interval))throw Error("unsupported Binance interval");
33 + int(limit,"limit");
34 + if(limit>1000)throw Error("Binance limit exceeds one response window");
35 + const url=new URL("https://api.binance.com/api/v3/klines");
36 + for(const [k,v] of Object.entries({symbol,interval,startTime:startMs,endTime:endMs,limit}))url.searchParams.set(k,String(v));
37 + return Object.freeze({url:url.toString(),method:"GET",providerCode:"binance",dataKind:"source_ohlc",
38 + requiresCommercialLicensingReview:true,needsNetworkProbe:true,permission:"review_required"});
39 +}
40 +export function providerCanPubliclyRedistribute(providerCode){
41 + if(!Object.hasOwn(PROVIDERS,providerCode))throw Error("unknown provider");
42 + // Must be enabled per contract and instrument; no provider is authorized by default.
43 + return false;
44 +}