Home > Learning, Lesson, Problem, Projects/Experiments, Python > Python: Shares Speculation System – Part 2

Python: Shares Speculation System – Part 2

Learning : Python, DataBase, SQL, SQlite3
Subject: Plan, Design and Build a Shares Speculation System

Project Card:
Project Name: Shares Speculation System
By: Ali
Date: 2.7.2020
Version: V01-2.7.2020

In this part we will set the database connection, create the Tables and Insert the Zero records. So first let’s do the Import and the database connection..

# Database connection

import sqlite3, os 

# Create the data-base and name it as Share_S_System. 
db_conn = sqlite3.connect ("Share_S_System.db") 

# Set the connection. 
c = db_conn.cursor() 

Now we will write the function to creates the Tables, we have five tables and this could be change during the project.

# Code to create the Tables

def create_tables_() :
    # to create tables. 
    sql_share_t =    "CREATE TABLE if not exists shares_name  (s_id INTEGER PRIMARY KEY AUTOINCREMENT, full_name text, abb_name text )" 
    sql_buy_t_t =   "CREATE TABLE if not exists buy_t_table (bt_id INTEGER PRIMARY KEY AUTOINCREMENT ,buy_date text, sn_id integer, buy_amount integer, buy_price float, cost float)" 
    sql_sell_t_t  = "CREATE TABLE if not exists sell_t_table (st_id INTEGER PRIMARY KEY AUTOINCREMENT, sell_date text, sn_id integer, sell_amount integer, sell_price float, profit float)" 
    sql_budget_t  = "CREATE TABLE if not exists budget_t (bud_id INTEGER PRIMARY KEY AUTOINCREMENT, bud_date text, bud_amount float, bud_note text )"  

    sql_year_roi =  "CREATE TABLE if not exists year_roi (y_id INTEGER PRIMARY KEY AUTOINCREMENT, bud_amount float, profits float, costs float, roi float, t_buy float, t_sell float )"


    input('\n .. Shares Speculation System Tables created.. Press any key .. ') 

Next we will Insert a ‘Zero’ records in the Tables, this weill set the ID’s field in each table to ‘0’ so with next records the AUTOINCREMENT will work as it should. here is the code ..

Last function in this part will be the Main-Menu of the system. The system will have five Menus each one will have it’s own page and functions to manage it, we will write all the needed functions. Here is the Main-Menu.

Coming Up: In Next part we will write the menu and the functions for the Budget Managment.

1. Part-1 has no code file.

:: Shares Speculation System ::

Part 1 Part 2 Part 3 Part 4

To Download my Python code (.py) files Click-Here

Follow me on Twitter..

By: Ali Radwani

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: