I am trying to save time series data (generated using web sockets) in MongoDB using Python.
from pymongo import MongoClient
client = MongoClient()
db=client.market_data #market_data is my db name
kws = KiteTicker("4515kn****", "pOYgD0hvSfofC********") #stock market data client connection
db.tick.insertMany(kws.connect());
#tick is my mongo collection name kws.connect() generates timeseries data in below format.
DEBUG:root:Ticks: [{‘timestamp’: datetime.datetime(2020, 7, 20, 13, 25, 5), ‘last_price’: 1912.5, ‘oi_day_low’: 0, ‘volume’: 9522995, ‘sell_quantity’: 1213264, ‘last_quantity’: 31, ‘change’: 0.04184757022545141, ‘oi’: 0, ‘average_price’: 1913.44, ‘ohlc’: {‘high’: 1929.9, ‘close’: 1911.7, ‘open’: 1917.8, ‘low’: 1899.65}, ‘tradable’: True, ‘depth’: {‘sell’: [{‘price’: 1912.8, ‘orders’: 3, ‘quantity’: 62}, {‘price’: 1912.95, ‘orders’: 1, ‘quantity’: 61}, {‘price’: 1913.15, ‘orders’: 1, ‘quantity’: 6}, {‘price’: 1913.2, ‘orders’: 2, ‘quantity’: 194}, {‘price’: 1913.25, ‘orders’: 1, ‘quantity’: 50}], ‘buy’: [{‘price’: 1912.5, ‘orders’: 16, ‘quantity’: 1409}, {‘price’: 1912.45, ‘orders’: 1, ‘quantity’: 50}, {‘price’: 1912.25, ‘orders’: 1, ‘quantity’: 1}, {‘price’: 1912.2, ‘orders’: 1, ‘quantity’: 1}, {‘price’: 1912.15, ‘orders’: 1, ‘quantity’: 104}]}, ‘mode’: ‘full’, ‘last_trade_time’: datetime.datetime(2020, 7, 20, 13, 25, 5), ‘buy_quantity’: 806075, ‘oi_day_high’: 0, ‘instrument_token’: 738561}]
DEBUG:root:Ticks: [{‘timestamp’: datetime.datetime(2020, 7, 20, 13, 25, 6), ‘last_price’: 1912.5, ‘oi_day_low’: 0, ‘volume’: 9523089, ‘sell_quantity’: 1214242, ‘last_quantity’: 1, ‘change’: 0.04184757022545141, ‘oi’: 0, ‘average_price’: 1913.44, ‘ohlc’: {‘high’: 1929.9, ‘close’: 1911.7, ‘open’: 1917.8, ‘low’: 1899.65}, ‘tradable’: True, ‘depth’: {‘sell’: [{‘price’: 1912.8, ‘orders’: 3, ‘quantity’: 62}, {‘price’: 1912.95, ‘orders’: 1, ‘quantity’: 61}, {‘price’: 1913.15, ‘orders’: 1, ‘quantity’: 6}, {‘price’: 1913.2, ‘orders’: 2, ‘quantity’: 194}, {‘price’: 1913.25, ‘orders’: 1, ‘quantity’: 50}], ‘buy’: [{‘price’: 1912.5, ‘orders’: 17, ‘quantity’: 1354}, {‘price’: 1912.45, ‘orders’: 1, ‘quantity’: 50}, {‘price’: 1912.25, ‘orders’: 1, ‘quantity’: 1}, {‘price’: 1912.2, ‘orders’: 1, ‘quantity’: 1}, {‘price’: 1912.15, ‘orders’: 1, ‘quantity’: 104}]}, ‘mode’: ‘full’, ‘last_trade_time’: datetime.datetime(2020, 7, 20, 13, 25, 6), ‘buy_quantity’: 805788, ‘oi_day_high’: 0, ‘instrument_token’: 738561}]
db.tick.insertMany()
method is not saving this data in my mongo collection.
Any help?
Thanks.