borsapy 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
borsapy/viop.py ADDED
@@ -0,0 +1,162 @@
1
+ """VİOP (Vadeli İşlem ve Opsiyon Piyasası) module for Turkish derivatives market."""
2
+
3
+ from functools import cached_property
4
+
5
+ import pandas as pd
6
+
7
+ from borsapy._providers.viop import get_viop_provider
8
+
9
+ __all__ = ["VIOP"]
10
+
11
+
12
+ class VIOP:
13
+ """
14
+ VİOP (Vadeli İşlem ve Opsiyon Piyasası) data access.
15
+
16
+ Provides access to Turkish derivatives market data including
17
+ futures and options contracts.
18
+
19
+ Data source: İş Yatırım (HTML scraping)
20
+ Note: Data is delayed by ~15 minutes
21
+
22
+ Examples:
23
+ >>> from borsapy import VIOP
24
+ >>> viop = VIOP()
25
+ >>> viop.futures # All futures contracts
26
+ >>> viop.stock_futures # Stock futures only
27
+ >>> viop.options # All options contracts
28
+ """
29
+
30
+ def __init__(self) -> None:
31
+ """Initialize VİOP data accessor."""
32
+ self._provider = get_viop_provider()
33
+
34
+ @cached_property
35
+ def futures(self) -> pd.DataFrame:
36
+ """
37
+ Get all futures contracts.
38
+
39
+ Returns:
40
+ DataFrame with columns:
41
+ - code: Contract code (e.g., F_AKBNK0226)
42
+ - contract: Contract name (e.g., AKBNK Şubat 2026 Vadeli)
43
+ - price: Last price
44
+ - change: Price change
45
+ - volume_tl: Trading volume in TL
46
+ - volume_qty: Trading volume in contracts
47
+ - category: stock, index, currency, or commodity
48
+ """
49
+ return self._provider.get_futures("all")
50
+
51
+ @cached_property
52
+ def stock_futures(self) -> pd.DataFrame:
53
+ """
54
+ Get stock futures contracts (Pay Vadeli İşlem).
55
+
56
+ Returns:
57
+ DataFrame with futures on individual stocks.
58
+ """
59
+ return self._provider.get_futures("stock")
60
+
61
+ @cached_property
62
+ def index_futures(self) -> pd.DataFrame:
63
+ """
64
+ Get index futures contracts (Endeks Vadeli İşlem).
65
+
66
+ Includes XU030, XLBNK, etc.
67
+
68
+ Returns:
69
+ DataFrame with index futures.
70
+ """
71
+ return self._provider.get_futures("index")
72
+
73
+ @cached_property
74
+ def currency_futures(self) -> pd.DataFrame:
75
+ """
76
+ Get currency futures contracts (Döviz Vadeli İşlem).
77
+
78
+ Includes USD/TRY, EUR/TRY, etc.
79
+
80
+ Returns:
81
+ DataFrame with currency futures.
82
+ """
83
+ return self._provider.get_futures("currency")
84
+
85
+ @cached_property
86
+ def commodity_futures(self) -> pd.DataFrame:
87
+ """
88
+ Get commodity futures contracts (Kıymetli Madenler).
89
+
90
+ Includes gold, silver, platinum, palladium.
91
+
92
+ Returns:
93
+ DataFrame with commodity futures.
94
+ """
95
+ return self._provider.get_futures("commodity")
96
+
97
+ @cached_property
98
+ def options(self) -> pd.DataFrame:
99
+ """
100
+ Get all options contracts.
101
+
102
+ Returns:
103
+ DataFrame with columns:
104
+ - code: Contract code
105
+ - contract: Contract name
106
+ - price: Last price
107
+ - change: Price change
108
+ - volume_tl: Trading volume in TL
109
+ - volume_qty: Trading volume in contracts
110
+ - category: stock or index
111
+ """
112
+ return self._provider.get_options("all")
113
+
114
+ @cached_property
115
+ def stock_options(self) -> pd.DataFrame:
116
+ """
117
+ Get stock options contracts (Pay Opsiyon).
118
+
119
+ Returns:
120
+ DataFrame with options on individual stocks.
121
+ """
122
+ return self._provider.get_options("stock")
123
+
124
+ @cached_property
125
+ def index_options(self) -> pd.DataFrame:
126
+ """
127
+ Get index options contracts (Endeks Opsiyon).
128
+
129
+ Returns:
130
+ DataFrame with index options.
131
+ """
132
+ return self._provider.get_options("index")
133
+
134
+ def get_by_symbol(self, symbol: str) -> pd.DataFrame:
135
+ """
136
+ Get all derivatives for a specific underlying symbol.
137
+
138
+ Args:
139
+ symbol: Underlying symbol (e.g., "AKBNK", "THYAO", "XU030")
140
+
141
+ Returns:
142
+ DataFrame with all futures and options for the symbol.
143
+ """
144
+ symbol = symbol.upper()
145
+
146
+ futures = self._provider.get_futures("all")
147
+ options = self._provider.get_options("all")
148
+
149
+ # Filter out empty DataFrames before concat
150
+ dfs = [df for df in [futures, options] if not df.empty]
151
+ if not dfs:
152
+ return pd.DataFrame(columns=["code", "contract", "price", "change", "volume_tl", "volume_qty", "category"])
153
+
154
+ all_data = pd.concat(dfs, ignore_index=True)
155
+
156
+ # Filter by symbol in contract name or code
157
+ mask = (
158
+ all_data["contract"].str.upper().str.contains(symbol, na=False) |
159
+ all_data["code"].str.upper().str.contains(symbol, na=False)
160
+ )
161
+
162
+ return all_data[mask].reset_index(drop=True)