我正在嘗試Alpha Vantage在我的 Deno 應用程式中使用 NPM 包。我嘗試使用它的SkyPack版本。但它給了我以下錯誤:
Duplicate identifier 'alpha'.deno-ts(2300)
Unexpected keyword or identifier.
這是我正在使用的代碼:
import alphavantageTs from 'https://cdn.skypack.dev/alphavantage-ts';
export class StockTimeSeries{
alpha = new alphavantageTs ("ASLDVIWXGEWFWNZG");
alpha.stocks.intraday("msft").then((data: any) => {
console.log(data);
});
alpha.stocks.batch(["msft", "aapl"]).then((data: any) => {
console.log(data);
});
alpha.forex.rate("btc", "usd").then((data: any) => {
console.log(data);
});
alpha.crypto.intraday("btc", "usd").then((data: any) => {
console.log(data);
});
alpha.technicals.sma("msft", "daily", 60, "close").then((data: any) => {
console.log(data);
});
alpha.sectors.performance().then((data: any) => {
console.log(data);
});
}
uj5u.com熱心網友回復:
看起來 SkyPack 正在回應401該模塊的子依賴項之一。我什至不確定它是否與 Deno 兼容。
也就是說,這里是模塊的 repo 源,這里是 API 的檔案。看起來它只是一個簡單的 REST API,它通過查詢引數來區分請求,因此您可以使用該模塊作為模板來制作自己的 Deno 客戶端,而無需花費太多精力。我會給你一些入門代碼:
TS游樂場
export type Params = NonNullable<ConstructorParameters<typeof URLSearchParams>[0]>;
class AlphaVantageNS { constructor (protected readonly api: AlaphaVantage) {} }
class Forex extends AlphaVantageNS {
rate (from_currency: string, to_currency: string) {
return this.api.query({
function: 'CURRENCY_EXCHANGE_RATE',
from_currency,
to_currency,
});
}
}
export class AlaphaVantage {
#token: string;
constructor (token: string) {
this.#token = token;
}
async query <Result = any>(params: Params): Promise<Result> {
const url = new URL('https://www.alphavantage.co/query');
const usp = new URLSearchParams(params);
usp.set('apikey', this.#token);
url.search = usp.toString();
const request = new Request(url.href);
const response = await fetch(request);
if (!response.ok) throw new Error('Response not OK');
return response.json();
}
forex = new Forex(this);
}
// Use:
const YOUR_API_KEY = 'demo';
const alpha = new AlaphaVantage(YOUR_API_KEY);
alpha.forex.rate('BTC', 'USD').then(data => console.log(data));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435506.html
標籤:npm 德诺 阿尔法优势 skypack-cdn
上一篇:npm和yarn的不同檔案夾
