def update_interests(): print "update_interests" connect_db() powers = {} investor = Investor.objects(is_active=True).first() interests = get_lending_interest(investor, "BTC") qrate = sorted(interests, key=lambda x:x["rate"])[:5][0] # quantil qrate = Decimal(qrate["rate"]) interest = Interest(investor_id=investor.id, currency="BTC", qrate=qrate) interest.save()
def __init__(self): if 'instructor' not in session: return redirect(url_for('instructor_login')) self.newInstructor = Instructor() self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription()
def __init__(self): self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson()
def make_loans(): connect_db() investor = Investor.objects(is_active=True).first() history = get_lending_history(investor) # *********** hitory cash = get_lending_balance(investor) # *********** cash offers = get_lending_offers(investor) # *********** offers active = get_lending_active(investor) # *********** active currency = "BTC" balance = Decimal(cash.get(currency, 0)) obalance = sum([Decimal(o["amount"]) for o in offers.get(currency, [])]+[Decimal(0)]) abalance = sum([Decimal(a["amount"])+Decimal(a["fees"]) for a in active if a["currency"] == currency]+[Decimal(0)]) for h in history: if LoanHistory.objects(order_id=h["id"]).only("id").count(): continue currency = h["currency"] l = LoanHistory(investor_id=investor.id) l.order_id = h["id"] l.currency = currency l.amount = h["amount"] l.rate = h["rate"] l.duration = h["duration"] l.open = str2time(h["open"]) l.close = str2time(h["close"]) l.fee = h["fee"] l.earned = h["earned"] l.interest = h["interest"] l.balance = balance+obalance l.abalance = abalance l.save() total = balance + obalance + abalance #estimate balance print "%s balances f: %s, o: %s, a: %s = t: %s" % (currency, balance, obalance, abalance, total) BTC balances f: 0, o: 0.01847761, a: 0.35108246 = t: 0.36956007 qrate_list = Interest.objects(Q(investor_id=investor.id)&Q(currency=currency)).order_by("-created").distinct("qrate")[:24] if len(qrate_list) < 24: return is_trade = True # Logic TODO # History rate analize and something else # if balance < total/2: is_trade = False rate = sorted(qrate_list)[12] # average amount = min(balance, max(total/5, MIN_AMOUNT["BTC"])) if is_trade and balance > 0: print investor, currency, amount, rate ret = make_lending_offer(investor, currency, amount, rate, 2, "", autoRenew=0) if ret: balance -= amount investor.last_update = datetime.datetime.now() investor.save()
class InstructorController(): def __init__(self): if 'instructor' not in session: return redirect(url_for('instructor_login')) self.newInstructor = Instructor() self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() def dashboar(self): data = {} #return render_template("instructor/dashboard.html", data=data) return session['instructor'] def select_interests(): data = {} data['loggedIn'] = False if 'student' in session: student_interests = self.newStudent_interest.get_student_interests( session['student']['name']) data['selected_interests'] = [] if student_interests: for interest in student_interests: #print(interest) data['selected_interests'].append(interest['interest_id']) data['loggedIn'] = True data['student'] = session['student'] data['interests'] = self.newInterest.interests() return render_template("fields.html", data=data) else: return redirect(url_for('index')) def toggle_interests(): if request.method == 'POST': newStudent_interest = Student_interest() interest = request.form['interest'] student_name = session['student']['name'] action = request.form['action'] if action == 'add': data = newStudent_interest.add(student_name, interest) if action == 'remove': data = newStudent_interest.remove(student_name, interest) return json.dumps({'status': data})
def __init__(self): if 'student' not in session: return redirect(url_for('index')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response()
def __init__(self): if 'instructor' in session: self.loggedIn = True self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response()
def __init__(self): if 'instructor' in session: self.loggedIn = True else: return redirect(url_for('instructor_login')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response() self.uploadFolder = 'static/images/courses_cover_photos' self.allowedExtensions = set(['png', 'jpg', 'jpeg', 'gif', 'psd'])
class StudentController(): def __init__(self): self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() def dashboard(self): data = {} data['loggedIn'] = False if 'student' in session: student_id = ObjectId(session['student']['id']) student_subscriptions = self.newStudent_subscription.get_student_subscriptions(student_id) student_interests = self.newStudent_interest.get_student_interests(session['student']['name']) data['selected_interests'] = [] data['interest_courses'] = [] data['subscribed'] = [] if student_interests: for interest in student_interests: #print(interest) myInterest = self.newInterest.get_interest_by_id(interest['interest_id']) data['selected_interests'].append(myInterest['name']) interest_courses = self.newCourse_interest.get_interest_courses(interest['interest_id']) if interest_courses: for interest_course in interest_courses: course = self.newCourse.get_course_by_id(interest_course['course_id']) if course not in data['interest_courses']: course_subscription = self.newStudent_subscription.get_course_subscriptions(interest_course['course_id']) course['subscribed'] = course_subscription.count() data['interest_courses'].append(course) if student_subscriptions: for subscribed in student_subscriptions: course = self.newCourse.get_course_by_id(subscribed['course_id']) course_subscription = self.newStudent_subscription.get_course_subscriptions(subscribed['course_id']) course['subscribed'] = course_subscription.count() data['subscribed'].append(course) data['loggedIn'] = True data['student'] = session['student'] data['interests'] = self.newInterest.interests() return render_template("dashboard.html", data=data) else: return redirect(url_for('index')) def select_interests(self): data = {} data['loggedIn'] = False if 'student' in session: student_interests = self.newStudent_interest.get_student_interests(session['student']['name']) data['selected_interests'] = [] if student_interests: for interest in student_interests: #print(interest) data['selected_interests'].append(interest['interest_id']) data['loggedIn'] = True data['student'] = session['student'] data['interests'] = self.newInterest.interests() return render_template("fields.html", data=data) else: return redirect(url_for('index')) def toggle_interests(self): if request.method == 'POST': newStudent_interest = Student_interest() interest = request.form['interest'] student_name = session['student']['name'] action = request.form['action'] if action == 'add': data = newStudent_interest.add(student_name, interest) if action == 'remove': data = newStudent_interest.remove(student_name, interest) return json.dumps({'status':data});
def __init__(self): self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription()