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

Python: Shares Speculation System – Part 7



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 write the Function to Delete a Transaction from the System, and will write the last part of show_all_Transaction function.
First we will write a Function to Delete a Transaction, we have two types of Transactions “Buying” and “Selling” so the user will select the Transaction Type to delete.
1. Buying Transaction: If the user select to Delete a Buying Transaction, we will call show_all function to display all the Buying Transactions and the ask the user to Enter the ID of the record to be Deleted. Here is the Code ..

ali radwani python project learning sql codeing

Then we will print-out the Selected Transaction Details and ask the user to Confirm the Deleting action by Entering ‘Y’.
After Confirming we need to perform or to Aplay three parts of code:
1. Deleting the Buying Transaction from Buying Table (buy_t_table).
2. Deleting the Buying Record from the Budget Table.
3. Updating the Share Basket Table (s_basket).
For the “Update the Share Basket Table (s_basket).” we need to Subtract the amount of the shares from the Share Basket.
Here is the code for all three action..

The Same actions will be taken if the user select to Delete a Selling
transaction. So if the user select “2. Selling Transaction:” we will call show_all function to display all the Selling Transactions and the ask the user to Enter the ID of the record to be Deleted and will display the Transaction Details. Here is the Code ..

And will waite for the user to Confirm the Deleting action, then again three blocks of code will Delete and update records in our system, here are the code ..

Now we finish the def del_trans(): Function to Delete a Buying or Selling Transaction and will work on the last part of def show_all_trans (inside = ‘No’, show=’3′): to Show/Display both Buying and Selling Transactions in one table format. To do so First we will RUN two SQL commands to ‘fetchall’ Buying and Selling Transaction… Here is the code ..


# Get All Sell Transactions Order by id desc
c.execute (" select * from sell_t_table where st_id > 0 order by st_id desc")
show_s_trans = c.fetchall()

# Get All buy Transactions Order by id desc
c.execute (" select * from buy_t_table where bt_id > 0 order by bt_id desc")
show_b_trans = c.fetchall()

Then we print-out the Table header as the following line:
print(“\n”,” “*11,”{:<9}{:<13}{:<30}{:<16}{:<11}{:<15}{}”.format(‘ID’,’Date’,’Share Name’,’SAmount’,’Price’,’Cost’,’Income’))
Then using a For loop we will print-out the transactions in same format of the table header .. Here is the full Code

Last thing we will print the Totals of Investment, Incomes and the Net Profit.


print(" "*73,'Total Investment is: {:,}'.format(total_inv))
print(" "*76,'Total Incomes is: {:,}'.format(total_inc))
print(" "*75,"-"*30,"\n"," "*75,' Net Profit is: {:,} '.format(total_inc - total_inv))

We Done with this Part ..
Coming Up: In the Next post we will write the Function to Edit a Transaction.

[NOTES]
1. Part-1 has no code file.
2. We are applying some basic Validations on some part of the code, and assuming that the user will not enter a messy data.
3. This Application Purpose for Saving Transactions and NOT for Desetion Making and Dose’t Have any type of AI or ML Model to Predict the Prices and/or Giving Sugestions on Buying or Selling Shares.
:: Shares Speculation System ::

Part 1 Part 2 Part 3 Part 4 Part 5
Part 6 Part 7 Part 8

All the code are available ..

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


Follow me on Twitter..

By: Ali Radwani

  1. No comments yet.
  1. No trackbacks yet.

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: