# tseopt
This library contains code for fetching and processing option data from the Tehran Stock Exchange using various public APIs.
---
## Requirements
### 1. Ensure Python version 3.12 or higher is installed
Check if Python is installed and available from the command line by running:
```bash
python3 --version # Unix/macOS
```
or
```bash
py --version # Windows
```
If you do not have Python, please install the **latest** 3.x version from python.org
### 2. Ensure you can run pip from the command line
```bash
python3 -m pip --version # Unix/macOS
```
or
```bash
py -m pip --version # Windows
```
If pip isn’t already installed, then first try to bootstrap it from the standard library:
```bash
python3 -m ensurepip --default-pip # Unix/macOS
```
or
```bash
py -m ensurepip --default-pip # Windows
```
### 3. Ensure pip, setuptools, and wheel are up to date
```bash
python3 -m pip install --upgrade pip setuptools wheel # Unix/macOS
```
or
```bash
py -m pip install --upgrade pip setuptools wheel # Windows
```
---
## Installation
Use the package manager pip to install `tseopt`.
```bash
pip install tseopt
```
## Usage
##### For a better view of the output data, please refer to `README.ipynb`.
### TSETMC Website API
Fetches all Bourse and FaraBours data (suitable for screening the total market).
```python
from tseopt import get_all_options_data
entire_option_market_data = get_all_options_data()
print(entire_option_market_data.head(5))
print(entire_option_market_data.iloc[0])
```
### Screen Market
```python
import pandas as pd
from tseopt.use_case.screen_market import OptionMarket, convert_to_billion_toman
option_market = OptionMarket(entire_option_market_data=entire_option_market_data)
print(f"total_trade_value: {option_market.total_trade_value / 1e10:.0f} B Toman", end="\n\n")
most_trade_value_calls = pd.DataFrame(option_market.most_trade_value.get("call"))
most_trade_value_calls['ticker'] = most_trade_value_calls['ticker'].astype(str)
most_trade_value_calls["trades_value"] = convert_to_billion_toman(most_trade_value_calls["trades_value"])
most_trade_value_puts = pd.DataFrame(option_market.most_trade_value.get("put"))
most_trade_value_puts['ticker'] = most_trade_value_puts['ticker'].astype(str)
most_trade_value_puts["trades_value"] = convert_to_billion_toman(most_trade_value_puts["trades_value"])
most_trade_value_by_underlying_asset = pd.DataFrame(option_market.most_trade_value_by_underlying_asset)
most_trade_value_by_underlying_asset[["call", "put", "total"]] =convert_to_billion_toman(most_trade_value_by_underlying_asset[["call", "put", "total"]])
print(most_trade_value_calls)
print(most_trade_value_puts)
print(most_trade_value_by_underlying_asset)
```
### Tadbir API
Provides low latency and more detailed data (such as initial margin and order book). This may be suitable for obtaining data for actual trading.
```python
from tseopt import tadbir_api
isin_list = ["IRO9AHRM2501", "IROATVAF0621", "IRO9BMLT2771", "IRO9TAMN8991", "IRO9IKCO81M1"]
bulk_data = tadbir_api.get_last_bulk_data(isin_list=isin_list)
detail_data = tadbir_api.get_detail_data(isin_list[0])
symbol_info = detail_data.get("symbol_info")
order_book = pd.DataFrame(detail_data.get("order_book"))
print(bulk_data)
print(symbol_info)
print(order_book)
```
### Mercantile Exchange
Fetches all data which mercantile exchange website provides.
```python
from tseopt import make_a_mercantile_data_object
md = make_a_mercantile_data_object()
md.update_data(timeout=20)
print(md.gavahi[0])
print(md.sandoq[0])
print(md.salaf[0])
print(md.future[0])
print(md.markets_info[0])
print(md.cdc[0])
print(md.all_market)
print(md.future_date_time)
```
### Technical Terms
| English Word | Farsi Translation |
|-----------------------|-----------------------------|
| ua_tse_code | کد نماد دارایی پایه |
| ua_ticker | نماد معاملاتی دارایی پایه |
| days_to_maturity | روزهای باقیمانده تا سررسید |
| strike_price | قیمت اعمال |
| contract_size | اندازه قرارداد |
| ua_close_price | قیمت پایانی دارایی پایه |
| ua_yesterday_price | قیمت روز گذشته دارایی پایه |
| begin_date | تاریخ شروع قرارداد |
| end_date | تاریخ سررسید قرارداد |
| tse_code | کد نماد آپشن |
| ticker | نماد معاملاتی آپشن |
| trades_num | تعداد معاملات آپشن |
| trades_volume | حجم معاملات آپشن |
| trades_value | ارزش معاملات آپشن |
| last_price | آخرین قیمت آپشن |
| close_price | قیمت پایانی آپشن |
| yesterday_price | قیمت روز گذشته آپشن |
| open_positions | موقعیتهای باز |
| yesterday_open_positions | موقعیتهای باز روز گذشته |
| notional_value | ارزش اسمی |
| bid_price | قیمت پیشنهادی خرید |
| bid_volume | حجم پیشنهادی خرید |
| ask_price | قیمت پیشنهادی فروش |
| ask_volume | حجم پیشنهادی فروش |
## Contributing
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
## License
[MIT](https://choosealicense.com/licenses/mit/)
Raw data
{
"_id": null,
"home_page": "https://github.com/masoudghah/TSELiveOptionData",
"name": "tseopt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "tse options tehran derivative",
"author": "Masoud Ghahremani",
"author_email": "p.masoud.ghahremani@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/92/60/cf96089ed1a6073e68faa353895f27a0e65a3c5a6e3275c953ad3f877da0/tseopt-0.1.1.tar.gz",
"platform": null,
"description": "# tseopt\r\n\r\nThis library contains code for fetching and processing option data from the Tehran Stock Exchange using various public APIs.\r\n\r\n---\r\n## Requirements\r\n### 1. Ensure Python version 3.12 or higher is installed\r\n\r\nCheck if Python is installed and available from the command line by running:\r\n\r\n```bash\r\npython3 --version # Unix/macOS\r\n```\r\nor\r\n```bash\r\npy --version # Windows\r\n```\r\nIf you do not have Python, please install the **latest** 3.x version from python.org \r\n\r\n\r\n### 2. Ensure you can run pip from the command line\r\n\r\n```bash\r\npython3 -m pip --version # Unix/macOS\r\n```\r\nor\r\n\r\n```bash\r\npy -m pip --version # Windows\r\n```\r\n\r\nIf pip isn\u2019t already installed, then first try to bootstrap it from the standard library:\r\n```bash\r\npython3 -m ensurepip --default-pip # Unix/macOS\r\n```\r\nor\r\n\r\n```bash\r\npy -m ensurepip --default-pip # Windows\r\n```\r\n\r\n\r\n### 3. Ensure pip, setuptools, and wheel are up to date\r\n\r\n```bash\r\npython3 -m pip install --upgrade pip setuptools wheel # Unix/macOS\r\n```\r\nor\r\n```bash\r\npy -m pip install --upgrade pip setuptools wheel # Windows\r\n```\r\n---\r\n\r\n## Installation\r\n\r\nUse the package manager pip to install `tseopt`.\r\n\r\n```bash\r\npip install tseopt\r\n```\r\n\r\n## Usage\r\n##### For a better view of the output data, please refer to `README.ipynb`.\r\n\r\n\r\n### TSETMC Website API\r\nFetches all Bourse and FaraBours data (suitable for screening the total market).\r\n```python\r\nfrom tseopt import get_all_options_data\r\n\r\nentire_option_market_data = get_all_options_data()\r\nprint(entire_option_market_data.head(5))\r\nprint(entire_option_market_data.iloc[0])\r\n\r\n```\r\n\r\n### Screen Market\r\n\r\n```python\r\nimport pandas as pd\r\nfrom tseopt.use_case.screen_market import OptionMarket, convert_to_billion_toman\r\n\r\noption_market = OptionMarket(entire_option_market_data=entire_option_market_data)\r\n\r\nprint(f\"total_trade_value: {option_market.total_trade_value / 1e10:.0f} B Toman\", end=\"\\n\\n\")\r\n\r\nmost_trade_value_calls = pd.DataFrame(option_market.most_trade_value.get(\"call\"))\r\nmost_trade_value_calls['ticker'] = most_trade_value_calls['ticker'].astype(str)\r\nmost_trade_value_calls[\"trades_value\"] = convert_to_billion_toman(most_trade_value_calls[\"trades_value\"])\r\n\r\n\r\nmost_trade_value_puts = pd.DataFrame(option_market.most_trade_value.get(\"put\"))\r\nmost_trade_value_puts['ticker'] = most_trade_value_puts['ticker'].astype(str)\r\nmost_trade_value_puts[\"trades_value\"] = convert_to_billion_toman(most_trade_value_puts[\"trades_value\"])\r\n\r\n\r\nmost_trade_value_by_underlying_asset = pd.DataFrame(option_market.most_trade_value_by_underlying_asset)\r\nmost_trade_value_by_underlying_asset[[\"call\", \"put\", \"total\"]] =convert_to_billion_toman(most_trade_value_by_underlying_asset[[\"call\", \"put\", \"total\"]])\r\n\r\n\r\nprint(most_trade_value_calls)\r\nprint(most_trade_value_puts)\r\nprint(most_trade_value_by_underlying_asset)\r\n\r\n```\r\n\r\n### Tadbir API\r\nProvides low latency and more detailed data (such as initial margin and order book). This may be suitable for obtaining data for actual trading.\r\n```python\r\nfrom tseopt import tadbir_api\r\n\r\nisin_list = [\"IRO9AHRM2501\", \"IROATVAF0621\", \"IRO9BMLT2771\", \"IRO9TAMN8991\", \"IRO9IKCO81M1\"]\r\n\r\nbulk_data = tadbir_api.get_last_bulk_data(isin_list=isin_list)\r\ndetail_data = tadbir_api.get_detail_data(isin_list[0])\r\nsymbol_info = detail_data.get(\"symbol_info\")\r\norder_book = pd.DataFrame(detail_data.get(\"order_book\"))\r\n\r\nprint(bulk_data)\r\n\r\nprint(symbol_info)\r\nprint(order_book)\r\n\r\n```\r\n\r\n### Mercantile Exchange\r\nFetches all data which mercantile exchange website provides.\r\n```python\r\nfrom tseopt import make_a_mercantile_data_object\r\n\r\n\r\nmd = make_a_mercantile_data_object()\r\nmd.update_data(timeout=20)\r\nprint(md.gavahi[0])\r\nprint(md.sandoq[0])\r\nprint(md.salaf[0])\r\nprint(md.future[0])\r\nprint(md.markets_info[0])\r\nprint(md.cdc[0])\r\nprint(md.all_market)\r\nprint(md.future_date_time)\r\n\r\n```\r\n\r\n### Technical Terms\r\n\r\n\r\n| English Word | Farsi Translation |\r\n|-----------------------|-----------------------------|\r\n| ua_tse_code | \u06a9\u062f \u0646\u0645\u0627\u062f \u062f\u0627\u0631\u0627\u06cc\u06cc \u067e\u0627\u06cc\u0647 |\r\n| ua_ticker | \u0646\u0645\u0627\u062f \u0645\u0639\u0627\u0645\u0644\u0627\u062a\u06cc \u062f\u0627\u0631\u0627\u06cc\u06cc \u067e\u0627\u06cc\u0647 |\r\n| days_to_maturity | \u0631\u0648\u0632\u0647\u0627\u06cc \u0628\u0627\u0642\u06cc\u200c\u0645\u0627\u0646\u062f\u0647 \u062a\u0627 \u0633\u0631\u0631\u0633\u06cc\u062f |\r\n| strike_price | \u0642\u06cc\u0645\u062a \u0627\u0639\u0645\u0627\u0644 |\r\n| contract_size | \u0627\u0646\u062f\u0627\u0632\u0647 \u0642\u0631\u0627\u0631\u062f\u0627\u062f |\r\n| ua_close_price | \u0642\u06cc\u0645\u062a \u067e\u0627\u06cc\u0627\u0646\u06cc \u062f\u0627\u0631\u0627\u06cc\u06cc \u067e\u0627\u06cc\u0647 |\r\n| ua_yesterday_price | \u0642\u06cc\u0645\u062a \u0631\u0648\u0632 \u06af\u0630\u0634\u062a\u0647 \u062f\u0627\u0631\u0627\u06cc\u06cc \u067e\u0627\u06cc\u0647 |\r\n| begin_date | \u062a\u0627\u0631\u06cc\u062e \u0634\u0631\u0648\u0639 \u0642\u0631\u0627\u0631\u062f\u0627\u062f |\r\n| end_date | \u062a\u0627\u0631\u06cc\u062e \u0633\u0631\u0631\u0633\u06cc\u062f \u0642\u0631\u0627\u0631\u062f\u0627\u062f |\r\n| tse_code | \u06a9\u062f \u0646\u0645\u0627\u062f \u0622\u067e\u0634\u0646 |\r\n| ticker | \u0646\u0645\u0627\u062f \u0645\u0639\u0627\u0645\u0644\u0627\u062a\u06cc \u0622\u067e\u0634\u0646 |\r\n| trades_num | \u062a\u0639\u062f\u0627\u062f \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u0622\u067e\u0634\u0646 |\r\n| trades_volume | \u062d\u062c\u0645 \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u0622\u067e\u0634\u0646 |\r\n| trades_value | \u0627\u0631\u0632\u0634 \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u0622\u067e\u0634\u0646 |\r\n| last_price | \u0622\u062e\u0631\u06cc\u0646 \u0642\u06cc\u0645\u062a \u0622\u067e\u0634\u0646 |\r\n| close_price | \u0642\u06cc\u0645\u062a \u067e\u0627\u06cc\u0627\u0646\u06cc \u0622\u067e\u0634\u0646 |\r\n| yesterday_price | \u0642\u06cc\u0645\u062a \u0631\u0648\u0632 \u06af\u0630\u0634\u062a\u0647 \u0622\u067e\u0634\u0646 |\r\n| open_positions | \u0645\u0648\u0642\u0639\u06cc\u062a\u200c\u0647\u0627\u06cc \u0628\u0627\u0632 |\r\n| yesterday_open_positions | \u0645\u0648\u0642\u0639\u06cc\u062a\u200c\u0647\u0627\u06cc \u0628\u0627\u0632 \u0631\u0648\u0632 \u06af\u0630\u0634\u062a\u0647 |\r\n| notional_value | \u0627\u0631\u0632\u0634 \u0627\u0633\u0645\u06cc |\r\n| bid_price | \u0642\u06cc\u0645\u062a \u067e\u06cc\u0634\u0646\u0647\u0627\u062f\u06cc \u062e\u0631\u06cc\u062f |\r\n| bid_volume | \u062d\u062c\u0645 \u067e\u06cc\u0634\u0646\u0647\u0627\u062f\u06cc \u062e\u0631\u06cc\u062f |\r\n| ask_price | \u0642\u06cc\u0645\u062a \u067e\u06cc\u0634\u0646\u0647\u0627\u062f\u06cc \u0641\u0631\u0648\u0634 |\r\n| ask_volume | \u062d\u062c\u0645 \u067e\u06cc\u0634\u0646\u0647\u0627\u062f\u06cc \u0641\u0631\u0648\u0634 |\r\n\r\n\r\n## Contributing\r\n\r\nPull requests are welcome. For major changes, please open an issue first\r\nto discuss what you would like to change.\r\n\r\n## License\r\n\r\n[MIT](https://choosealicense.com/licenses/mit/)\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "This library contains code for fetching and processing option data from the Tehran Stock Exchange using various public APIs.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/masoudghah/TSELiveOptionData"
},
"split_keywords": [
"tse",
"options",
"tehran",
"derivative"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b02ee2ade28f458cc098edeb66d33a9712c50b33545db0e183efa2330c558604",
"md5": "eb4773870a6be97f406891c2e2c37d2e",
"sha256": "05052b97b34991e290cba6f1cda2df284dfdcee762bbe4d997ae64d20cc888f6"
},
"downloads": -1,
"filename": "tseopt-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eb4773870a6be97f406891c2e2c37d2e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 15760,
"upload_time": "2024-12-02T19:08:59",
"upload_time_iso_8601": "2024-12-02T19:08:59.057902Z",
"url": "https://files.pythonhosted.org/packages/b0/2e/e2ade28f458cc098edeb66d33a9712c50b33545db0e183efa2330c558604/tseopt-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9260cf96089ed1a6073e68faa353895f27a0e65a3c5a6e3275c953ad3f877da0",
"md5": "bd91b12f9cc026714360bc889ab5e76d",
"sha256": "7b0c6d76a86562e233a6f7922eddb4e75cb6aa88caf4649c1cd5bf0aa973a45d"
},
"downloads": -1,
"filename": "tseopt-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "bd91b12f9cc026714360bc889ab5e76d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 15120,
"upload_time": "2024-12-02T19:09:00",
"upload_time_iso_8601": "2024-12-02T19:09:00.369427Z",
"url": "https://files.pythonhosted.org/packages/92/60/cf96089ed1a6073e68faa353895f27a0e65a3c5a6e3275c953ad3f877da0/tseopt-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 19:09:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "masoudghah",
"github_project": "TSELiveOptionData",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pandas",
"specs": [
[
"==",
"2.2.2"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.32.3"
]
]
},
{
"name": "fake-useragent",
"specs": [
[
"==",
"1.5.1"
]
]
}
],
"lcname": "tseopt"
}