def confirm_withdraw_p2p(Req, S, PrivateKey): Transfer = CardP2PTransfers.objects.get(user=Req.user, confirm_key=S, status="created") IsCancel = Req.REQUEST.get("do", None) if ( Transfer.status == "processing" or Transfer.status == "auto" or Transfer.status == "created" ) and IsCancel is not None: Transfer.status = "order_cancel" Transfer.save() order = Transfer.order order.status = "order_cancel" order.save() add_trans(order.transit_2, Transfer.amnt, Transfer.currency, order.transit_1, order, "order_cancel", S, True) t = loader.get_template("simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_cancel Dict["simple_msg"] = settings.withdraw_msg_cancel caching().delete("balance_" + str(Req.user.id)) return tmpl_context(Req, t, Dict) if Transfer.status != "created": raise TransError("hacker " + Req.user.username) ##add trans may be there Transfer.status = "processing" Transfer.sign_record(PrivateKey) Transfer.save() t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok notify_admin_withdraw(withdraw_p2p(Transfer)) return tmpl_context(Req, t, Dict)
def confirm_withdraw_emoney(Req, S, PrivateKey): Transfer = TransOut.objects.get(user=Req.user, confirm_key=S, status='created') IsCancel = Req.REQUEST.get("do", None) if Transfer.status == "created" and IsCancel is not None: Transfer.status = "canceled" Transfer.save() order = Transfer.order order.status = "canceled" order.save() add_trans(order.transit_2, Transfer.amnt, Transfer.currency, order.transit_1, order, "canceled", S, False) t = loader.get_template("simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_cancel Dict["simple_msg"] = settings.withdraw_msg_cancel caching().delete("balance_" + str(Req.user.id)) return tmpl_context(Req, t, Dict) if Transfer.status != "created": raise TransError("hacker " + Req.user.username) ##add trans may be there Transfer.status = "processing" Transfer.sign_record(PrivateKey) Transfer.save() t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok return tmpl_context(Req, t, Dict)
def confirm_withdraw_currency(Req, S, PrivateKey): S = S.replace("\n", "").replace(" ", "") Transfer = CryptoTransfers.objects.get(status="created", confirm_key=S) ##add trans may be there AccountTo = Accounts.objects.get(user=Transfer.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = TradePairs.objects.get(currency_on=Transfer.currency, currency_from=Transfer.currency) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response["Content-Type"] = "application/json" return Response order = Orders( user=Transfer.user, currency1=Transfer.currency, currency2=Transfer.currency, price=Transfer.amnt, sum1_history=Transfer.amnt + Transfer.comission, sum2_history=Transfer.amnt, sum1=Transfer.amnt + Transfer.comission, sum2=Transfer.amnt, transit_1=AccountTo, transit_2=TradePair.transit_from, trade_pair=TradePair, status="created", ) order.save() order.status = "processing" order.save() Transfer.order = order Transfer.status = "processing" Transfer.sign_record(PrivateKey) Transfer.save() # TODO add process exception in withdraw crypto currency add_trans( AccountTo, Transfer.amnt + Transfer.comission, Transfer.currency, TradePair.transit_from, order, "withdraw", S, True, ) t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok caching().delete("balance_" + str(Transfer.user.id)) notify_admin_withdraw(withdraw_crypto(Transfer)) return tmpl_context(Req, t, Dict)
def notification(Req): if not Req.user.is_authenticated(): return denied(Req) else: t = loader.get_template("notify.html") Dict = {} caching().delete("balance_" + str(Req.user.id) ) List = list(main.models.Msg.objects.filter(user_to = Req.user,user_from_id = 1, user_hide_to = "false" )) page = Req.GET.get('page', 1) PageObject = my_cached_paging("notify_" + str(Req.user.id), main.models.Msg, page, List) Dict["msgs"] = PageObject.object_list Dict["paging"] = PageObject main.models.Msg.objects.filter(user_to = Req.user,user_from_id = 1, user_hide_to = "false" ).update(user_seen_to = "true") return http_tmpl_context(Req, t, Dict )
def confirm_withdraw_currency(Req, S, PrivateKey=''): S = S.replace("\n", "").replace(" ", "") Transfer = CryptoTransfers.objects.get(status="created", confirm_key=S) ##add trans may be there AccountTo = get_account(user=Transfer.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = TradePairs.objects.get(currency_on=Transfer.currency, currency_from=Transfer.currency) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response order = Orders(price=Decimal("1"), user=Transfer.user, currency1=Transfer.currency, currency2=Transfer.currency, sum1_history=Transfer.amnt + Transfer.comission, sum2_history=Transfer.amnt, sum1=Transfer.amnt + Transfer.comission, sum2=Transfer.amnt, transit_1=AccountTo.acc(), transit_2=TradePair.transit_from, trade_pair=TradePair, status="created", ) order.save() order.status = "processing" order.save() Transfer.order = order Transfer.status = "processing" Transfer.sign_record(PrivateKey) Transfer.save() # TODO add process exception in withdraw crypto currency add_trans(AccountTo.acc(), Transfer.amnt + Transfer.comission, Transfer.currency, TradePair.transit_from, order, "withdraw", S, False) t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok caching().delete("balance_" + str(Transfer.user.id)) notify_admin_withdraw(withdraw_crypto(Transfer)) return tmpl_context(Req, t, Dict)
def time(Req): Dict = {"use_f2a": False} cache = caching() if Req.user.is_authenticated(): Dict["logged"] = True if Req.session.has_key("deal_comission"): Dict["deal_comission"] = Req.session["deal_comission_show"] else: ComisObj = UserCustomSettings.objects.get(user_id=Req.user.id, setting__title="deal_comission") DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100")) Req.session["deal_comission_show"] = DealComission Req.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value)) Dict["deal_comission"] = DealComission if Req.session.has_key("use_f2a"): Dict["use_f2a"] = Req.session["use_f2a"] else: Dict["use_f2a"] = False else: Dict["deal_comission"] = "0.10" if Req.session.session_key is not None: cache.set("chat_" + Req.session.session_key, Req.user.username, 60000) Dict["usd_uah_rate"] = get_memory_var("usd_uah_rate") Dict["time"] = (datetime.now() - datetime(1970,1,1)).total_seconds() # datetime.now().strftime("%d.%m.%y %H:%M:%S") Dict["sessionid"] = Req.session.session_key return json_true(Req, Dict)
def try_login(request): username = request.REQUEST.get('login') password = request.REQUEST.get('password') user = authenticate(username = username, password = password) if user is not None: if user.is_active is True: if not check2fa(user): login(request, user) request.result_auth = "good" request.session['auth_user_computered'] = True request.session['use_f2a'] = False request.session['user_id'] = user.id ComisObj = UserCustomSettings.objects.get(user_id = request.user.id, setting__title = "deal_comission" ) DealComission = format_numbers4( Decimal(ComisObj.value)*Decimal("100") ) request.session["deal_comission_show"] = DealComission request.session["deal_comission"] = format_numbers4( Decimal( ComisObj.value ) ) request.session['username'] = user.username request.session['email'] = user.email notify_email(user, "auth_notify", request ) return HttpResponse("good") else: cache = caching() key = "2fa_%s" % (generate_key("2fa_")) cache.set(key, user.id, 300) return HttpResponse(key) else: request.result_auth = "bad" notify_email(user, "auth_notify", request ) return HttpResponse("bad") else: notify_email_admin(request, "try_login" ) return HttpResponse("very_bad")
def __inner_remove_order(Order, User): Order2Remove = Orders.objects.get(user = User, id = int(Order), status="processing" ) Title = Order2Remove.trade_pair.url_title LOCK = "trades" + Title TradeLock = my_lock(LOCK) try : Order2Remove.status = "canceled" Order2Remove.save() Account = Accounts.objects.get(user = User, currency = Order2Remove.currency1) add_trans(Order2Remove.transit_1, Order2Remove.sum1, Order2Remove.currency1, Account, Order2Remove, "order_cancel") cache = caching() cache.delete_many(["buy_list_" + Title, "sell_list_" + Title, "balance_" + str(User.id), 'client_orders_' + str(User.id) + "_" + Title]) my_release(TradeLock) return True except: my_release(TradeLock) return False
def time(Req): Dict = {"use_f2a": False} cache = caching() if Req.user.is_authenticated(): Dict["logged"] = True if Req.session.has_key("deal_comission"): Dict["deal_comission"] = Req.session["deal_comission_show"] else: ComisObj = UserCustomSettings.objects.get(user_id=Req.user.id, setting__title="deal_comission") DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100")) Req.session["deal_comission_show"] = DealComission Req.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value)) Dict["deal_comission"] = DealComission if Req.session.has_key("use_f2a"): Dict["use_f2a"] = Req.session["use_f2a"] else: Dict["use_f2a"] = False else: Dict["deal_comission"] = "0.10" if Req.session.session_key is not None: cache.set("chat_" + Req.session.session_key, Req.user.username, 60000) Dict["usd_uah_rate"] = get_memory_var("usd_uah_rate") Dict["time"] = datetime.now().strftime("%d.%m.%y %H:%M:%S") Dict["sessionid"] = Req.session.session_key return json_true(Req, Dict)
def setup_g2a(request): CachedKey = 'qr_' + str(request.user.id) cache = caching() Dict = {} (base32, base16) = g2f.newSecret() Link = g2f.getQRLink(request.user.username, base32) imgRequest = urllib2.Request(Link) imgData = urllib2.urlopen(imgRequest).read() valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % ( request.user.id) F = open(valid_image, 'wb') F.write(imgData) F.close() Dict["g2a_private_key32"] = base32 Dict["g2a_private_key"] = base16 temp_qr = generate_key("qr") Dict["g2a_qr"] = "/profile/qr?key=%s" % (temp_qr) cache.set("temp_qr" + temp_qr, request.user.id, 300) cache.set(CachedKey, base32, 600) return json_true(request, Dict)
def setup_g2a_verify(request, val): CachedKey = 'qr_' + str(request.user.id) cache = caching() Secret = cache.get(CachedKey, False) if not Secret: return json_false500(request) if g2f.auth(Secret, val): Setting = None SettingType = CustomSettings.objects.get(title="g2a") try: Setting = UserCustomSettings.objects.get(user=request.user, setting=SettingType) except UserCustomSettings.DoesNotExist: Setting = UserCustomSettings(user=request.user, setting=SettingType, value=SettingType.def_value) valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % ( request.user.id) os.remove(valid_image) Setting.value = Secret Setting.save() request.session['use_f2a'] = True return json_true(request) else: return json_false500(request)
def setup_g2a_verify(request, val): CachedKey = 'qr_' + str(request.user.id) cache = caching() Secret = cache.get(CachedKey, False) if not Secret: return json_false500(request) if g2f.auth(Secret, val): Setting = None SettingType = CustomSettings.objects.get(title = "g2a") try : Setting = UserCustomSettings.objects.get(user = request.user, setting = SettingType ) except UserCustomSettings.DoesNotExist: Setting = UserCustomSettings(user = request.user, setting = SettingType, value = SettingType.def_value ) valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (request.user.id) os.remove(valid_image) Setting.value = Secret Setting.save() request.session['use_f2a'] = True return json_true(request) else : return json_false500(request)
def setup_g2a(request): CachedKey = 'qr_' + str(request.user.id) cache = caching() Dict = {} (base32, base16) = g2f.newSecret() Link = g2f.getQRLink(request.user.username, base32) imgRequest = urllib2.Request(Link) imgData = urllib2.urlopen(imgRequest).read() valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (request.user.id) F = open(valid_image,'wb') F.write(imgData) F.close() Dict["g2a_private_key32"] = base32 Dict["g2a_private_key"]= base16 temp_qr = generate_key("qr") Dict["g2a_qr"] = "/profile/qr?key=%s" % ( temp_qr ) cache.set("temp_qr" + temp_qr, request.user.id, 300) cache.set(CachedKey, base32,600) return json_true(request, Dict)
def auth(Req): Nonce = Req.REQUEST.get("nonce", None) if Nonce is None: return json_false500(Req) (Sign, PublicKey) = (None, None) Sign = Req.META.get('HTTP_API_SIGN', None) if Sign is None: return json_false500(Req, { "description": "invalid_params", "key": "api_sign" }) PublicKey = Req.META.get('HTTP_PUBLIC_KEY', None) if PublicKey is None: return json_false500(Req, { "description": "invalid_params", "key": "public_key" }) try: Req.user = check_api_sign(PublicKey, Sign, Req.body) Cache = caching() Cache.set("nonce_" + PublicKey, int(Nonce), 50000) Nonce = Cache.get("nonce_" + PublicKey) return json_true(Req, {"nonce": Nonce, "public_key": PublicKey}) except: return json_false500(Req, {"description": "auth_faild"})
def login_f2a(request): key = request.REQUEST.get('key', None) password = request.REQUEST.get('password', None) cache = caching() UserIdCached = cache.get(key, False) if not UserIdCached: return json_false500(request) UserIdCachedInt = int(UserIdCached) Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a") if auth(Setting.value, password): user = User.objects.get(id=UserIdCachedInt) user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) request.result_auth = "good" request.session['auth_user_computered'] = True request.session['use_f2a'] = True request.session['user_id'] = user.id request.session['username'] = user.username request.session['email'] = user.email ComisObj = UserCustomSettings.objects.get(user_id=request.user.id, setting__title="deal_comission") DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100")) request.session["deal_comission_show"] = DealComission request.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value)) notify_email(user, "auth_notify", request) return HttpResponse("good") else: return json_false500(request)
def __inner_remove_order(Order, User): Order2Remove = Orders.objects.get(user=User, id=int(Order), status="processing") Title = Order2Remove.trade_pair.url_title LOCK = "trades" + Title TradeLock = my_lock(LOCK) try: Order2Remove.status = "canceled" Order2Remove.save() Account = Accounts.objects.get(user=User, currency=Order2Remove.currency1) add_trans(Order2Remove.transit_1, Order2Remove.sum1, Order2Remove.currency1, Account, Order2Remove, "order_cancel") cache = caching() cache.delete_many([ "buy_list_" + Title, "sell_list_" + Title, "balance_" + str(User.id), 'client_orders_' + str(User.id) + "_" + Title ]) my_release(TradeLock) return True except: my_release(TradeLock) return False
def confirm_withdraw_liqpay(Req, S): Transfer = LiqPayTrans.objects.get(user = Req.user, status = "created", confirm_key = S) liqpay_class = liqpay("ru", Transfer.currency.title) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3) : Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response ##add trans may be there AccountTo = Accounts.objects.get(user = Req.user, currency = Transfer.currency) ## if not by reference, but by users TradePair = liqpay_class.get_traid_pair() order = Orders( user = Req.user, currency1 = Transfer.currency, currency2 = Transfer.currency, sum1_history = Transfer.amnt, sum2_history = Transfer.amnt, sum1 = Transfer.amnt, sum2 = Transfer.amnt, transit_1 = AccountTo, transit_2 = TradePair.transit_from , trade_pair = TradePair, status = "created" ) order.save() add_trans(AccountTo, Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", S, True) order.status = "processing" order.save() Transfer.order = order Transfer.status = "processing" Transfer.save() t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok caching().delete("balance_" + str(Req.user.id) ) return tmpl_context(Req, t, Dict)
def login_f2a_operation(request): password = request.REQUEST.get('password', None) UserIdCachedInt = request.user.id Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a") if auth(Setting.value, password): cache = caching() Key = "f2a_" + generate_key("fa_") cache.set(Key, UserIdCachedInt, 20) return HttpResponse(Key) return json_false500(request)
def confirm_withdraw_liqpay(Req, S): Transfer = LiqPayTrans.objects.get(user=Req.user, status="created", confirm_key=S) liqpay_class = liqpay("ru", Transfer.currency.title) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response ##add trans may be there AccountTo = get_account(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = liqpay_class.get_traid_pair() order = Orders(user=Req.user, price=Decimal("1"), currency1=Transfer.currency, currency2=Transfer.currency, sum1_history=Transfer.amnt, sum2_history=Transfer.amnt, sum1=Transfer.amnt, sum2=Transfer.amnt, transit_1=AccountTo.acc(), transit_2=TradePair.transit_from, trade_pair=TradePair, status="created" ) order.save() add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", S, False) order.status = "processing" order.save() Transfer.order = order Transfer.status = "processing" Transfer.save() t = loader.get_template("ajax_simple_msg.html") Dict = {} Dict["title"] = settings.withdraw_ok Dict["simple_msg"] = settings.withdraw_msg_ok caching().delete("balance_" + str(Req.user.id)) return tmpl_context(Req, t, Dict)
def g2a_qr(request): key = request.REQUEST.get('key') cache = caching() Secret = cache.get("temp_qr" + key, False) if not Secret: return json_false500(request) valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (Secret) with open(valid_image, "rb") as f: Response = HttpResponse(f.read(), mimetype="image/png") Response['Cache-Control'] = 'max-age=0' return Response
def pin_image(request, Key): cache = caching() CachedKey = "pin_" + Key UserId = cache.get(CachedKey, False) if int(request.user.id) != int(UserId) : return denied(request) Pin = PinsImages.objects.get( user_id = int(UserId) ) valid_image = settings.ROOT_PATH +"pins_images/pin_%i.png" % ( int(UserId) ) with open(valid_image, "rb") as f: Response = HttpResponse(f.read(), mimetype="image/png") Response['Cache-Control'] = 'max-age=0' return Response
def delete_tornado_cache(t, keys): print "delete all cache" s = TornadoServer.get_instance() cache = s.cache start = time.time() cache = caching() keys.append("state") cache.delete_many(keys) print "setup cache state" #cache.set("state", t, 60000) print "delete all cache timing" end = time.time() print end - start
def pin_image(request, Key): cache = caching() CachedKey = "pin_" + Key UserId = cache.get(CachedKey, False) if int(request.user.id) != int(UserId): return denied(request) Pin = PinsImages.objects.get(user_id=int(UserId)) valid_image = settings.ROOT_PATH + "pins_images/pin_%i.png" % (int(UserId)) with open(valid_image, "rb") as f: Response = HttpResponse(f.read(), mimetype="image/png") Response['Cache-Control'] = 'max-age=0' return Response
def check_freq(Type, Count): Now = calendar.timegm(gmtime()) cache = caching() Prev = cache.get(Type) if Prev: Prev = int(Prev) if Now - Prev > Count: cache.set(Type, str(Now)) return True else: cache.set(Type, str(Now)) return True return False
def get(self): start = time.time() cache = caching() with transaction.atomic(): remove_orders() process_deals(start, cache) s = TornadoServer.get_instance() if len(s.keys4delete) > 0: delete_tornado_cache(start, s.keys4delete) print s.keys4delete s.keys4delete = [] end = time.time() print "=" * 64 print end - start print "=" * 64 self.write({"status": True, "time": end - start})
def try_login(request): username = request.REQUEST.get('login') password = request.REQUEST.get('password') usr = None # try: usr = User.objects.get(email=username) #except User.DoesNotExist: # request.result_auth = "bad" # return HttpResponse("bad") user = authenticate(username=usr.username, password=password) if user is not None: if user.is_active is True: if not check2fa(user): login(request, user) request.result_auth = "good" request.session['auth_user_computered'] = True request.session['use_f2a'] = False request.session['user_id'] = user.id ComisObj = UserCustomSettings.objects.get( user_id=request.user.id, setting__title="deal_comission") DealComission = format_numbers4( Decimal(ComisObj.value) * Decimal("100")) request.session["deal_comission_show"] = DealComission request.session["deal_comission"] = format_numbers4( Decimal(ComisObj.value)) request.session['username'] = user.username request.session['email'] = user.email notify_email(user, "auth_notify", request) return HttpResponse("good") else: cache = caching() key = "2fa_%s" % (generate_key("2fa_")) cache.set(key, user.id, 300) return HttpResponse(key) else: request.result_auth = "bad" notify_email(user, "auth_notify", request) return HttpResponse("bad") else: notify_email_admin(request, "try_login") return HttpResponse("very_bad")
def get(self, order_id): start = time.time() order = Orders.objects.get(id=order_id, status="created") s = TornadoServer.get_instance() try: with transaction.atomic(): FromAccount = Accounts.objects.get(user=order.user, currency=order.currency1) add_trans(FromAccount, order.sum1_history, order.currency1, order.transit_1, order, "deposit") order.status = "processing" order.save() cache = caching() try: i = order.user_id s.keys4delete.append("balance_" + str(i)) delete_user_state(i, start) print "got trans from %i" % i Title = order.trade_pair.url_title CachedKey1 = 'client_orders_' + str(i) + "_" + Title CachedKey2 = 'balance_' + str(i) s.keys4delete.append(CachedKey1) s.keys4delete.append(CachedKey2) s.keys4delete.append("buy_list_" + Title) s.keys4delete.append("sell_list_" + Title) except: traceback.print_exc() print "problem in working with cache" end = time.time() print "add trans timing" print end - start self.write({"status": True, "time": end - start}) except: traceback.print_exc() order.status = "core_error" print "add trans timing" end = time.time() print end - start order.save() self.set_status(500)
def btce_btc_usd(Req, Type, Time): CachedKey = 'btce_' + Type + '_stat' + Time cache = caching() Cached = cache.get(CachedKey, False) if Cached: return cached_json_object(Cached) Dict = {} Cursor = connection.cursor() AskList = get_price_ask(Cursor, Type, Time) BidList = get_price_bid(Cursor, Type, Time) (VolList, Last) = get_price_vol(Cursor, Type, Time) Dict = {"data_bid": BidList, "data_ask": AskList, "data_vol": VolList, "last": Last} RespJ = json.JSONEncoder().encode(Dict) if int(Time) > 0: cache.set(CachedKey, RespJ, 5) else: cache.set(CachedKey, RespJ) return cached_json_object(RespJ)
def process_auto(Req, Res, TradePair): Dict = None Encoder = json.JSONEncoder() if Res["start_sum"] == Res["last_sum"]: Dict = {"status": True, "description": _("The order has been created")} elif Res["last_sum"] < TradePair.min_trade_base: Dict = { "status": "processed", "description": _("Your order has been fully processed successfully"), "start_sum_to_buy": str(Res["start_sum"]), "last_sum_to_buy": str(Res["last_sum"]) } elif Res["start_sum"] > Res["last_sum"]: Dict = { "status": "processed", "description": _("Your order has been processed partial"), "start_sum_to_buy": str(Res["start_sum"]), "last_sum_to_buy": str(Res["last_sum"]) } DeleteKeys = [] cache = caching() Type = TradePair.url_title for i in Res["users_bothered"]: CachedKey1 = 'client_orders_' + str(i) + "_" + Type CachedKey2 = 'balance_' + str(i) DeleteKeys.append(CachedKey1) DeleteKeys.append(CachedKey2) #deal_list_btc_uah DeleteKeys.append("deal_list_" + Type) DeleteKeys.append("sell_list_" + Type) DeleteKeys.append("buy_list_" + Type) cache.delete_many(DeleteKeys) return Encoder.encode(Dict)
def auth(Req): Nonce = Req.REQUEST.get("nonce", None) if Nonce is None : return json_false500(Req) (Sign, PublicKey) = (None, None) Sign = Req.META.get('HTTP_API_SIGN', None) if Sign is None: return json_false500(Req, {"description":"invalid_params", "key": "api_sign"} ) PublicKey = Req.META.get('HTTP_PUBLIC_KEY', None) if PublicKey is None: return json_false500(Req, {"description":"invalid_params","key": "public_key"} ) try : Req.user = check_api_sign(PublicKey, Sign, Req.body ) Cache = caching() Cache.set("nonce_" + PublicKey, int(Nonce), 50000) Nonce = Cache.get("nonce_" + PublicKey) return json_true(Req, {"nonce": Nonce,"public_key": PublicKey}) except: return json_false500(Req,{"description":"auth_faild"})
def process_auto(Req, Res, TradePair): Dict = None Encoder = json.JSONEncoder() if Res["start_sum"] == Res["last_sum"]: Dict = {"status": True, "description": _("The order has been created") } elif Res["last_sum"] < TradePair.min_trade_base: Dict = {"status": "processed", "description": _("Your order has been fully processed successfully"), "start_sum_to_buy": str(Res["start_sum"]), "last_sum_to_buy": str(Res["last_sum"]) } elif Res["start_sum"] > Res["last_sum"] : Dict = {"status": "processed", "description": _("Your order has been processed partial"), "start_sum_to_buy": str(Res["start_sum"]), "last_sum_to_buy": str(Res["last_sum"]) } DeleteKeys = [] cache = caching() Type = TradePair.url_title for i in Res["users_bothered"]: CachedKey1 = 'client_orders_' + str(i) + "_" + Type CachedKey2 = 'balance_' + str(i) DeleteKeys.append(CachedKey1) DeleteKeys.append(CachedKey2) #deal_list_btc_uah DeleteKeys.append("deal_list_" + Type) DeleteKeys.append("sell_list_" + Type) DeleteKeys.append("buy_list_" + Type) cache.delete_many(DeleteKeys) return Encoder.encode(Dict)
def btce_btc_usd(Req, Type, Time): CachedKey = 'btce_' + Type + '_stat' + Time cache = caching() Cached = cache.get(CachedKey, False) if Cached: return cached_json_object(Cached) Dict = {} Cursor = connection.cursor() AskList = get_price_ask(Cursor, Type, Time) BidList = get_price_bid(Cursor, Type, Time) (VolList, Last) = get_price_vol(Cursor, Type, Time) Dict = { "data_bid": BidList, "data_ask": AskList, "data_vol": VolList, "last": Last } RespJ = json.JSONEncoder().encode(Dict) if int(Time) > 0: cache.set(CachedKey, RespJ, 5) else: cache.set(CachedKey, RespJ) return cached_json_object(RespJ)
def __init__(self, *args): self.port = args[0] self.application = tornado.web.Application(args[1]) self.keys4delete = [] self.cache = caching()