From 08bdb4548561cab8e34722b2f81069547ee37d21 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Tue, 22 Sep 2020 00:10:35 +0300 Subject: [PATCH 1/3] feat: add the `getSymbol` method --- src/rest.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/rest.ts b/src/rest.ts index ab40906..8d3e4a0 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -70,6 +70,13 @@ export interface IGroupId extends IVersion { groupId: string; } +export interface ISymbolIdOptions extends IVersion { + /** + * Financial instrument id + */ + symbolId: string; +} + export interface ILastQuoteOptions extends IVersion { /** * Symbol id or symbol ids @@ -1162,6 +1169,18 @@ export class RestClient { return groups; } + /** + * Get instrument available for authorized user + */ + public async getSymbol({ + version = DefaultAPIVersion, + symbolId, + }: ISymbolIdOptions): Promise { + const url = new URL(`/md/${version}/symbols/${symbolId}`, this.url); + const symbol = (await this.fetch(url)) as IIntrument; + return symbol; + } + /** * Get the last quote */ From dec0b5d361be748a19bbe5d1454179df681b34bb Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Tue, 22 Sep 2020 00:14:03 +0300 Subject: [PATCH 2/3] test: add getSymbol --- test/rest.spec.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/rest.spec.ts b/test/rest.spec.ts index 71beee5..2695b2a 100644 --- a/test/rest.spec.ts +++ b/test/rest.spec.ts @@ -781,6 +781,72 @@ suite("RestClient", () => { assert.deepStrictEqual(symbols, response); }); + test(".getSymbol()", async () => { + const version = "3.0"; + const symbolId = "AAPL.NASDAQ"; + const response: IIntrument = { + ticker: "AAPL", + mpi: "0.01", + id: "AAPL.NASDAQ", + country: "US", + symbolType: "Stock", + exchange: "NASDAQ", + type: "Stock", + expiration: 1503619200000, + minPriceIncrement: "0.01", + currency: "0.01", + i18n: { + property1: "string", + property2: "string", + }, + optionData: { + right: "PUT", + strikePrice: "30.5", + optionRight: "PUT", + optionGroupId: "OZL.CBOT.U2017.P*", + }, + group: "AAPL", + name: "Apple", + symbolId: "AAPL.NASDAQ", + description: "Apple", + }; + + nock(url) + .get(`/md/${version}/symbols/${symbolId}`) + .delay(1) + .reply(200, response); + + const symbol = await client.getSymbol({ version, symbolId }); + assert.deepStrictEqual(symbol, response); + }); + + test(".getSymbol() (with no `version`)", async () => { + const symbolId = "AAPL.NASDAQ"; + const response: IIntrument = { + optionData: null, + i18n: {}, + name: "Apple", + description: "Apple Inc. - Common Stock", + country: "US", + exchange: "NASDAQ", + id: "AAPL.NASDAQ", + currency: "USD", + mpi: "0.01", + type: "STOCK", + ticker: "AAPL", + expiration: null, + group: null, + }; + + nock(url) + .get(`/md/${DefaultAPIVersion}/symbols/${symbolId}`) + .delay(1) + .reply(200, response); + + const symbol = await client.getSymbol({ symbolId }); + assert.deepStrictEqual(symbol, response); + }); + test(".getLastQuote()", async () => { const version = "3.0"; const level = "market_depth" as const; From abd569bd614a1ae82aa67cc7a543bdf7184ef7ea Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Tue, 22 Sep 2020 00:14:54 +0300 Subject: [PATCH 3/3] docs(readme): add getSymbol example --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c8dfadb..6334fbb 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,14 @@ const symbol = await client.getGroupNearestSymbol({ version, groupId }); const symbols = await client.getSymbols(); ``` +- [`getSymbol`](https://api-live.exante.eu/api-docs/#operation/getSymbol) + +```typescript +const version = "3.0"; +const symbolId = "AAPL.NASDAQ"; +const symbol = await client.getSymbol({ version, symbolId }); +``` + - [`getLastQuote`](https://api-live.exante.eu/api-docs/#operation/getQuoteLast) ```typescript