0.1.6 • Published 4 years ago

tse-browser-client v0.1.6

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

Usage:

Using standalone version: (bundled with the 3 dependencies)

<script src="https://cdn.jsdelivr.net/npm/tse-browser-client/dist/tse.bundle.min.js"></script>
<script>
  (async function () {
    const data = await tse.getPrices(['ذوب', 'فولاد']);
    const adjustedData = await tse.getPrices(['خساپا'], {adjustPrices: 1});
  
    const customCols1 = await tse.getPrices(['شپنا'], {columns: [4,7,8]}); // default names
    const customCols2 = await tse.getPrices(['شپنا'], {columns: [[4,'DATE'],[7,'MAX'],[8,'MIN']]}); // custom names
    
    console.table(tse.columnList); // view column indexes and their names
  })();
</script>

Using unbundled version: (the 3 dependencies must be loaded before)

<script src="https://cdn.jsdelivr.net/npm/big.js"></script>
<script src="path/to/jalaali-js.js"></script>
<script src="https://cdn.jsdelivr.net/npm/localforage"></script>
<script src="https://cdn.jsdelivr.net/npm/tse-browser-client"></script>
<script>
tse.getPrices(['فولاد']).then(([prices]) => console.log(prices));
</script>

Simple PHP proxy example:

// proxy.php
<?php
$t  = isset($_GET['t'])  ? $_GET['t']  : '';
$a  = isset($_GET['a'])  ? $_GET['a']  : '';
$a2 = isset($_GET['a2']) ? $_GET['a2'] : '';

echo file_get_contents("http://service.tsetmc.com/tsev2/data/TseClient2.aspx?t=$t&a=$a&a2=$a2");
?>
tse.API_URL = 'http://path/to/proxy.php';
(async function () {
  const data = await tse.getPrices(['فملی']);
})();

Get jalaali-js for browser: (Windows)

mkdir tmp && cd tmp && npm i jalaali-js && echo module.exports = require('jalaali-js'); > x.js && npx browserify x.js -o ../jalaali-js.js -s jalaali && del x.js && cd ../ && rmdir tmp /s /q

Published files in dist/ | File | Description |------------------------|-----------------------| |dist/tse.js | Unminified code. | |dist/tse.min.js | Minified code. | |dist/tse.bundle.min.js| Minified dependencies + minified code. |


API

MemberDescription
tse.API_URLThe API URL to use for HTTP requests. Only string and valid URL. Default: 'http://service.tsetmc.com/tsev2/data/TseClient2.aspx'
tse.UPDATE_INTERVALUpdate data only if these many days have passed since the last update. Only integers. Default: 1
tse.PRICES_UPDATE_CHUNKAmount of instruments per request. Only integers. Min: 1, Max: 60, Default: 10
tse.PRICES_UPDATE_CHUNK_DELAYAmount of delay (in ms) to wait before requesting another chunk of instruments. Default: 500
tse.PRICES_UPDATE_RETRY_COUNTAmount of retry attempts before giving up. Only integers. Default: 3
tse.PRICES_UPDATE_RETRY_DELAYAmount of delay (in ms) to wait before making another retry. Only integers. Default: 5000
tse.getInstruments()Update (if needed) and return list of instruments. (InstrumentAndShare)
tse.getPrices(symbols=[], ?settings={...})Update (if needed) and return prices of instruments.
const defaultSettings = {
  columns: [
    [4, 'date'],
    [6, 'open'],
    [7, 'high'],
    [8, 'low'],
    [9, 'last'],
    [10, 'close'],
    [12, 'vol']
  ],
  adjustPrices: 0,
  daysWithoutTrade: false,
  startDate: '20010321'
};

const prices = await tse.getPrices(symbols=['sym1', 'sym2', ...], defaultSettings);
/*
  prices: [
    // sym1 prices
    {
      open:  [0, 0, ...],
      high:  [0, 0, ...],
      low:   [0, 0, ...],
      last:  [0, 0, ...]
      close: [0, 0, ...],
      vol:   [0, 0, ...]
    },
    
    // sym2 prices
    {
      open: [],
      high: [],
      ...
    },
    
    ...
  ]
*/
adjustPricesdescdesc fa
0Noneبدون تعدیل
1Share increase and dividendsافزایش سرمایه + سود
2Share increaseافزایش سرمایه

Column indexes: index | name | fname ------|------|------------------ 0 | CompanyCode | کد شرکت 1 | LatinName | نام لاتین 2 | Symbol | نماد 3 | Name | نام 4 | Date | تاریخ میلادی 5 | ShamsiDate | تاریخ شمسی 6 | PriceFirst | اولین قیمت 7 | PriceMax | بیشترین قیمت 8 | PriceMin | کمترین قیمت 9 | LastPrice | آخرین قیمت 10 | ClosingPrice | قیمت پایانی 11 | Price | ارزش 12 | Volume | حجم 13 | Count | تعداد معاملات

14 | PriceYesterday | قیمت دیروز

Notes

DependencyWhy
big.jsFor price adjustment calculations.
jalaali-jsOnly needed due to the ShamsiDate column.
localforageFor storing in indexedDB.
0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago