Skip to content

Commit

Permalink
Merge pull request #37 from b2broker/get_symbol
Browse files Browse the repository at this point in the history
Get symbol
  • Loading branch information
vansergen authored Sep 21, 2020
2 parents beaf83e + abd569b commit 7125d5f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1162,6 +1169,18 @@ export class RestClient {
return groups;
}

/**
* Get instrument available for authorized user
*/
public async getSymbol({
version = DefaultAPIVersion,
symbolId,
}: ISymbolIdOptions): Promise<IIntrument> {
const url = new URL(`/md/${version}/symbols/${symbolId}`, this.url);
const symbol = (await this.fetch(url)) as IIntrument;
return symbol;
}

/**
* Get the last quote
*/
Expand Down
66 changes: 66 additions & 0 deletions test/rest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7125d5f

Please sign in to comment.