Tag Archives: database

How to insert ,update, delete into MongoDB NOSQL database with Python

How to insert ,update, delete into  MongoDB NOSQL database with  Python

Watch this 30 minute video to guide you through this process for my database for my trading system

 

How to insert update delete in a MongoDB NOSQL database with Python

 

Source code:

Query

#https://docs.mongodb.org/getting-started/python/query/

from pymongo import MongoClient

client = MongoClient()
# db = client.qln
# cursor = db.qln.find({"positions.shortsymbol": "ibm"})
#
# for document in cursor:
#     print(document)


db = client.qln
collection = db.equity

stocks = collection.find({"shortsymbol": "k"})

print stocks.count()
for stock in stocks:
    print(stock)

Insert

#https://docs.mongodb.org/getting-started/python/insert/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

#db.equity.insert( { "_id": 5, item: "box", qty: 20 } )

# from datetime import datetime
result = db.equity.insert_one(
    { "idx" : 2,
      "shortsymbol" : "k",
      "shortentryts" : 1000,
      "shortentryprice" : 100,
      "shortstoplossper" : 0.08,
      "shortupstop" : 105.1,
      "shortlowstop" : 95.1,
      "shortsofttargperc" : 0.08,
      "shortuptarget" : 105.1,
      "showlowtarget" : 95.1,
      "longsymbol" : "pep",
      "longentryts" : 1000,
      "longentryprice" : 100,
      "longstoplossper" : 0.08,
      "longupstop" : "10.5.1",
      "longlowstop" : 95.1,
      "longsofttarget" : 0.08,
      "longuptarget" : 105.1,
      "longdowntarget" : 95.1,
      "shortexitts" : 1000,
      "shortexitprice" : 95.1,
      "longexitprice" : 105.1,
      "shortqty" : 1000,
      "longqty" : 1000,
      "shortbeta" : 0.95,
      "longbeta" : 1.01
    }

)
print result.inserted_id

#https://docs.mongodb.org/getting-started/python/query/
cursor = db.qln.find()

for document in cursor:
    print(document)


Update

 

#https://docs.mongodb.org/manual/reference/method/db.collection.update/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

result = db.equity.update_one(
    {"shortsymbol": "k"},
    {"$set": {"shortentryprice": 107.5, "shortstoplossper": 1.40}}
)

print result.matched_count
print result.modified_count

Delete

 

#https://docs.mongodb.org/getting-started/python/remove/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

result = db.equity.delete_many({"shortsymbol": "k"})

print result.deleted_count

PostGreSQL database SQL for AK47

PostGreSQL database SQL for AK47

 

Here is the PostgresSQL entire DDL (data definition language) which will create all structures for tables for my initial AK-47 database. This was created using ‘Export Tables’ out of RazorSQL
http://razorsql.com/docs/how_to_export.html
I use this tool since it can run on Windows, Linux, and Mac OSX

Continue reading

My PostGres SQL Trading Database DDL Schema

My PostGres SQL Trading Database DDL Schema

Here is the current and first version of it to be loaded into PostGreSQL trading ddl postgres sql

This is the needed for my entire trading ut this will be tweaked to make it efficient. It is a lazy persons person for testing at the current moment.

You should use a dcent low cost front client like RazorSQL to interface with PostGres  http://razorsql.com/

Video links thread on Online Meetup LIVE Event: NOSQL vs SQL database smackdown, which one for what?

Video links thread  on Online Meetup LIVE Event: NOSQL vs SQL database smackdown, which one for what?

There are so many databases usedbut what for what reason. I really want to investigate this with others online. If you are interested in our poll on this on popularity, please, visit:

http://quantlabs.net/surveys/tick-db/

This should also cover the experience with pros and cons of operating systems as well including Windows, Linux, or Mac OSX.

When? Dec 15 at 7 PM EST

This will be delivered online via Goto Meeting. Also note as will there will no playback other than for Quant Elite members after this LIVE event.

LIVE Event: NOSQL vs SQL database smackdown, which one for what?

Monday, Dec 15, 2014, 7:00 PM

13 Members Went

Check out this Meetup →

 

Continue reading

How I converted FinancialDemo SQL database from SQL Server 2012 to SQL Server 2014 CTP2

How I converted FinancialDemo SQL database from SQL Server 2012 to SQL Server 2014 CTP2

This was a pain!

NOTE: That this is nowhere and is suggested for LIVE trading. It is not optimized for it but useful testing trading strategies in development. I will post a final database scheme as we get close to launch live trading day

Other Limitations of SQL Server 2014:

Your SQL Server 2014 cannot reside with any other SQL Server install on the same system. See

In Memory OLTP with SQL Server 2014

Note: I had to convert all table primary key ids from SQL data type int to bigint to accomodate .NET C# long type as I am using DateTime.Now.Ticks to store as a unique id. Not smart I know but quick and dirty fix! Proper fix will be needed with official release of SQL Server 2014 and before going into live trading. The reason for is this that IDENTITY(1,1) is not supported in SQL Server CTP2 for  Optimized In Memory tables. I know that sucks already.

 

Limitations listed in comment:

In Memory OLTP with SQL Server 2014

Download this MSSQL14FinanceDemoscript

Also, visit for the update C# Watcher for IQFeed which is updated to insert into SQL Server 2014 CTP

https://quantlabs.net/academy/cs-watcher-for-iqfeed-with-converted-to-sql-server-2014-ctp2-release/