- download Python Adapter for BitMEX Realtime Data get it from here
- setup it
- Schema.png :- it is DB schema for retional DB.
- Init_Data.py :- Initial data this have shared data such as DB_name and some data used to setup sqliteDB.
- Mongo_StoreData.py :- have function that used to Store and Retrieve from MongoDB.
- SqliteDB_Setupe.py :- have the sql query that use to build DB in first time .
- sqlite_StoreData.py :- have function that used to Store and Retrieve from Sqlite.
- pre_main :- that have updated code that will replaced with main.py file.
you can change DataBase_name , host and port in Init_Data.py file, and you add more "categories" and add more elements to any category and change and specify his type as "Static" or "Dinamic"
- Clone this repository
git clone https://github.com/moroclash/Store-json-in-Database.git
- replace local main.py with pre_main.py run this command
cat pre_main.py >> main.py
- you shoud put your mail and password to can connect with API , put them in file main.py
login=None, password=None #line 16 in main.py file
- to store Data in DB
-
MongoDB :
- check that you have MongoDB on your PC , install it if not exist
- go to main.py file and remove this command symbol from ln 40 to ln 56
# to store in MongoDB remove the comming comments import Mongo_StoreData as Mstore # Run forever while(ws.ws.sock.connected): ticker = ws.get_ticker() logger.info("Ticker : %s" % ticker) funds = ws.funds() logger.info("Funds: %s" % funds) market_depth = ws.market_depth() logger.info("Market Depth: %s" % market_depth) #store market_depth in mongo DB Mstore.store_data(category_name="market_depth",ws=market_depth) recent_trades = ws.recent_trades() logger.info("Recent Trades: %s\n\n" % recent_trades) #store recent_trades in mongo DB Mstore.store_data(category_name="recent_trades",ws=recent_trades) sleep(10)
- Run program
python main.py- it will store market_depth ans recent_trades in DB
-
Sqlite :
- you should run SqliteDB_Setupe.py file at first time to create DataBase
- go to main.py file and remove this command symbol from ln 21 to ln 37
# to save in sqlite Database remove the comming comments import sqlite_StoreData as Sstore # Run forever while(ws.ws.sock.connected): ticker = ws.get_ticker() #logger.info("Ticker : %s" % ticker) funds = ws.funds() #logger.info("Funds: %s" % funds) market_depth = ws.market_depth() #logger.info("Market Depth: %s" % market_depth) #store market_depth in Sqlite DB Sstore.store_market_depth(market_depth=market_depth,category="market_depth") recent_trades = ws.recent_trades() #logger.info("Recent Trades: %s\n\n" % recent_trades) #store recent_trades in mongo DB Sstore.store_recent_trades(recent_trades=recent_trades,category="recent_trades") sleep(10)
- Run program
python main.py- it will store market_depth ans recent_trades in sqliteDB
-
-
from MongoDB
- import Mongo_StoreData
- use function
# it take three parameters # 1. category_name such as "market_depth" or "recent_trades" # 2. timeStamp it's the timestamp that you search # 3. symbol it's the symbol that you search such as "XBTUSD" # it will retrive data and display it retrive_data(category_name , timeStamp , symbol)
-
from Sqlite
- import sqlite_StoreData
- use functions
# to retrieve market_depth # it take three parameters # 1. category_name such as "market_depth" # 2. timeStamp it's the timestamp that you search # 3. symbol it's the symbol that you search such as "XBTUSD" # it will retrive data and display it retrive_market_depth(TimeStamp,symbol,category_name) # to retrieve recent_trades # it take three parameters # 1. category_name such as "recent_trades" # 2. timeStamp it's the timestamp that you search # 3. symbol it's the symbol that you search such as "XBTUSD" # it will retrive data and display it retrive_recent_trades(TimeStamp,symbol,category_name)
- MongoDB :
have high performance and high speed it will store data even API change his Data format in runtime , but it will have duplicated data.
- Sqlite :