Browse Source

Fix expiry calculations

Eren Yilmaz 6 years ago
parent
commit
7335c79b2c
3 changed files with 5 additions and 7 deletions
  1. 2 3
      create_new_stock.py
  2. 0 1
      model.py
  3. 3 3
      server_controller.py

+ 2 - 3
create_new_stock.py

@@ -1,5 +1,4 @@
-from datetime import timedelta
-from time import strptime
+from datetime import timedelta, datetime
 
 
 import model
 import model
 from model import cleanup
 from model import cleanup
@@ -7,7 +6,7 @@ from model import cleanup
 if __name__ == '__main__':
 if __name__ == '__main__':
     timeout = float(input('How long will the initial selling be available? (minutes):'))
     timeout = float(input('How long will the initial selling be available? (minutes):'))
     try:
     try:
-        expiry = strptime(model.current_db_time(), '%Y-%m-%d %H:%M:%S') + timedelta(minutes=timeout)
+        expiry = datetime.strptime(model.current_db_time(), '%Y-%m-%d %H:%M:%S') + timedelta(minutes=timeout)
         print(model.new_stock(expiry))
         print(model.new_stock(expiry))
         cleanup()
         cleanup()
     except OverflowError:
     except OverflowError:

+ 0 - 1
model.py

@@ -3,7 +3,6 @@ import re
 import sqlite3 as db
 import sqlite3 as db
 import sys
 import sys
 import uuid
 import uuid
-from datetime import timedelta, datetime
 from math import floor
 from math import floor
 
 
 from passlib.handlers.sha2_crypt import sha256_crypt
 from passlib.handlers.sha2_crypt import sha256_crypt

+ 3 - 3
server_controller.py

@@ -1,6 +1,5 @@
 import json
 import json
-from datetime import timedelta
-from time import strptime
+from datetime import timedelta, datetime
 
 
 from bottle import request, response
 from bottle import request, response
 import model
 import model
@@ -136,7 +135,8 @@ def order():
         if not model.user_owns_at_least(amount, user_id, ownable_id):
         if not model.user_owns_at_least(amount, user_id, ownable_id):
             return bad_request('You can not sell more than you own.')
             return bad_request('You can not sell more than you own.')
     try:
     try:
-        expiry = strptime(model.current_db_time(), '%Y-%m-%d %H:%M:%S') + timedelta(minutes=time_until_expiration)
+        expiry = datetime.strptime(model.current_db_time(), '%Y-%m-%d %H:%M:%S') + \
+                 timedelta(minutes=time_until_expiration)
     except OverflowError:
     except OverflowError:
         return bad_request('The expiration time is too far in the future.')
         return bad_request('The expiration time is too far in the future.')
     model.place_order(buy, ownership_id, limit, stop_loss, amount, expiry)
     model.place_order(buy, ownership_id, limit, stop_loss, amount, expiry)