Skip to content

Commit

Permalink
Merge pull request #17 from imxeno/develop
Browse files Browse the repository at this point in the history
A major update to the project
  • Loading branch information
imxeno authored Nov 15, 2022
2 parents d98e47f + bf7d448 commit 26e5330
Show file tree
Hide file tree
Showing 22 changed files with 3,168 additions and 601 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
'@typescript-eslint/no-explicit-any': 'off'
}
};
8 changes: 6 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
src/
.github/
*
!dist/**/*
!package.json
!package-lock.json
!LICENSE
!README.md
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ISC License

Copyright (c) 2018, Piotr Adamczyk
Copyright (c) 2018-2019, Piotr Adamczyk

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
65 changes: 8 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# TradingView Scraper for Node.js

[![npm version](https://img.shields.io/npm/v/tradingview-scraper.svg)](https://npmjs.com/package/tradingview-scraper)
[![dependencies](https://img.shields.io/david/imxeno/tradingview-scraper.svg)](https://david-dm.org/imxeno/tradingview-scraper)
![types](https://img.shields.io/npm/types/tradingview-scraper)
![license](https://img.shields.io/npm/l/tradingview-scraper.svg)

Expand All @@ -11,7 +10,12 @@ _warning: the implementation is a little bit dirty, but hey, it works!_
## Installation

```javascript
# npm
npm install tradingview-scraper
# yarn
yarn add tradingview-scraper
# pnpm
pnpm add tradingview-scraper
```

## Featuring
Expand All @@ -23,68 +27,15 @@ yarn add tradingview-scraper
- HTTP Origin header spoofing so nobody will notice anything suspicious
- okay, let's finally go into the _serious mode_, shall we?

## Constructor
## Usage

```javascript
import { TradingViewAPI } from "tradingview-scraper";
const tv = new TradingViewAPI();
```

### new TradingViewAPI()

In order to request data from TradingView using this library, you need to instantiate a new object of TradingViewAPI. The constructor does not accept any parameters, and starts handling connection to TradingView's servers out of the box.

## Methods

List of all available methods for TradingViewAPI.

### getTicker(ticker)

Loads the data about `ticker` from TradingView.

Parameters:

- `ticker` is a ticker name, either 'pro' or 'short'

Returns a `Promise` which when resolved returns an object representing the current data for `ticker` on TradingView, for example:

```javascript
{ last_retrieved: 2020-11-30T21:04:33.099Z,
ch: -236.23,
chp: -3.05,
current_session: 'market',
description: 'Bitcoin / U.S. dollar',
exchange: 'BITSTAMP',
fractional: false,
high_price: 781523,
is_tradable: true,
low_price: 745221.08,
lp: 751727.46,
minmov: 1,
minmove2: 0,
open_price: 775321.69,
original_name: 'BITSTAMP:BTCUSD',
prev_close_price: 775321.69,
pricescale: 100,
pro_name: 'BITSTAMP:BTCUSD',
short_name: 'BTCUSD',
type: 'bitcoin',
update_mode: 'streaming',
volume: 5167.07349537,
s: 'ok',
last_update: 2020-11-30T21:04:21.842Z,
ask: 752026.56,
bid: 751628.22 }
```

The Promise may be rejected if the request was timed out.
_warning: The request will timeout if the `ticker` does not exist on TradingView. That is an expected behavior._
Coming soon, for now just check [Examples](./examples).

## License

ISC License

Copyright (c) 2018, Piotr Adamczyk
Copyright (c) 2018-2022, Piotr Adamczyk

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
15 changes: 15 additions & 0 deletions examples/bitcoinFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TradingViewAPI } from "../";

const bitcoinSymbol = "BTCUSD";
const tv = new TradingViewAPI();

tv.setup().then(() =>
tv.getTicker(bitcoinSymbol).then((ticker) =>
ticker
.fetch()
.then(console.log)
.then(() => {
tv.cleanup();
})
)
);
24 changes: 24 additions & 0 deletions examples/bitcoinTicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TradingViewAPI } from "../";

const bitcoinSymbol = "BTCUSD";
const tv = new TradingViewAPI();

process.stdout.write("Loading...");

tv.setup().then(() => {
tv.getTicker(bitcoinSymbol).then((ticker) => {
let last = 0;
ticker.on("update", (data) => {
if (data.lp && data.lp !== last) {
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
process.stdout.write(
`[${bitcoinSymbol}] ${last > data.lp ? "-" : "+"} ${data.lp.toFixed(
2
)} `
);
last = data.lp;
}
});
});
});
Loading

0 comments on commit 26e5330

Please sign in to comment.