def create_order(User, Amnt1, Amnt2, Currency1, Currency2, TradePair, Status="created"): if TradePair.currency_on.id == Currency1.id: transit1 = TradePair.transit_on transit2 = TradePair.transit_from else: transit2 = TradePair.transit_on transit1 = TradePair.transit_from order = Orders(user=User, currency1=Currency1, currency2=Currency2, sum1_history=Amnt1, sum2_history=Amnt2, sum1=Amnt1, sum2=Amnt2, transit_1=transit1, transit_2=transit2, trade_pair=TradePair, status=Status) order.save() return order
def start_pay(Req, CurrencyTitle, Amnt): AmountStr = Decimal(Amnt) User = Req.user currency = CurrencyIn = Currency.objects.get(title=CurrencyTitle) user_account = Accounts.objects.get(user=User, currency=currency) if AmountStr < 0: raise TransError("NegativeAmount") trade_pair = TradePairs.objects.get(url_title="okpay_" + CurrencyTitle.lower()) if AmountStr < trade_pair.min_trade_base: raise TransError("MinAmount") order = Orders( user=User, currency1=currency, currency2=currency, price=AmountStr, sum1_history=AmountStr, sum2_history=AmountStr, sum1=AmountStr, sum2=AmountStr, transit_1=trade_pair.transit_on, transit_2=user_account, trade_pair=trade_pair, status="processing", ) order.save() ResultUrl = generate_result_url(order, User, Amnt) ServerResultUrl = generate_api_result_url(order, User, Amnt) currency_norm = "" if CurrencyTitle == "okpay_rur": currency_norm = "RUB" if CurrencyTitle == "okpay_usd": currency_norm = "USD" if CurrencyTitle == "okpay_eur": currency_norm = "EUR" if CurrencyTitle == "RUR": currency_norm = "RUB" if CurrencyTitle == "EUR": currency_norm = "EUR" if CurrencyTitle == "USD": currency_norm = "USD" Dict = { "order_id": str(order.id), "result_url": ResultUrl, "type": "okpay", "ext_details": "none", "currency": currency_norm, "server_url": ServerResultUrl, "amount": str(AmountStr), } Response = HttpResponse(json.JSONEncoder().encode(Dict)) Response["Content-Type"] = "application/json" return Response
def add_order(request): items = Cart.objects.all() for item in items: order = Orders(user=item.user, product=item.product, count=item.count, total=item.total) order.save() messages.success(request, "New Orders Placed Successfully") Cart.objects.all().delete() return redirect('profile')
def start_pay(Req, CurrencyTitle, Amnt): AmountStr = Decimal(Amnt) User = Req.user currency = CurrencyIn = Currency.objects.get(title=CurrencyTitle) user_account = Accounts.objects.get(user=User, currency=currency) if AmountStr < 0: raise TransError("NegativeAmount") trade_pair = TradePairs.objects.get(url_title="okpay_" + CurrencyTitle.lower()) if AmountStr < trade_pair.min_trade_base: raise TransError("MinAmount") order = Orders(user=User, currency1=currency, currency2=currency, price=AmountStr, sum1_history=AmountStr, sum2_history=AmountStr, sum1=AmountStr, sum2=AmountStr, transit_1=trade_pair.transit_on, transit_2=user_account, trade_pair=trade_pair, status="processing") order.save() ResultUrl = generate_result_url(order, User, Amnt) ServerResultUrl = generate_api_result_url(order, User, Amnt) currency_norm = '' if CurrencyTitle == 'okpay_rur': currency_norm = 'RUB' if CurrencyTitle == 'okpay_usd': currency_norm = 'USD' if CurrencyTitle == 'okpay_eur': currency_norm = 'EUR' if CurrencyTitle == 'RUR': currency_norm = 'RUB' if CurrencyTitle == 'EUR': currency_norm = 'EUR' if CurrencyTitle == 'USD': currency_norm = 'USD' Dict = { "order_id": str(order.id), "result_url": ResultUrl, "type": "okpay", "ext_details": "none", "currency": currency_norm, "server_url": ServerResultUrl, "amount": str(AmountStr) } Response = HttpResponse(json.JSONEncoder().encode(Dict)) Response['Content-Type'] = 'application/json' return Response
def generate_pay_request(self, User, Amount): currency = "" if self.__currency.title == "USD": currency = "USD" elif self.__currency.title == perfect_money_sdk.str_class_name()+"_eur": currency = "EUR" elif self.__currency.title == "EUR": currency = "EUR" elif self.__currency.title == perfect_money_sdk.str_class_name()+"_usd": currency = "USD" AmountStr = Decimal(Amount) user_account = Accounts.objects.get(user = User, currency = self.__currency) if AmountStr<0: raise TransError("NegativeAmount") if AmountStr < self.__min_amnt : raise TransError("MinAmount") order = Orders( user = User, currency1 = self.__currency, currency2 = self.__currency, price=AmountStr, sum1_history = AmountStr, sum2_history = AmountStr, sum1 = AmountStr, sum2 = AmountStr, transit_1 = self.__transit_account, transit_2 = user_account, trade_pair = self.__trade_pair, status = "processing" ) order.save() ResultUrl = self.generate_result_url(order, User, Amount ) ServerResultUrl = self.generate_api_result_url(order, User, Amount ) Dict = { "public_key": self.__public_id, "order_id": str(order.id), "result_url" : ResultUrl, "type":"perfectmoney", "ext_details":"none", "description" :self.description, "currency" :currency, "server_url": ServerResultUrl, "server_url_fail": self.generate_api_result_url_fail(order, User, Amount ), "amount": "%.2f" % float(AmountStr) } Response = HttpResponse( json.JSONEncoder().encode(Dict) ) Response['Content-Type'] = 'application/json' return Response
def generate_order_request(self, User, Amount): AmountStr = Decimal(Amount) user_account = Accounts.objects.get(user=User, currency=self.__currency) if AmountStr < 0: raise TransError("NegativeAmount") if AmountStr < self.__min_amnt: raise TransError("MinAmount") order = Orders(user=User, currency1=self.__currency, currency2=self.__currency, sum1_history=AmountStr, sum2_history=AmountStr, sum1=AmountStr, sum2=AmountStr, transit_1=self.__transit_account, transit_2=user_account, trade_pair=self.__trade_pair, status="processing" ) order.save() ResultUrl = self.generate_result_url(order, User, Amount) ServerResultUrl = self.generate_api_result_url(order, User, Amount) # Payment = "amt=%s&ccy=%s&details=%s&ext_details=%s&pay_way=privat24&order=%s&merchant=%s" % (str(AmountStr), self.__currency.title, self.description, "none", str(order.id), self.__public_id ) signature = self.signature(Payment) Dict = { "signature": signature, "public_key": self.__public_id, "order_id": str(order.id), "result_url": ResultUrl, "type": "privat24", "ext_details": "none", "description": self.description, "currency": self.__currency.title, "server_url": ServerResultUrl, "amount": str(AmountStr) } Response = HttpResponse(json.JSONEncoder().encode(Dict)) Response['Content-Type'] = 'application/json' return Response
def generate_pay_request(self, User, Amount): AmountStr = Decimal(Amount) user_account = Accounts.objects.get(user = User, currency = self.__currency) if AmountStr<0: raise TransError("NegativeAmount") if AmountStr<self.__min_amnt: raise TransError("MinAmount") order = Orders( user = User, currency1 = self.__currency, currency2 = self.__currency, sum1_history = AmountStr, sum2_history = AmountStr, sum1 = AmountStr, sum2 = AmountStr, transit_1 = self.__transit_account, transit_2 = user_account, trade_pair = self.__trade_pair, status = "created" ) order.save() ResultUrl = self.generate_result_url(order, User, Amount ) ServerResultUrl = self.generate_api_result_url(order, User, Amount ) m = hashlib.sha1(self.__private_key + str(AmountStr) + self.__currency.title + self.__public_key + str(order.id) + self.__type + self.__description + ResultUrl + ServerResultUrl ) signature = b64encode( m.digest() ) Dict = { "signature":signature, "public_key": self.__public_key, "order_id": str(order.id), "result_url" : ResultUrl, "language" : self.__language, "type" : self.__type, "description" :self.__description, "currency" :self.__currency.title, "server_url": ServerResultUrl, "amount": str(AmountStr) } Response = HttpResponse( json.JSONEncoder().encode(Dict) ) Response['Content-Type'] = 'application/json' return Response
def alter_order(new_data, old_data=None, user=None): if old_data is None: old_data = Orders() if user is None: user = User() new_data["customer"] = user.pk if str(old_data.status).upper() == 'PENDING': serializer = OrdersSerializer(old_data, data=new_data) if serializer.is_valid(): serializer.save() # order_change_email(user) serializer.fields.pop("customer") return True, serializer.data else: return False, serializer.errors return False, {"Error": "Order already confirmed. Contact us to have your order changed"}
def generate_pay_request(self, User, Amount): AmountStr = Decimal(Amount) user_account = Accounts.objects.get(user=User, currency=self.__currency) if AmountStr < 0: raise TransError("NegativeAmount") if AmountStr < self.__min_amnt: raise TransError("MinAmount") order = Orders(user=User, currency1=self.__currency, currency2=self.__currency, sum1_history=AmountStr, sum2_history=AmountStr, sum1=AmountStr, sum2=AmountStr, transit_1=self.__transit_account, transit_2=user_account, trade_pair=self.__trade_pair, status="processing") order.save() ResultUrl = self.generate_result_url(order, User, Amount) ServerResultUrl = self.generate_api_result_url(order, User, Amount) # Payment = "amt=%s&ccy=%s&details=%s&ext_details=%s&pay_way=privat24&order=%s&merchant=%s" % ( str(AmountStr), self.__currency.title, self.description, "none", str(order.id), self.__public_id) signature = self.signature(Payment) Dict = { "signature": signature, "public_key": self.__public_id, "order_id": str(order.id), "result_url": ResultUrl, "type": "privat24", "ext_details": "none", "description": self.description, "currency": self.__currency.title, "server_url": ServerResultUrl, "amount": str(AmountStr) } Response = HttpResponse(json.JSONEncoder().encode(Dict)) Response['Content-Type'] = 'application/json' return Response
def emoney_transfer_withdraw_secure(Req, Form, provider): Key = generate_key("p2p_ahuihui") Wallet = Form.cleaned_data["wallet"] Wallet = Wallet.replace(" ", "") Transfer = TransOut( wallet=Wallet, currency=Form.currency_instance, amnt=Form.cleaned_data["amnt"], user=Req.user, pub_date=datetime.datetime.now(), confirm_key=Key, provider=provider ) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response Transfer.save() AccountTo = get_account(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users trade_pair_title = provider + "_" + Form.currency_instance.title.lower() TradePair = TradePairs.objects.get(url_title=trade_pair_title) 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() # TODO add process exception in withdraw p2p add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, False) order.status = "processing" order.save() Transfer.order = order Transfer.save() #if settings.DEBUG is False: send_mail(_(u'Подтверждение вывода ') + settings.BASE_HOST, confirm_emoney_withdraw_email(Form.cleaned_data, Key), [Req.user.email], fail_silently=False)
def create_order(User, Amnt1, Amnt2, Currency1, Currency2, TradePair, Status = "created" ): if TradePair.currency_on.id == Currency1.id: transit1 = TradePair.transit_on transit2 = TradePair.transit_from else : transit2 = TradePair.transit_on transit1 = TradePair.transit_from order = Orders(user = User, currency1 = Currency1, currency2 = Currency2, sum1_history = Amnt1, sum2_history = Amnt2, sum1 = Amnt1, sum2 = Amnt2, transit_1 = transit1, transit_2 = transit2, trade_pair = TradePair, status = Status ) order.save() return order
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 emoney_transfer_withdraw_secure(Req, Form, provider): Key = generate_key("p2p_ahuihui") Wallet = Form.cleaned_data["wallet"] Wallet = Wallet.replace(" ", "") Transfer = TransOut( wallet=Wallet, currency=Form.currency_instance, amnt=Form.cleaned_data["amnt"], user=Req.user, pub_date=datetime.datetime.now(), confirm_key=Key, provider=provider, ) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response["Content-Type"] = "application/json" return Response Transfer.save() AccountTo = Accounts.objects.get(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users trade_pair_title = provider + "_" + Form.currency_instance.title.lower() TradePair = TradePairs.objects.get(url_title=trade_pair_title) order = Orders( user=Req.user, currency1=Transfer.currency, currency2=Transfer.currency, sum1_history=Transfer.amnt, sum2_history=Transfer.amnt, sum1=Transfer.amnt, price=Decimal("1"), sum2=Transfer.amnt, transit_1=AccountTo, transit_2=TradePair.transit_from, trade_pair=TradePair, status="created", ) order.save() # TODO add process exception in withdraw p2p add_trans(AccountTo, Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, True) order.status = "processing" order.save() Transfer.order = order Transfer.save() # if settings.DEBUG is False: send_mail( _(u"Подтверждение вывода ") + settings.BASE_HOST, confirm_emoney_withdraw_email(Form.cleaned_data, Key), settings.EMAIL_HOST_USER, [Req.user.email], fail_silently=False, )
def p2p_transfer_withdraw_secure(Req, Form): Key = generate_key("p2p_ahuihui") CardNumber = Form.cleaned_data["CardNumber"] CardNumber = CardNumber.replace(" ", "") Transfer = CardP2PTransfers( debit_credit="out", CardName=Form.cleaned_data["CardName"], CardNumber=CardNumber, currency=Form.currency_instance, amnt=Form.cleaned_data["amnt"], user=Req.user, pub_date=datetime.datetime.now(), confirm_key=Key ) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response Transfer.save() AccountTo = get_account(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = TradePairs.objects.get(url_title="p2p_transfers") 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() # TODO add process exception in withdraw p2p add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, True) order.status = "processing" order.save() Transfer.order = order Transfer.save() #if settings.DEBUG is False: send_mail(_(u'Подтверждение вывода ') + settings.BASE_HOST, confirm_p2p_withdraw_email(Form.cleaned_data, Key), settings.EMAIL_HOST_USER, [Req.user.email], fail_silently=False)
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 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 confirm_withdraw_bank(Req, S): Transfer = BankTransfers.objects.get(user=Req.user, status="created", confirm_key=S) ##add trans may be there AccountTo = get_account(user=Req.user, currency=Transfer.currency) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 2): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response ## if not by reference, but by users TradePair = TradePairs.objects.get(url_title="bank_transfers") 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() # TODO add process exception in withdraw crypto currency 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 return tmpl_context(Req, t, Dict)
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 confirm_withdraw_bank(Req, S): Transfer = BankTransfers.objects.get(user=Req.user, status="created", confirm_key=S) ##add trans may be there AccountTo = Accounts.objects.get(user=Req.user, currency=Transfer.currency) FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 2): Response = HttpResponse('{"status":false}') Response["Content-Type"] = "application/json" return Response ## if not by reference, but by users TradePair = TradePairs.objects.get(url_title="bank_transfers") 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() # TODO add process exception in withdraw crypto currency 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 return tmpl_context(Req, t, Dict)
def buy(Req, Trade_pair): FreqKey = "orders" + str(Req.user.id) Start = time.time() if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response getcontext().prec = settings.TRANS_PREC try: Count = Req.REQUEST.get("count") Price = Req.REQUEST.get("price") Count = Decimal(Count.replace(",", ".").strip()) Price = Decimal(Price.replace(",", ".").strip()) Count = to_prec(Count, settings.TRANS_PREC) Price = to_prec(Price, settings.TRANS_PREC) except: Response = HttpResponse(process_mistake(Req, "invalid_params")) Response['Content-Type'] = 'application/json' return Response if Price <= 0: Response = HttpResponse(process_mistake(Req, "SumLess0")) Response['Content-Type'] = 'application/json' return Response if Count <= 0: Response = HttpResponse(process_mistake(Req, "CountLess0")) Response['Content-Type'] = 'application/json' return Response TradePair = TradePairs.objects.get(url_title=Trade_pair) LOCK = "trades" + TradePair.url_title if TradePair.min_trade_base > Count: Response = HttpResponse(process_mistake(Req, "MinCount")) Response['Content-Type'] = 'application/json' return Response Custom = "0.0005" # Req.session["deal_comission"] Comission = Decimal(Custom) CurrencyOnS = Req.REQUEST.get("currency") CurrencyBaseS = Req.REQUEST.get("currency1") Amnt1 = Price * Count Amnt2 = Count CurrencyBase = Currency.objects.get(title=CurrencyBaseS) CurrencyOn = Currency.objects.get(title=CurrencyOnS) TradeLock = my_lock(LOCK) order = Orders(user=Req.user, currency1=CurrencyBase, currency2=CurrencyOn, price=Price, sum1_history=Amnt1, sum2_history=Amnt2, sum1=Amnt1, sum2=Amnt2, transit_1=TradePair.transit_from, transit_2=TradePair.transit_on, trade_pair=TradePair, comission=Comission) order.save() try: FromAccount = Accounts.objects.get(user=Req.user, currency=CurrencyBase) add_trans(FromAccount, Amnt1, CurrencyBase, TradePair.transit_from, order, "deposit") order.status = "processing" order.save() system_notify(deposit_funds(order), Req.user) ResAuto = make_auto_trade(order, TradePair, order.price, CurrencyBase, Amnt1, CurrencyOn, Amnt2) Response = HttpResponse(process_auto(Req, ResAuto, TradePair)) my_release(TradeLock) Response['Content-Type'] = 'application/json' End = time.time() measure = OrderTimer(order=order, time_work=str(End - Start)) measure.save() return Response except TransError as e: order.status = "canceled" order.save() Status = e.value Response = HttpResponse(process_mistake(Req, Status)) Response['Content-Type'] = 'application/json' my_release(TradeLock) End = time.time() measure = OrderTimer(order=order, time_work=str(End - Start)) measure.save() return Response
def generate_pay_request(self, User, Amount): currency = "" if self.__currency.title == "USD": currency = "USD" elif self.__currency.title == perfect_money_sdk.str_class_name( ) + "_eur": currency = "EUR" elif self.__currency.title == "EUR": currency = "EUR" elif self.__currency.title == perfect_money_sdk.str_class_name( ) + "_usd": currency = "USD" AmountStr = Decimal(Amount) user_account = Accounts.objects.get(user=User, currency=self.__currency) if AmountStr < 0: raise TransError("NegativeAmount") if AmountStr < self.__min_amnt: raise TransError("MinAmount") order = Orders(user=User, currency1=self.__currency, currency2=self.__currency, price=AmountStr, sum1_history=AmountStr, sum2_history=AmountStr, sum1=AmountStr, sum2=AmountStr, transit_1=self.__transit_account, transit_2=user_account, trade_pair=self.__trade_pair, status="processing") order.save() ResultUrl = self.generate_result_url(order, User, Amount) ServerResultUrl = self.generate_api_result_url(order, User, Amount) Dict = { "public_key": self.__public_id, "order_id": str(order.id), "result_url": ResultUrl, "type": "perfectmoney", "ext_details": "none", "description": self.description, "currency": currency, "server_url": ServerResultUrl, "server_url_fail": self.generate_api_result_url_fail(order, User, Amount), "amount": "%.2f" % float(AmountStr) } Response = HttpResponse(json.JSONEncoder().encode(Dict)) Response['Content-Type'] = 'application/json' return Response
def buy(Req, Trade_pair): getcontext().prec = settings.TRANS_PREC try : Count = Req.REQUEST.get("count") Price = Req.REQUEST.get("price") Count = Decimal( Count.replace(",",".").strip() ) Price = Decimal( Price.replace(",",".").strip() ) Count = to_prec(Count, settings.TRANS_PREC ) Price = to_prec(Price, settings.TRANS_PREC ) except: Response = HttpResponse(process_mistake(Req, "invalid_params")) Response['Content-Type'] = 'application/json' return Response if Price <= 0: Response = HttpResponse(process_mistake(Req, "SumLess0")) Response['Content-Type'] = 'application/json' return Response if Count<=0: Response = HttpResponse(process_mistake(Req, "CountLess0")) Response['Content-Type'] = 'application/json' return Response TradePair = TradePairs.objects.get(url_title = Trade_pair) if TradePair.min_trade_base > Count: Response = HttpResponse(process_mistake(Req, "MinCount")) Response['Content-Type'] = 'application/json' return Response CurrencyOnS = Req.REQUEST.get("currency") CurrencyBaseS = Req.REQUEST.get("currency1") Amnt1 = Price * Count Amnt2 = Count CurrencyBase = Currency.objects.get(title = CurrencyBaseS ) CurrencyOn = Currency.objects.get(title = CurrencyOnS ) order = Orders(user = Req.user, currency1 = CurrencyBase, currency2 = CurrencyOn, price = Price, sum1_history = Amnt1, sum2_history = Amnt2, sum1 = Amnt1, sum2 = Amnt2, transit_1 = TradePair.transit_from, transit_2 = TradePair.transit_on, trade_pair = TradePair ) order.save() try: FromAccount = Accounts.objects.get(user = Req.user, currency = CurrencyBase) add_trans(FromAccount, Amnt1, CurrencyBase, TradePair.transit_from, order, "deposit") order.status = "processing" order.save() system_notify(deposit_funds(order), Req.user) ResAuto = make_auto_trade(order, TradePair, order.price, CurrencyBase, Amnt1, CurrencyOn, Amnt2) Response = HttpResponse(process_auto(Req, ResAuto, TradePair)) Response['Content-Type'] = 'application/json' return Response except TransError as e: order.status = "canceled" order.save() Status = e.value Response = HttpResponse(process_mistake(Req, Status)) Response['Content-Type'] = 'application/json' return Response
def p2p_transfer_withdraw_common_operation(Req, Form): Key = generate_key("p2p_ahuihui") CardNumber = Form.cleaned_data["CardNumber"] CardNumber = CardNumber.replace(" ", "") Amnt = Form.cleaned_data["amnt"] NewAmnt = get_comisP2P(CardNumber, Decimal(Amnt)) Transfer = None FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response["Content-Type"] = "application/json" return Response if NewAmnt < 0: Transfer = CardP2PTransfers( debit_credit="out", CardName=Form.cleaned_data["CardName"], CardNumber=CardNumber, currency=Form.currency_instance, amnt=Amnt, pub_date=datetime.datetime.now(), user=Req.user, confirm_key=Key, status="processing2", ) Transfer.sign_record(settings.COMMON_SALT) if NewAmnt > 0: Transfer = CardP2PTransfers( debit_credit="out", CardName=Form.cleaned_data["CardName"], CardNumber=CardNumber, currency=Form.currency_instance, amnt=Amnt, pub_date=datetime.datetime.now(), user=Req.user, confirm_key=Key, status="auto", ) Transfer.sign_record(settings.COMMON_SALT) AccountTo = Accounts.objects.get(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = TradePairs.objects.get(url_title="p2p_transfers") 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() # TODO add process exception in withdraw p2p add_trans(AccountTo, Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, True) order.status = "processing" order.save() Transfer.order = order Transfer.save() notify_admin_withdraw(withdraw_p2p_auto(Transfer)) send_mail( _(u"Подтверждение вывода ") + settings.BASE_HOST, confirm_p2p_withdraw_email_common(Form.cleaned_data, Key), settings.EMAIL_HOST_USER, [Req.user.email], fail_silently=False, )
def p2p_transfer_withdraw_common_operation(Req, Form): Key = generate_key("p2p_ahuihui") CardNumber = Form.cleaned_data["CardNumber"] CardNumber = CardNumber.replace(" ", "") Amnt = Form.cleaned_data["amnt"] NewAmnt = get_comisP2P(CardNumber, Decimal(Amnt)) Transfer = None FreqKey = "orders" + str(Req.user.id) if not check_freq(FreqKey, 3): Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response if NewAmnt < 0: Transfer = CardP2PTransfers( debit_credit="out", CardName=Form.cleaned_data["CardName"], CardNumber=CardNumber, currency=Form.currency_instance, amnt=Amnt, pub_date=datetime.datetime.now(), user=Req.user, confirm_key=Key, status="processing2") Transfer.sign_record(settings.COMMON_SALT) if NewAmnt > 0: Transfer = CardP2PTransfers( debit_credit="out", CardName=Form.cleaned_data["CardName"], CardNumber=CardNumber, currency=Form.currency_instance, amnt=Amnt, pub_date=datetime.datetime.now(), user=Req.user, confirm_key=Key, status="auto" ) Transfer.sign_record(settings.COMMON_SALT) AccountTo = get_account(user=Req.user, currency=Transfer.currency) ## if not by reference, but by users TradePair = TradePairs.objects.get(url_title="p2p_transfers") 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() # TODO add process exception in withdraw p2p add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, False) order.status = "processing" order.save() Transfer.order = order Transfer.save() notify_admin_withdraw(withdraw_p2p_auto(Transfer)) send_mail(_(u'Подтверждение вывода ') + settings.BASE_HOST, confirm_p2p_withdraw_email_common(Form.cleaned_data, Key), [Req.user.email], fail_silently=False)
def buy(Req, Trade_pair): FreqKey = "orders" + str(Req.user.id) Start = time.time() if not check_freq(FreqKey, 3) : Response = HttpResponse('{"status":false}') Response['Content-Type'] = 'application/json' return Response getcontext().prec = settings.TRANS_PREC try : Count = Req.REQUEST.get("count") Price = Req.REQUEST.get("price") Count = Decimal( Count.replace(",",".").strip() ) Price = Decimal( Price.replace(",",".").strip() ) Count = to_prec(Count, settings.TRANS_PREC ) Price = to_prec(Price, settings.TRANS_PREC ) except: Response = HttpResponse(process_mistake(Req, "invalid_params")) Response['Content-Type'] = 'application/json' return Response if Price <= 0: Response = HttpResponse(process_mistake(Req, "SumLess0")) Response['Content-Type'] = 'application/json' return Response if Count<=0: Response = HttpResponse(process_mistake(Req, "CountLess0")) Response['Content-Type'] = 'application/json' return Response TradePair = TradePairs.objects.get(url_title = Trade_pair) LOCK = "trades" + TradePair.url_title if TradePair.min_trade_base > Count: Response = HttpResponse(process_mistake(Req, "MinCount")) Response['Content-Type'] = 'application/json' return Response Custom = "0.0005"# Req.session["deal_comission"] Comission = Decimal(Custom) CurrencyOnS = Req.REQUEST.get("currency") CurrencyBaseS = Req.REQUEST.get("currency1") Amnt1 = Price * Count Amnt2 = Count CurrencyBase = Currency.objects.get(title = CurrencyBaseS ) CurrencyOn = Currency.objects.get(title = CurrencyOnS ) TradeLock = my_lock(LOCK) order = Orders(user = Req.user, currency1 = CurrencyBase, currency2 = CurrencyOn, price = Price, sum1_history = Amnt1, sum2_history = Amnt2, sum1 = Amnt1, sum2 = Amnt2, transit_1 = TradePair.transit_from, transit_2 = TradePair.transit_on, trade_pair = TradePair, comission = Comission ) order.save() try: FromAccount = Accounts.objects.get(user = Req.user, currency = CurrencyBase) add_trans(FromAccount, Amnt1, CurrencyBase, TradePair.transit_from, order, "deposit") order.status = "processing" order.save() system_notify(deposit_funds(order), Req.user) ResAuto = make_auto_trade(order, TradePair, order.price, CurrencyBase, Amnt1, CurrencyOn, Amnt2) Response = HttpResponse(process_auto(Req, ResAuto, TradePair)) my_release(TradeLock) Response['Content-Type'] = 'application/json' End = time.time() measure = OrderTimer(order = order,time_work = str(End - Start)) measure.save() return Response except TransError as e: order.status = "canceled" order.save() Status = e.value Response = HttpResponse(process_mistake(Req, Status)) Response['Content-Type'] = 'application/json' my_release(TradeLock) End = time.time() measure = OrderTimer(order = order,time_work = str(End - Start)) measure.save() return Response