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 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 ask(Req, UrlTitle): CurrentTradePair = TradePairs.objects.get(url_title=UrlTitle) SumList = [] Amount = Decimal("0") TempSum = Decimal('0') try: Amount = Decimal(Req.REQUEST.get("amount", None)) Query = "SELECT * FROM main_orders WHERE currency1_id=%i AND currency2_id=%i \ AND status='processing' \ AND user_id!=%i ORDER BY price DESC" % ( CurrentTradePair.currency_on.id, CurrentTradePair.currency_from.id, Req.user.id) List = Orders.objects.raw(Query) for item in List: if Amount > item.sum1: Amount -= item.sum1 TempSum += item.sum1 SumList.append({"sum": item.sum1, "price": item.price}) else: TempSum += Amount SumList.append({"sum": Amount, "price": item.price}) break except: Response = HttpResponse( '{"status":false, "description":"amount is incorrect"}') Response['Content-Type'] = 'application/json' return Response #format_numbers_strong(balance_buy.balance ) AvaragePrice = Decimal("0") BuySum = Decimal("0") for item in SumList: BuySum += item['sum'] AvaragePrice += ((item['sum'] / TempSum) * item['price']) Dict = { "buy_sum": format_numbers_strong(BuySum), "price": format_numbers_strong(AvaragePrice), "status": True } RespJ = json.JSONEncoder().encode(Dict) return cached_json_object(RespJ)
def ask(Req, UrlTitle): CurrentTradePair = TradePairs.objects.get(url_title = UrlTitle) SumList = [] Amount = Decimal("0") TempSum = Decimal('0') try: Amount = Decimal( Req.REQUEST.get("amount", None) ) Query = "SELECT * FROM main_orders WHERE currency1_id=%i AND currency2_id=%i \ AND status='processing' \ AND user_id!=%i ORDER BY price DESC" % ( CurrentTradePair.currency_on.id, CurrentTradePair.currency_from.id, Req.user.id) List = Orders.objects.raw(Query) for item in List: if Amount > item.sum1 : Amount -= item.sum1 TempSum += item.sum1 SumList.append({"sum":item.sum1,"price":item.price}) else: TempSum += Amount SumList.append({"sum":Amount,"price":item.price}) break except : Response = HttpResponse('{"status":false, "description":"amount is incorrect"}') Response['Content-Type'] = 'application/json' return Response #format_numbers_strong(balance_buy.balance ) AvaragePrice = Decimal("0") BuySum = Decimal("0") for item in SumList: BuySum += item['sum'] AvaragePrice += ((item['sum']/TempSum)*item['price'] ) Dict = {"buy_sum": format_numbers_strong(BuySum), "price": format_numbers_strong(AvaragePrice), "status":True } RespJ = json.JSONEncoder().encode(Dict) return cached_json_object(RespJ)