ui export
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from pymongo import MongoClient
|
||||
cmt="current_market_trades"
|
||||
cma="current_market_asks"
|
||||
cmb="current_market_bids"
|
||||
|
||||
class MongoExporter():
|
||||
|
||||
def __init__(self,conn_string,db,econ) -> None:
|
||||
|
||||
# Provide the mongodb atlas url to connect python to mongodb using pymongo
|
||||
|
||||
|
||||
# Create a connection using MongoClient. You can import MongoClient or use pymongo.MongoClient
|
||||
client = MongoClient(conn_string)
|
||||
|
||||
# Create the database for our example (we will use the same database throughout the tutorial
|
||||
self.client=client[db]
|
||||
self.econ=econ
|
||||
|
||||
def reset_market(self):
|
||||
"""Resets the current market data in the analytics stack"""
|
||||
c=self.client
|
||||
c[cmt].drop()
|
||||
c[cma].drop()
|
||||
c[cmb].drop()
|
||||
|
||||
def submit_full_market(self):
|
||||
c=self.client
|
||||
market=self.econ.get_component("ContinuousDoubleAuction")
|
||||
self.reset_market()
|
||||
|
||||
for i in range(len(market.executed_trades)):
|
||||
step=market.executed_trades[i]
|
||||
if len(step)>0:
|
||||
for transaction in step:
|
||||
transaction["step"]=i
|
||||
c[cmt].insert_one(transaction)
|
||||
c[cma].insert_many(market.asks)
|
||||
c[cmb].insert_many(market.bids)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# This is added so that many files can reuse the function get_database()
|
||||
Reference in New Issue
Block a user