pyarrow-client 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Arrow Trading
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,490 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyarrow-client
3
+ Version: 1.0.0
4
+ Summary: Python SDK for Arrow Trading API
5
+ Author-email: Abhishek Jain <abhishek.jain@irage.in>, Shubham Jain <shubham.j@irage.in>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/arrowtech/py-arrow
8
+ Project-URL: Bug Tracker, https://github.com/arrowtech/py-arrow/issues
9
+ Project-URL: Documentation, https://docs.arrow.trade
10
+ Project-URL: Source, https://github.com/arrowtech/py-arrow
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.25.0
15
+ Requires-Dist: websocket-client>=1.0.0
16
+ Requires-Dist: pyotp>=2.6.0
17
+ Requires-Dist: python-dateutil>=2.8.0
18
+ Requires-Dist: urllib3>=1.26.0
19
+ Dynamic: license-file
20
+
21
+ # ArrowConnect – Official Python Client for Arrow Trading API
22
+
23
+ [![PyPI version](https://badge.fury.io/py/arrowconnect.svg)](https://badge.fury.io/py/arrowconnect)
24
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
25
+ [![Python Versions](https://img.shields.io/pypi/pyversions/arrowconnect.svg)](https://pypi.org/project/arrowconnect/)
26
+ [![Downloads](https://pepy.tech/badge/arrowconnect)](https://pepy.tech/project/arrowconnect)
27
+
28
+ **ArrowConnect** is the official Python SDK for the Arrow Trading Platform, providing comprehensive access to trading APIs, real-time market data, and order management capabilities. Built for traders, quants, and fintech developers who need reliable, high-performance access to Indian financial markets.
29
+
30
+ ## 🚀 Key Features
31
+
32
+ ### 📊 **Market Data & Analytics**
33
+ - Real-time quotes, OHLC, LTP, and market depth
34
+ - Historical data retrieval and analysis
35
+ - Option chain data and expiry information
36
+ - Market holidays and trading calendars
37
+ - Index listings and sector data
38
+
39
+ ### 💼 **Order Management**
40
+ - Place, modify, and cancel orders across exchanges
41
+ - Support for all order types (Market, Limit, SL, SL-M)
42
+ - Bracket orders and cover orders
43
+ - AMO (After Market Orders) support
44
+ - Real-time order status tracking
45
+
46
+ ### 📡 **Real-time Streaming**
47
+ - WebSocket-based live market data feeds
48
+ - Order and position update streams
49
+ - Multiple subscription modes (LTPC, Quote, Full)
50
+ - Automatic reconnection with exponential backoff
51
+ - Thread-safe event handling
52
+
53
+ ### 🔐 **Authentication & Security**
54
+ - OAuth-based authentication flow
55
+ - TOTP (Time-based OTP) integration
56
+ - Automatic session management
57
+ - Token refresh and validation
58
+
59
+ ---
60
+
61
+ ## 📦 Installation
62
+
63
+ ```bash
64
+ pip install arrowconnect
65
+ ```
66
+
67
+ **Requirements:**
68
+ - Python 3.7+
69
+ - `requests`, `websocket-client`, `pyotp`, `py-arrow`
70
+
71
+ ---
72
+
73
+ ## 🏃‍♂️ Quick Start
74
+
75
+ ### Authentication
76
+
77
+ ```python
78
+ from arrowconnect import ArrowClient
79
+
80
+ # Initialize client
81
+ client = ArrowClient(app_id="your_app_id")
82
+
83
+ # Method 1: Manual login (web-based)
84
+ login_url = client.login_url()
85
+ print(f"Visit: {login_url}")
86
+ # After authorization, get request_token from callback
87
+ client.login(request_token="token_from_callback", api_secret="your_secret")
88
+
89
+ # Method 2: Automated login
90
+ client.auto_login(
91
+ user_id="your_user_id",
92
+ password="your_password",
93
+ api_secret="your_api_secret",
94
+ totp_secret="your_totp_secret"
95
+ )
96
+ ```
97
+
98
+ ### Basic Trading Operations
99
+
100
+ ```python
101
+ from arrowconnect.constants import Exchange, OrderType, ProductType, TransactionType, Variety, Retention
102
+
103
+ # Place a buy order
104
+ order_id = client.place_order(
105
+ exchange=Exchange.NSE,
106
+ symbol="RELIANCE",
107
+ quantity=10,
108
+ disclosed_quantity=0,
109
+ product=ProductType.DELIVERY,
110
+ order_type=OrderType.MARKET,
111
+ variety=Variety.NORMAL,
112
+ transaction_type=TransactionType.BUY,
113
+ price=0.0,
114
+ validity=Retention.DAY
115
+ )
116
+
117
+ print(f"Order placed: {order_id}")
118
+
119
+ # Get order status
120
+ orders = client.get_orders()
121
+ for order in orders:
122
+ print(f"Order {order['orderNo']}: {order['status']}")
123
+
124
+ # Get user positions
125
+ holdings = client.get_holdings()
126
+ print(f"Current holdings: {holdings}")
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 📡 Real-time Market Data
132
+
133
+ ### WebSocket Streaming
134
+
135
+ ```python
136
+ from arrowconnect import ArrowStreams, DataMode
137
+
138
+ # Initialize streams
139
+ streams = ArrowStreams(
140
+ appID="your_app_id",
141
+ token="your_access_token",
142
+ debug=True
143
+ )
144
+
145
+ # Set up event handlers
146
+ def on_tick(tick):
147
+ print(f"Tick: {tick.token} LTP: {tick.ltp} Change: {tick.net_change}%")
148
+
149
+ def on_order_update(order):
150
+ print(f"Order Update: {order}")
151
+
152
+ # Connect handlers
153
+ streams.data_stream.on_ticks = on_tick
154
+ streams.order_stream.on_order_update = on_order_update
155
+
156
+ # Connect to streams
157
+ streams.connect_all()
158
+
159
+ # Subscribe to market data
160
+ token_list = [3045, 1594] # NSE tokens for RELIANCE, INFY
161
+ streams.subscribe_market_data(DataMode.LTPC, token_list)
162
+
163
+ # Keep connection alive
164
+ import time
165
+ try:
166
+ while True:
167
+ time.sleep(1)
168
+ except KeyboardInterrupt:
169
+ streams.disconnect_all()
170
+ ```
171
+
172
+ ### Market Data Modes
173
+
174
+ ```python
175
+ # LTPC Mode - Last Trade Price & Change
176
+ streams.subscribe_market_data(DataMode.LTPC, [3045])
177
+
178
+ # Quote Mode - Detailed quotes with OI, volume
179
+ streams.subscribe_market_data(DataMode.QUOTE, [3045])
180
+
181
+ # Full Mode - Complete market depth (bids/asks)
182
+ streams.subscribe_market_data(DataMode.FULL, [3045])
183
+ ```
184
+
185
+ ---
186
+
187
+ ## 💹 Advanced Trading Features
188
+
189
+ ### Order Modification
190
+
191
+ ```python
192
+ # Modify existing order
193
+ client.modify_order(
194
+ order_id="order_id_here",
195
+ exchange=Exchange.NSE,
196
+ quantity=15, # Changed quantity
197
+ symbol="RELIANCE",
198
+ price=2500.0, # New price
199
+ disclosed_qty=0,
200
+ product=ProductType.INTRADAY,
201
+ transaction_type=TransactionType.BUY,
202
+ order_type=OrderType.LIMIT,
203
+ validity=Retention.DAY
204
+ )
205
+ ```
206
+
207
+ ### Bracket Orders
208
+
209
+ ```python
210
+ # Place bracket order with target and stop loss
211
+ order_id = client.place_order(
212
+ exchange=Exchange.NSE,
213
+ symbol="RELIANCE",
214
+ quantity=10,
215
+ disclosed_quantity=0,
216
+ product=ProductType.BRACKET,
217
+ order_type=OrderType.LIMIT,
218
+ variety=Variety.NORMAL,
219
+ transaction_type=TransactionType.BUY,
220
+ price=2450.0,
221
+ validity=Retention.DAY,
222
+ trigger_price=2400.0 # Stop loss trigger
223
+ )
224
+ ```
225
+
226
+ ### Margin Calculation
227
+
228
+ ```python
229
+ # Calculate margin for single order
230
+ margin_params = {
231
+ "exchange": "NSE",
232
+ "symbol": "RELIANCE",
233
+ "quantity": 100,
234
+ "price": 2500,
235
+ "product": "MIS",
236
+ "transactionType": "BUY"
237
+ }
238
+
239
+ margin_info = client.get_order_margin(margin_params)
240
+ print(f"Required margin: ₹{margin_info['totalMargin']}")
241
+
242
+ # Calculate basket margin for multiple orders
243
+ orders = [margin_params] # Add multiple order dicts
244
+ basket_margin = client.get_basket_margin(orders)
245
+ ```
246
+
247
+ ---
248
+
249
+ ## 📊 Market Data & Analytics
250
+
251
+ ### Historical Data & Instruments
252
+
253
+ ```python
254
+ # Get all tradable instruments
255
+ instruments = client.get_instruments()
256
+
257
+ # Get option chain data
258
+ option_symbols = client.get_option_chain_symbols()
259
+ option_chain = client.get_option_chain({
260
+ "symbol": "NIFTY",
261
+ "expiry": "2024-03-28"
262
+ })
263
+
264
+ # Get market holidays
265
+ holidays = client.get_holidays()
266
+
267
+ # Get index listings
268
+ indices = client.get_index_list()
269
+ ```
270
+
271
+ ### Expiry Information
272
+
273
+ ```python
274
+ from arrowconnect import ArrowClient
275
+
276
+ # Get expiry dates for instruments
277
+ nifty_expiries = ArrowClient.get_expiry_dates("NIFTY", "2024")
278
+ print(f"NIFTY expiries: {nifty_expiries}")
279
+ ```
280
+
281
+ ---
282
+
283
+ ## 🔧 Configuration & Error Handling
284
+
285
+ ### Client Configuration
286
+
287
+ ```python
288
+ client = ArrowClient(
289
+ app_id="your_app_id",
290
+ timeout=30, # Request timeout in seconds
291
+ debug=True, # Enable debug logging
292
+ root_url="https://edge.arrow.trade", # Custom API endpoint
293
+ pool_config={
294
+ "pool_connections": 10,
295
+ "pool_maxsize": 20
296
+ }
297
+ )
298
+ ```
299
+
300
+ ### WebSocket Configuration
301
+
302
+ ```python
303
+ from arrowconnect.streams import ConnectionConfig
304
+
305
+ config = ConnectionConfig(
306
+ appID="your_app_id",
307
+ token="your_token",
308
+ debug=True,
309
+ enable_reconnect=True,
310
+ max_reconnect_attempts=300,
311
+ max_reconnect_delay=10,
312
+ read_timeout=30,
313
+ ping_interval=30
314
+ )
315
+
316
+ streams = ArrowStreams.from_config(config)
317
+ ```
318
+
319
+ ### Error Handling
320
+
321
+ ```python
322
+ from arrowconnect.exceptions import ArrowException
323
+
324
+ try:
325
+ order_id = client.place_order(
326
+ # order parameters
327
+ )
328
+ except ArrowException as e:
329
+ print(f"Trading error: {e.message} (Code: {e.code})")
330
+ except Exception as e:
331
+ print(f"General error: {e}")
332
+ ```
333
+
334
+ ---
335
+
336
+ ## 📈 Sample Trading Strategy
337
+
338
+ ```python
339
+ import time
340
+ from arrowconnect import ArrowClient, ArrowStreams, DataMode
341
+ from arrowconnect.constants import *
342
+
343
+ class SimpleStrategy:
344
+ def __init__(self, app_id, token):
345
+ self.client = ArrowClient(app_id)
346
+ self.client.set_token(token)
347
+
348
+ self.streams = ArrowStreams(app_id, token)
349
+ self.streams.data_stream.on_ticks = self.on_market_tick
350
+
351
+ self.position = 0
352
+ self.target_symbol = "RELIANCE"
353
+ self.target_token = 3045
354
+
355
+ def start(self):
356
+ # Connect to real-time feeds
357
+ self.streams.connect_data_stream()
358
+ self.streams.subscribe_market_data(DataMode.QUOTE, [self.target_token])
359
+
360
+ print("Strategy started. Monitoring market data...")
361
+
362
+ def on_market_tick(self, tick):
363
+ if tick.token == self.target_token:
364
+ # Simple momentum strategy
365
+ if tick.net_change > 2.0 and self.position == 0:
366
+ self.buy_signal(tick)
367
+ elif tick.net_change < -1.0 and self.position > 0:
368
+ self.sell_signal(tick)
369
+
370
+ def buy_signal(self, tick):
371
+ try:
372
+ order_id = self.client.place_order(
373
+ exchange=Exchange.NSE,
374
+ symbol=self.target_symbol,
375
+ quantity=10,
376
+ disclosed_quantity=0,
377
+ product=ProductType.INTRADAY,
378
+ order_type=OrderType.MARKET,
379
+ variety=Variety.NORMAL,
380
+ transaction_type=TransactionType.BUY,
381
+ price=0.0,
382
+ validity=Retention.DAY
383
+ )
384
+ self.position = 10
385
+ print(f"BUY order placed: {order_id} at LTP: {tick.ltp}")
386
+ except Exception as e:
387
+ print(f"Buy order failed: {e}")
388
+
389
+ def sell_signal(self, tick):
390
+ try:
391
+ order_id = self.client.place_order(
392
+ exchange=Exchange.NSE,
393
+ symbol=self.target_symbol,
394
+ quantity=self.position,
395
+ disclosed_quantity=0,
396
+ product=ProductType.INTRADAY,
397
+ order_type=OrderType.MARKET,
398
+ variety=Variety.NORMAL,
399
+ transaction_type=TransactionType.SELL,
400
+ price=0.0,
401
+ validity=Retention.DAY
402
+ )
403
+ self.position = 0
404
+ print(f"SELL order placed: {order_id} at LTP: {tick.ltp}")
405
+ except Exception as e:
406
+ print(f"Sell order failed: {e}")
407
+
408
+ # Usage
409
+ if __name__ == "__main__":
410
+ strategy = SimpleStrategy("your_app_id", "your_token")
411
+ strategy.start()
412
+
413
+ try:
414
+ while True:
415
+ time.sleep(1)
416
+ except KeyboardInterrupt:
417
+ print("Strategy stopped")
418
+ strategy.streams.disconnect_all()
419
+ ```
420
+
421
+ ---
422
+
423
+ ## 🔍 API Reference
424
+
425
+ ### ArrowClient Methods
426
+
427
+ | Method | Description | Returns |
428
+ |--------|-------------|---------|
429
+ | `login(request_token, api_secret)` | Authenticate using request token | `Dict[str, str]` |
430
+ | `auto_login(user_id, password, api_secret, totp_secret)` | Automated login with credentials | `Dict[str, str]` |
431
+ | `place_order(**params)` | Place new order | `str` (order_id) |
432
+ | `modify_order(order_id, **params)` | Modify existing order | `str` |
433
+ | `cancel_order(order_id)` | Cancel order | `str` |
434
+ | `get_orders()` | Get all orders | `List[Dict]` |
435
+ | `get_order(order_id)` | Get specific order details | `List[Dict]` |
436
+ | `get_trades()` | Get all trades | `List[Dict]` |
437
+ | `get_holdings()` | Get user holdings | `Dict` |
438
+ | `get_user_details()` | Get user profile | `Dict` |
439
+ | `get_order_margin(params)` | Calculate order margin | `Dict` |
440
+ | `get_basket_margin(orders)` | Calculate basket margin | `Dict` |
441
+
442
+ ### WebSocket Events
443
+
444
+ | Event | Trigger | Data Type |
445
+ |-------|---------|-----------|
446
+ | `on_connect` | Connection established | `None` |
447
+ | `on_disconnect` | Connection lost | `None` |
448
+ | `on_ticks` | Market data received | `MarketTick` |
449
+ | `on_order_update` | Order status changed | `Dict` |
450
+ | `on_error` | Error occurred | `Exception` |
451
+
452
+ ---
453
+
454
+ ## 🤝 Contributing
455
+
456
+ We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.
457
+
458
+ ### Development Setup
459
+
460
+ ```bash
461
+ git clone https://github.com/arrowtech/arrowconnect-python.git
462
+ cd arrowconnect-python
463
+ pip install -e .[dev]
464
+ pytest tests/
465
+ ```
466
+
467
+ ---
468
+
469
+ ## 📄 License
470
+
471
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
472
+
473
+ ---
474
+
475
+ ## 📞 Support
476
+
477
+ - **Documentation**: [https://docs.arrow.trade](https://docs.arrow.trade)
478
+ - **API Reference**: [https://api.arrow.trade/docs](https://api.arrow.trade/docs)
479
+ - **Issues**: [GitHub Issues](https://github.com/arrowtech/arrowconnect-python/issues)
480
+ - **Support Email**: support@arrow.trade
481
+
482
+ ---
483
+
484
+ ## ⚠️ Disclaimer
485
+
486
+ This software is for educational and informational purposes only. Trading in financial markets involves substantial risk and may not be suitable for all investors. Past performance is not indicative of future results. Please trade responsibly and consult with financial advisors before making investment decisions.
487
+
488
+ ---
489
+
490
+ **Built with ❤️ by the Arrow Trading Team**