@stoqey/finnhub
Version:
NodeJS Finhubb wrapper
284 lines • 13.7 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
var chai_1 = require("chai");
var dotenv_1 = __importDefault(require("dotenv"));
var index_1 = __importDefault(require("../../index"));
dotenv_1.default.config();
var finnHubKey = (process && process.env.FINNHUB_KEY) || "";
console.log("finnHubKey", finnHubKey);
var finnhubAPI = new index_1.default(finnHubKey);
var symbol = "AAPL";
/**
* https://finnhub.io/docs/api/symbol-search
*/
describe("Symbol lookup", function () {
it("Query for google and expect result as in docs ", function () { return __awaiter(void 0, void 0, void 0, function () {
var expectedRes, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
expectedRes = {
count: 12,
result: [
{
description: "GLOBAL X MSCI PORTUGAL ETF",
displaySymbol: "PGAL",
symbol: "PGAL",
type: "ETP",
},
{
description: "SHANDONG MOLONG PETROLEUM-H",
displaySymbol: "SHANF",
symbol: "SHANF",
type: "Common Stock",
},
{
description: "ICMTRADER Google Inc",
displaySymbol: "GOOGL/USD",
symbol: "ICMTRADER:152",
type: "US Equities (CFDs)",
},
{
description: "GOLD BOND GROUP LTD/THE",
displaySymbol: "GOLD.TA",
symbol: "GOLD.TA",
type: "Common Stock",
},
{
description: "SDM GROUP HOLDINGS LIMITED",
displaySymbol: "8363.HK",
symbol: "8363.HK",
type: "Common Stock",
},
{
description: "GLOBAL X MSCI PORTUGAL ETF",
displaySymbol: "4GXV.BE",
symbol: "4GXV.BE",
type: "ETP",
},
{
description: "SHANDONG MOLONG PETROLEUM-A",
displaySymbol: "002490.SZ",
symbol: "002490.SZ",
type: "Common Stock",
},
{
description: "SHANDONG MOLONG PETROLEUM-H",
displaySymbol: "PXI.F",
symbol: "PXI.F",
type: "Common Stock",
},
{
description: "BRD-GROUPE SOCIETE GENERALE",
displaySymbol: "0KVH.L",
symbol: "0KVH.L",
type: "Common Stock",
},
{
description: "XINJIANG GUOTONG PIPELINE-A",
displaySymbol: "002205.SZ",
symbol: "002205.SZ",
type: "Common Stock",
},
{
description: "SHANDONG MOLONG PETROLEUM-H",
displaySymbol: "PXI.MU",
symbol: "PXI.MU",
type: "Common Stock",
},
{
description: "SHANDONG MOLONG PETROLEUM-H",
displaySymbol: "PXI.SG",
symbol: "PXI.SG",
type: "Common Stock",
},
],
};
return [4 /*yield*/, finnhubAPI.symbolLookup("google")];
case 1:
res = _a.sent();
// TODO: Find a better way to compare these objects
chai_1.expect(res === null || res === void 0 ? void 0 : res.count).equal(expectedRes.count);
return [2 /*return*/];
}
});
}); });
it("Query for nothing and expect a very big object of size 7218", function () { return __awaiter(void 0, void 0, void 0, function () {
var expectedSize, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
expectedSize = 7218;
return [4 /*yield*/, finnhubAPI.symbolLookup()];
case 1:
res = _a.sent();
chai_1.expect(res === null || res === void 0 ? void 0 : res.count).equal(expectedSize);
return [2 /*return*/];
}
});
}); });
it("Query for empty string and expect a very big object of size 7218", function () { return __awaiter(void 0, void 0, void 0, function () {
var expectedSize, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
expectedSize = 7218;
return [4 /*yield*/, finnhubAPI.symbolLookup("")];
case 1:
res = _a.sent();
chai_1.expect(res === null || res === void 0 ? void 0 : res.count).equal(expectedSize);
return [2 /*return*/];
}
});
}); });
});
describe("Company Profile2", function () {
it("Should get Company Profile for symbol = " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var companyProfile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.companyProfile2({ symbol: symbol })];
case 1:
companyProfile = _a.sent();
chai_1.expect(companyProfile === null || companyProfile === void 0 ? void 0 : companyProfile.country).not.equal("");
return [2 /*return*/];
}
});
}); });
});
describe("Market News", function () {
it("Should return market news only for forex category", function () { return __awaiter(void 0, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.marketNews({ category: "forex" })];
case 1:
res = _a.sent();
res === null || res === void 0 ? void 0 : res.every(function (news) { return chai_1.expect(news).to.have.property("category", "forex"); });
return [2 /*return*/];
}
});
}); });
});
describe("Company News", function () {
it("Should return news only for 1st April for " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var req, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
req = {
symbol: symbol,
from: new Date("2021-04-01"),
to: new Date("2021-04-01"),
};
return [4 /*yield*/, finnhubAPI.companyNews(req)];
case 1:
res = _a.sent();
res === null || res === void 0 ? void 0 : res.every(function (news) { return chai_1.expect(news).to.have.property("related", symbol); });
return [2 /*return*/];
}
});
}); });
});
describe("News Sentiment", function () {
it("Should return news only for " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.newsSentiment(symbol)];
case 1:
res = _a.sent();
chai_1.expect(res).to.have.property("symbol", symbol);
return [2 /*return*/];
}
});
}); });
});
describe("Peers", function () {
it("should get Company peers " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var peers;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.peers(symbol)];
case 1:
peers = _a.sent();
chai_1.expect(peers === null || peers === void 0 ? void 0 : peers.length).greaterThan(0);
return [2 /*return*/];
}
});
}); });
});
describe("Basic Financials", function () {
it("should get Basic Financials for " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var basicFinancialsRes;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.basicFinancials({
symbol: symbol,
metric: "all",
})];
case 1:
basicFinancialsRes = _a.sent();
chai_1.expect(basicFinancialsRes === null || basicFinancialsRes === void 0 ? void 0 : basicFinancialsRes.symbol).to.be.equal(symbol);
return [2 /*return*/];
}
});
}); });
});
describe("Insider Financials", function () {
it("should get Insider Financials for " + symbol, function () { return __awaiter(void 0, void 0, void 0, function () {
var insiderTransactionRes;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, finnhubAPI.insiderTransactions({
symbol: symbol,
})];
case 1:
insiderTransactionRes = _a.sent();
chai_1.expect(insiderTransactionRes === null || insiderTransactionRes === void 0 ? void 0 : insiderTransactionRes.symbol).to.be.equal(symbol);
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=fundamentals.test.js.map