Skip to content

Commit 4181b1f

Browse files
authored
Merge pull request #476 from krishnavelu/develop
Develop -> master for 2.0.3
2 parents 41ea4a8 + 0817522 commit 4181b1f

File tree

4 files changed

+100
-58
lines changed

4 files changed

+100
-58
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ Symbols can be retrieved in multiple ways. Once you have the master contract loa
175175
#### Get a single instrument by it's name:
176176
Code
177177
```python
178-
tatasteel_nse_eq = alice.get_instrument_by_symbol('NSE', 'TATASTEEL')
179-
reliance_nse_eq = alice.get_instrument_by_symbol('NSE', 'RELIANCE')
180-
ongc_bse_eq = alice.get_instrument_by_symbol('BSE', 'ONGC')
178+
tatasteel_nse_eq = alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ')
179+
reliance_nse_eq = alice.get_instrument_by_symbol('NSE', 'RELIANCE-EQ')
180+
ongc_bse_eq = alice.get_instrument_by_symbol('BSE', 'ONGC-EQ')
181181
india_vix_nse_index = alice.get_instrument_by_symbol('NSE', 'India VIX')
182182
sensex_nse_index = alice.get_instrument_by_symbol('BSE', 'SENSEX')
183183
nifty50_nse_index = alice.get_instrument_by_symbol('NSE', 'NIFTY 50')
@@ -234,13 +234,13 @@ Please refer to the original documentation [here](https://v2api.aliceblueonline.
234234
#### Subscribe to a live feed
235235
Code
236236
```python
237-
alice.subscribe(alice.get_instrument_by_symbol('NSE', 'TATASTEEL'), LiveFeedType.TICK_DATA)
238-
alice.subscribe(alice.get_instrument_by_symbol('BSE', 'RELIANCE'), LiveFeedType.DEPTH_DATA)
237+
alice.subscribe(alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ'), LiveFeedType.TICK_DATA)
238+
alice.subscribe(alice.get_instrument_by_symbol('BSE', 'RELIANCE-EQ'), LiveFeedType.DEPTH_DATA)
239239
```
240240
#### Subscribe to multiple instruments in a single call. Give an array of instruments to be subscribed.
241241
Code
242242
```python
243-
alice.subscribe([alice.get_instrument_by_symbol('NSE', 'TATASTEEL'), alice.get_instrument_by_symbol('NSE', 'ACC')], LiveFeedType.TICK_DATA)
243+
alice.subscribe([alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ'), alice.get_instrument_by_symbol('NSE', 'ACC-EQ')], LiveFeedType.TICK_DATA)
244244
```
245245

246246
#### Start getting live feed via websocket
@@ -251,7 +251,7 @@ def event_handler_quote_update(message):
251251

252252
alice.start_websocket(subscribe_callback=event_handler_quote_update)
253253

254-
alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC'), LiveFeedType.TICK_DATA)
254+
alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC-EQ'), LiveFeedType.TICK_DATA)
255255
sleep(10)
256256
```
257257

@@ -260,13 +260,13 @@ Unsubscribe to an existing live feed.
260260

261261
Code
262262
```python
263-
alice.unsubscribe(alice.get_instrument_by_symbol('NSE', 'TATASTEEL'), LiveFeedType.TICK_DATA)
264-
alice.unsubscribe(alice.get_instrument_by_symbol('BSE', 'RELIANCE'), LiveFeedType.DEPTH_DATA)
263+
alice.unsubscribe(alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ'), LiveFeedType.TICK_DATA)
264+
alice.unsubscribe(alice.get_instrument_by_symbol('BSE', 'RELIANCE-EQ'), LiveFeedType.DEPTH_DATA)
265265
```
266266
#### Unsubscribe to multiple instruments in a single call. Give an array of instruments to be unsubscribed.
267267
Code
268268
```python
269-
alice.unsubscribe([alice.get_instrument_by_symbol('NSE', 'TATASTEEL'), alice.get_instrument_by_symbol('NSE', 'ACC')], LiveFeedType.TICK_DATA)
269+
alice.unsubscribe([alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ'), alice.get_instrument_by_symbol('NSE', 'ACC-EQ')], LiveFeedType.TICK_DATA)
270270
```
271271

272272
#### Get All Subscribed Symbols

alice_blue/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .alice_blue import AliceBlue, TransactionType, OrderType, ProductType, LiveFeedType, Instrument
2-
__all__ = ['AliceBlue', 'TransactionType', 'OrderType', 'ProductType', 'LiveFeedType', 'Instrument']
1+
from .alice_blue import AliceBlue, TransactionType, OrderType, ProductType, LiveFeedType, Instrument, HistoricalDataType
2+
__all__ = ['AliceBlue', 'TransactionType', 'OrderType', 'ProductType', 'LiveFeedType', 'Instrument', 'HistoricalDataType']

alice_blue/alice_blue.py

Lines changed: 87 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(self, username, session_id, master_contracts_to_download = None):
147147
self.__exchange_messages = []
148148
# Initialize Depth data
149149
self.__depth_data = {}
150-
self.__ltp = {}
150+
self.__tick_data = {}
151151

152152
try:
153153
self.get_profile()
@@ -249,57 +249,92 @@ def __extract_tick_data(self, data):
249249
data["instrument"] = self.get_instrument_by_token(data.pop("e"), int(data.pop("tk")))
250250
if("ts" in data): # Symbol
251251
data.pop("ts")
252-
if(data["instrument"].symbol not in self.__ltp):
253-
self.__ltp[data["instrument"].symbol] = 0
252+
if(data["instrument"].symbol not in self.__tick_data):
253+
self.__tick_data[data["instrument"].symbol] = {}
254+
self.__tick_data[data["instrument"].symbol]["ltp"] = 0
255+
self.__tick_data[data["instrument"].symbol]["percent_change"] = 0
256+
self.__tick_data[data["instrument"].symbol]["change_value"] = 0
257+
self.__tick_data[data["instrument"].symbol]["volume"] = 0
258+
self.__tick_data[data["instrument"].symbol]["open"] = 0
259+
self.__tick_data[data["instrument"].symbol]["high"] = 0
260+
self.__tick_data[data["instrument"].symbol]["low"] = 0
261+
self.__tick_data[data["instrument"].symbol]["close"] = 0
262+
self.__tick_data[data["instrument"].symbol]["exchange_time_stamp"] = None
263+
self.__tick_data[data["instrument"].symbol]["atp"] = 0
264+
self.__tick_data[data["instrument"].symbol]["tick_increment"] = 0
265+
self.__tick_data[data["instrument"].symbol]["lot_size"] = 0
266+
self.__tick_data[data["instrument"].symbol]["price_precision"] = 0
267+
self.__tick_data[data["instrument"].symbol]["total_open_interest"] = 0
254268
if("lp" in data): # Last Traded Price
255-
self.__ltp[data["instrument"].symbol] = float(data.pop("lp"))
256-
data["ltp"] = self.__ltp[data["instrument"].symbol]
269+
self.__tick_data[data["instrument"].symbol]["ltp"] = float(data.pop("lp"))
257270
if("pc" in data): # percentage change
258-
data["percent_change"] = float(data.pop("pc"))
271+
self.__tick_data[data["instrument"].symbol]["percent_change"] = float(data.pop("pc"))
259272
if("cv" in data): # change value (absolute change in price)
260-
data["change_value"] = float(data.pop("cv"))
261-
if("v" in data): # Volume
262-
data["volume"] = int(data.pop("v"))
263-
if("o" in data): # Open
264-
data["open"] = float(data.pop("o"))
265-
if("h" in data): # High
266-
data["high"] = float(data.pop("h"))
267-
if("l" in data): # Low
268-
data["low"] = float(data.pop("l"))
269-
if("c" in data): # Close
270-
data["close"] = float(data.pop("c"))
273+
self.__tick_data[data["instrument"].symbol]["change_value"] = float(data.pop("cv"))
274+
if("v" in data): # Volume
275+
self.__tick_data[data["instrument"].symbol]["volume"] = int(data.pop("v"))
276+
if("o" in data): # Open
277+
self.__tick_data[data["instrument"].symbol]["open"] = float(data.pop("o"))
278+
if("h" in data): # High
279+
self.__tick_data[data["instrument"].symbol]["high"] = float(data.pop("h"))
280+
if("l" in data): # Low
281+
self.__tick_data[data["instrument"].symbol]["low"] = float(data.pop("l"))
282+
if("c" in data): # Close
283+
self.__tick_data[data["instrument"].symbol]["close"] = float(data.pop("c"))
271284
if("ft" in data): # Feed Time
272-
data["exchange_time_stamp"] = datetime.datetime.fromtimestamp(int(data.pop("ft")))
285+
self.__tick_data[data["instrument"].symbol]["exchange_time_stamp"] = datetime.datetime.fromtimestamp(int(data.pop("ft")))
273286
if("ap" in data): # Average Price
274-
data["atp"] = float(data.pop("ap"))
287+
self.__tick_data[data["instrument"].symbol]["atp"] = float(data.pop("ap"))
275288
if("ti" in data): # Tick Increment
276-
data["tick_increment"] = float(data.pop("ti"))
289+
self.__tick_data[data["instrument"].symbol]["tick_increment"] = float(data.pop("ti"))
277290
if("ls" in data): # Lot Size
278-
data["lot_size"] = int(data.pop("ls"))
291+
self.__tick_data[data["instrument"].symbol]["lot_size"] = int(data.pop("ls"))
279292
if(data["instrument"].symbol not in self.__depth_data): # Initialize depth data
280293
self.__depth_data[data["instrument"].symbol] = {}
281-
self.__depth_data[data["instrument"].symbol]["bid_prices"] = [None, None, None, None, None]
282-
self.__depth_data[data["instrument"].symbol]["ask_prices"] = [None, None, None, None, None]
283-
self.__depth_data[data["instrument"].symbol]["bid_quantities"] = [None, None, None, None, None]
284-
self.__depth_data[data["instrument"].symbol]["ask_quantities"] = [None, None, None, None, None]
285-
self.__depth_data[data["instrument"].symbol]["buy_orders"] = [None, None, None, None, None]
286-
self.__depth_data[data["instrument"].symbol]["sell_orders"] = [None, None, None, None, None]
294+
self.__depth_data[data["instrument"].symbol]["bid_prices"] = [None, None, None, None, None]
295+
self.__depth_data[data["instrument"].symbol]["ask_prices"] = [None, None, None, None, None]
296+
self.__depth_data[data["instrument"].symbol]["bid_quantities"] = [None, None, None, None, None]
297+
self.__depth_data[data["instrument"].symbol]["ask_quantities"] = [None, None, None, None, None]
298+
self.__depth_data[data["instrument"].symbol]["buy_orders"] = [None, None, None, None, None]
299+
self.__depth_data[data["instrument"].symbol]["sell_orders"] = [None, None, None, None, None]
300+
self.__depth_data[data["instrument"].symbol]["open_interest"] = 0
301+
self.__depth_data[data["instrument"].symbol]["last_traded_quantity"]= 0
302+
self.__depth_data[data["instrument"].symbol]["last_traded_time"] = None
303+
self.__depth_data[data["instrument"].symbol]["total_buy_quantity"] = 0
304+
self.__depth_data[data["instrument"].symbol]["total_sell_quantity"] = 0
305+
self.__depth_data[data["instrument"].symbol]["upper_circuit"] = 0
306+
self.__depth_data[data["instrument"].symbol]["lower_circuit"] = 0
307+
287308
if("bp1" in data): # Best Bid
288-
data["best_bid_price"] = float(data.pop("bp1"))
289-
self.__depth_data[data["instrument"].symbol]["bid_prices"][0] = data["best_bid_price"]
309+
self.__depth_data[data["instrument"].symbol]["bid_prices"][0] = float(data.pop("bp1"))
290310
if("sp1" in data): # Best Ask
291-
data["best_ask_price"] = float(data.pop("sp1"))
292-
self.__depth_data[data["instrument"].symbol]["ask_prices"][0] = data["best_ask_price"]
311+
self.__depth_data[data["instrument"].symbol]["ask_prices"][0] = float(data.pop("sp1"))
293312
if("bq1" in data): # Best Bid Quantity
294-
data["best_bid_quantity"] = int(data.pop("bq1"))
295-
self.__depth_data[data["instrument"].symbol]["bid_quantities"][0] = data["best_bid_quantity"]
313+
self.__depth_data[data["instrument"].symbol]["bid_quantities"][0] = int(data.pop("bq1"))
296314
if("sq1" in data): # Best Ask Quantity
297-
data["best_ask_quantity"] = int(data.pop("sq1"))
298-
self.__depth_data[data["instrument"].symbol]["ask_quantities"][0] = data["best_ask_quantity"]
315+
self.__depth_data[data["instrument"].symbol]["ask_quantities"][0] = int(data.pop("sq1"))
299316
if("pp" in data): # Price Precision
300-
data["price_precision"] = int(data.pop("pp"))
317+
self.__tick_data[data["instrument"].symbol]["price_precision"] = int(data.pop("pp"))
301318
if("toi" in data): # Total Open Interest
302-
data["total_open_interest"] = int(data.pop("toi"))
319+
self.__tick_data[data["instrument"].symbol]["total_open_interest"] = int(data.pop("toi"))
320+
data["ltp"] = self.__tick_data[data["instrument"].symbol]["ltp"]
321+
data["percent_change"] = self.__tick_data[data["instrument"].symbol]["percent_change"]
322+
data["change_value"] = self.__tick_data[data["instrument"].symbol]["change_value"]
323+
data["volume"] = self.__tick_data[data["instrument"].symbol]["volume"]
324+
data["open"] = self.__tick_data[data["instrument"].symbol]["open"]
325+
data["high"] = self.__tick_data[data["instrument"].symbol]["high"]
326+
data["low"] = self.__tick_data[data["instrument"].symbol]["low"]
327+
data["close"] = self.__tick_data[data["instrument"].symbol]["close"]
328+
data["exchange_time_stamp"] = self.__tick_data[data["instrument"].symbol]["exchange_time_stamp"]
329+
data["atp"] = self.__tick_data[data["instrument"].symbol]["atp"]
330+
data["tick_increment"] = self.__tick_data[data["instrument"].symbol]["tick_increment"]
331+
data["lot_size"] = self.__tick_data[data["instrument"].symbol]["lot_size"]
332+
data["best_bid_price"] = self.__depth_data[data["instrument"].symbol]["bid_prices"][0]
333+
data["best_ask_price"] = self.__depth_data[data["instrument"].symbol]["ask_prices"][0]
334+
data["best_bid_quantity"] = self.__depth_data[data["instrument"].symbol]["bid_quantities"][0]
335+
data["best_ask_quantity"] = self.__depth_data[data["instrument"].symbol]["ask_quantities"][0]
336+
data["price_precision"] = self.__tick_data[data["instrument"].symbol]["price_precision"]
337+
data["total_open_interest"] = self.__tick_data[data["instrument"].symbol]["total_open_interest"]
303338
return data
304339

305340
def __extract_depth_data(self, data):
@@ -381,19 +416,27 @@ def __extract_depth_data(self, data):
381416
data["sell_orders"] = self.__depth_data[data["instrument"].symbol]["sell_orders"].copy()
382417

383418
if("oi" in data): # Open Interest
384-
data["open_interest"] = int(data.pop("oi"))
419+
self.__depth_data[data["instrument"].symbol]["open_interest"] = int(data.pop("oi"))
385420
if("ltq" in data): # Last Traded Quantity
386-
data["last_traded_quantity"] = int(data.pop("ltq"))
421+
self.__depth_data[data["instrument"].symbol]["last_traded_quantity"] = int(data.pop("ltq"))
387422
if("ltt" in data): # Last Traded Time
388-
data["last_traded_time"] = datetime.datetime.strptime(data.pop("ltt"), "%H:%M:%S").time()
423+
self.__depth_data[data["instrument"].symbol]["last_traded_time"] = datetime.datetime.strptime(data.pop("ltt"), "%H:%M:%S").time()
389424
if("tbq" in data): # Total Buy Quantity
390-
data["total_buy_quantity"] = int(data.pop("tbq"))
425+
self.__depth_data[data["instrument"].symbol]["total_buy_quantity"] = int(data.pop("tbq"))
391426
if("tsq" in data): # Total Sell Quantity
392-
data["total_sell_quantity"] = int(data.pop("tsq"))
427+
self.__depth_data[data["instrument"].symbol]["total_sell_quantity"] = int(data.pop("tsq"))
393428
if("uc" in data): # Upper Circuit
394-
data["upper_circuit"] = float(data.pop("uc"))
429+
self.__depth_data[data["instrument"].symbol]["upper_circuit"] = float(data.pop("uc"))
395430
if("lc" in data): # Lower Circuit
396-
data["lower_circuit"] = float(data.pop("lc"))
431+
self.__depth_data[data["instrument"].symbol]["lower_circuit"] = float(data.pop("lc"))
432+
433+
data["open_interest"] = self.__depth_data[data["instrument"].symbol]["open_interest"]
434+
data["last_traded_quantity"] = self.__depth_data[data["instrument"].symbol]["last_traded_quantity"]
435+
data["last_traded_time"] = self.__depth_data[data["instrument"].symbol]["last_traded_time"]
436+
data["total_buy_quantity"] = self.__depth_data[data["instrument"].symbol]["total_buy_quantity"]
437+
data["total_sell_quantity"] = self.__depth_data[data["instrument"].symbol]["total_sell_quantity"]
438+
data["upper_circuit"] = self.__depth_data[data["instrument"].symbol]["upper_circuit"]
439+
data["lower_circuit"] = self.__depth_data[data["instrument"].symbol]["lower_circuit"]
397440
return data
398441

399442
def __on_data_callback(self, ws=None, message=None, data_type=None, continue_flag=None):
@@ -674,7 +717,6 @@ def modify_order(self, transaction_type, instrument, product_type, order_id, ord
674717
"transtype" : transaction_type.value,
675718
"prctyp" : order_type.value,
676719
"qty" : quantity,
677-
"trading_symbol" : instrument.symbol,
678720
"price" : price,
679721
"trigPrice" : trigger_price,
680722
"pCode" : prod_type

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setuptools.setup(
77
name = 'alice_blue',
88
packages=setuptools.find_packages(),
9-
version = '2.0.2',
9+
version = '2.0.3',
1010
include_package_data=True,
1111
description = 'Official Python library for Alice Blue APIs',
1212
long_description=long_description,

0 commit comments

Comments
 (0)