Skip to content

Commit

Permalink
Merge pull request #16 from harsohailB/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
youup99 authored Apr 30, 2021
2 parents 389ccd6 + 49a7b46 commit 665881f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 20 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
</p>
</p>

## Usage

<p align="center">
<img src="./example/src/assets/images/usage.gif" alt="usage" width="75%"/>
</p>

## Installation

`npm install ticker-symbol-search`
Expand Down Expand Up @@ -84,7 +90,7 @@ where,

### Symbol Data Fetched

Through callback or hook
#### Stock Data Example

```json
{
Expand All @@ -98,6 +104,21 @@ Through callback or hook
}
```

### Types

```javascript
import {
StockSymbol,
FuturesSymbol,
ForexSymbol,
CFDSymbol,
CryptoSymbol,
IndexSymbol,
EconomicSymbol,
SymbolData, // union type of all symbols
} from "ticker-symbol-search";
```

## Development

To develop this package you need to install its dependencies and the dependencies of the example to test your changes
Expand Down
Binary file added example/src/assets/images/usage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"type": "git",
"url": "https://github.com/harsohailB/ticker-symbol-search"
},
"keywords": [
"react",
"typescript",
"library",
"stocks",
"tickers",
"fintech",
"crypto",
"finance",
"search"
],
"bugs": "https://github.com/harsohailB/ticker-symbol-search/issues",
"dependencies": {
"@material-ui/core": "^4.11.3",
Expand Down
22 changes: 9 additions & 13 deletions src/actions/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ import axios from "axios";
import { MarketTypes } from "../types/markets";

export const getSymbols = async (queryParams: SymbolQueryParams) => {
const endpointURL: string = `${config.proxyEndpoint}/${config.endpoint}/${Routes.SYMBOL_SEARCH}/`;
const targetParams: string = `?type=${
queryParams.type === MarketTypes.ALL ? "" : queryParams.type.toLowerCase()
}&text=${queryParams.text}&hl=${
queryParams.hl
}&exchange=&lang=en&domain=production`;

const response = await axios.get(endpointURL, {
params: {
text: queryParams.text,
hl: queryParams.hl,
exchange: "",
type:
queryParams.type === MarketTypes.ALL
? ""
: queryParams.type.toLowerCase(),
lang: "en",
domain: "production",
},
const symbolsEndpoint: string = `${config.endpoint}/${Routes.SYMBOL_SEARCH}`;

const response = await axios.get(config.proxyEndpoint, {
params: { url: symbolsEndpoint + targetParams },
});

if (response.status !== 200) {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { APIConfiguration } from "./types/config";

const protocol: string = "https";
const baseUrl: string = "symbol-search.tradingview.com";
const proxy: string = "thingproxy.freeboard.io/fetch";
const proxy: string = "api.allorigins.win/raw";

export const config: APIConfiguration = {
protocol,
Expand Down
2 changes: 1 addition & 1 deletion src/container/DraggableWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DraggableWrapper = (props: { theme?: Theme; children: JSX.Element }) => {
<ThemeProvider
theme={props.theme ? { ...defaultTheme, ...props.theme } : defaultTheme}
>
<Draggable disabled={isMobile} bounds="parent">
<Draggable disabled={isMobile}>
<Wrapper>{props.children}</Wrapper>
</Draggable>
</ThemeProvider>
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { TickerSymbolSearch } from "./container/TickerSymbolSearch";
export { useSearchSymbols } from "./hooks/useSearchSymbols";
export * from "./types/symbol";
export * from "./types/theme";
47 changes: 43 additions & 4 deletions src/types/symbol.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
export interface SymbolData {
export interface Symbol {
symbol: string;
description: string;
type: string;
exchange: string;
provider_id: string;
typespecs?: string[];
country?: string;
prefix?: string;
}

export interface Contract {
symbol: string;
description: string;
}

export interface StockSymbol extends Symbol {
typespecs: string[];
country: string;
}

export interface FuturesSymbol extends Symbol {
country: string;
contracts: Contract[];
}

export interface ForexSymbol extends Symbol {
prefix: string;
}

export interface CFDSymbol extends Symbol {
country: string;
}

export interface CryptoSymbol extends Symbol {}

export interface IndexSymbol extends Symbol {
country: string;
}

export interface EconomicSymbol extends Symbol {
params: string[];
}

export type SymbolData =
| StockSymbol
| FuturesSymbol
| ForexSymbol
| CFDSymbol
| CryptoSymbol
| IndexSymbol
| EconomicSymbol;

1 comment on commit 665881f

@vercel
Copy link

@vercel vercel bot commented on 665881f Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.