示例#1
0
文件: api.py 项目: kostyll/stock2
def common_deal_list(Pair, User_id=None):
    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Pair)
    except:
        return json_false500(Req)

    ldeals = None
    if User_id is None:
        ldeals = DealsMemory.objects.filter(trade_pair=Current.id).order_by("-id")
    else:
        ldeals = DealsMemory.objects.filter(trade_pair=Current.id, user_id=User_id).order_by("-id")

    ResList = []
    for item in ldeals:
        new_item = {}
        rate = item.price
        new_item['pub_date'] = formats.date_format(item.pub_date, "DATETIME_FORMAT")
        new_item["type"] = item.type_deal
        new_item["user"] = item.user
        new_item["price"] = format_numbers10(rate)
        new_item["amnt_base"] = format_numbers10(item.amnt_base)
        new_item["amnt_trade"] = format_numbers10(item.amnt_trade)
        ResList.append(new_item)

    return ResList
示例#2
0
文件: api.py 项目: kostyll/stock2
def sell_list(Req, Pair):
    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Pair)
    except:
        return json_false500(Req)

    SellList = OrdersMem.objects.filter(status="processing",
                                        currency1=Current.currency_on.id,
                                        currency2=Current.currency_from.id)
    getcontext().prec = 8
    Currency1Title = Current.currency_from.title
    Currency2Title = Current.currency_on.title
    AccumSellSum = 0
    GroupSellDict = {}
    for item in SellList:
        SellSum = item.sum1  ##LTC
        BuySum = item.sum2  ## UAH
        Rate = item.price
        AccumSellSum += SellSum
        if GroupSellDict.has_key(Rate):
            GroupSellDict[Rate][Currency2Title] = GroupSellDict[Rate][Currency2Title] + SellSum
            GroupSellDict[Rate][Currency1Title] = GroupSellDict[Rate][Currency1Title] + BuySum
        else:
            GroupSellDict[Rate] = {Currency2Title: SellSum, Currency1Title: BuySum}

    ResSellList = []
    LL = GroupSellDict.keys()
    L = []
    for i in LL:
        Temp = Decimal(i)
        GroupSellDict[Temp] = GroupSellDict[i]
        L.append(Temp)

    L.sort()
    Price = 0
    MinPrice = 0
    for i in L:
        Price = format_numbers10(i)
        ResSellList.append({"price": Price,
                            "currency_trade": format_numbers10(GroupSellDict[i][Currency2Title]),
                            "currency_base": format_numbers10(GroupSellDict[i][Currency1Title])})

    if len(ResSellList):
        MinPrice = ResSellList[0]["price"]

    Dict = {"orders_sum": format_numbers10(AccumSellSum),
            "list": ResSellList,
            "min_price": MinPrice,
            "max_price": Price}
    RespJ = json.JSONEncoder().encode(Dict)

    return RespJ
示例#3
0
文件: api.py 项目: kostyll/stock2
def buy_list(Req, Pair):
    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Pair)
    except:
        return json_false500(Req)

    BuyList = OrdersMem.objects.filter(status="processing",
                                       currency1=Current.currency_from.id,
                                       currency2=Current.currency_on.id)
    getcontext().prec = settings.TRANS_PREC
    Currency1Title = Current.currency_from.title
    Currency2Title = Current.currency_on.title
    List1 = {}
    AccumBuySum = 0
    for item in BuyList:
        SellSum = item.sum1  ## UAH
        BuySum = item.sum2  ## LTC
        Rate = item.price
        AccumBuySum += SellSum
        if List1.has_key(Rate):
            List1[Rate][Currency1Title] = List1[Rate][Currency1Title] + SellSum
            List1[Rate][Currency2Title] = List1[Rate][Currency2Title] + BuySum
        else:
            List1[Rate] = {Currency1Title: SellSum, Currency2Title: BuySum}

    ResBuyList = []

    LL = List1.keys()
    L = []
    for i in LL:
        Temp = Decimal(i)
        List1[Temp] = List1[i]
        L.append(Temp)

    L.sort()
    L.reverse()

    Price = 0
    MaxPrice = 0
    for i in L:
        Price = format_numbers10(i)
        ResBuyList.append({"price": Price,
                           "currency_trade": format_numbers10(List1[i][Currency2Title]),
                           "currency_base": format_numbers10(List1[i][Currency1Title])})

    if len(ResBuyList):
        MaxPrice = ResBuyList[0]["price"]
    Dict = {"orders_sum": format_numbers10(AccumBuySum), "list": ResBuyList,
            "max_price": MaxPrice, "min_price": Price}
    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
示例#4
0
文件: api.py 项目: kostyll/stock2
def balance(Req, User_id):
    List = []
    Dict = {}
    for i in Accounts.objects.filter(user_id=User_id):
        List.append({"balance": format_numbers10(i.balance), "currency": i.currency.title})

    User = Req.user
    Dict["notify_count"] = Msg.objects.filter(user_to=User,
                                              user_from_id=1,
                                              user_hide_to="false",
                                              user_seen_to="false").count()
    Dict["msg_count"] = Msg.objects.filter(user_to=User,
                                           user_hide_to="false",
                                           user_seen_to="false").exclude(user_from_id=1).count()
    try:
        online = OnlineUsers(user=Req.user)
        online.save()
    except:
        online = OnlineUsers.objects.get(user=Req.user)
        online.pub_date = datetime.datetime.now()
        online.save()

    if Req.session.has_key('use_f2a'):
        Dict["use_f2a"] = Req.session['use_f2a']
    else:
        Dict["use_f2a"] = False

    Dict["accounts"] = List
    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
示例#5
0
文件: api.py 项目: kostyll/stock2
def last_price(Req, Pair):
    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Pair)
    except:
        return json_false500(Req)
    Dict = None
    try:
        deal = DealsMemory.objects.filter(trade_pair=Current.id).latest("id")
        Dict = {"price": format_numbers4(deal.price), "price_10": format_numbers10(deal.price)}
    except:
        Dict = {"price": "0", "price_10": "0.000000000"}

    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
示例#6
0
文件: api.py 项目: kostyll/stock2
def client_orders(Req, User_id, Title):
    Dict = {}

    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Title)
    except:
        return json_false500(Req)



    Dict["auth"] = True
    MyOrders = OrdersMem.objects.fitler(user = User_id,
                                        trade_pair = Current,
                                        status='processing')

    MyOrdersList = []
    c = getcontext()
    c.prec = settings.TRANS_PREC

    for i in MyOrders:
        MyOrdersDict = {}
        MyOrdersDict["pub_date"] = formats.date_format(i.pub_date, "DATETIME_FORMAT")
        MyOrdersDict["id"] = i.id
        MyOrdersDict["sum1"] = str(i.sum1)

        if i.currency1 == Current.currency_on.id:
            MyOrdersDict["type"] = "sell"
            MyOrdersDict["price"] = format_numbers10(i.price)
            MyOrdersDict["amnt_trade"] = format_numbers10(i.sum1)
            MyOrdersDict["amnt_base"] = format_numbers10(i.sum1*i.price)
        else:
            MyOrdersDict["type"] = "buy"
            MyOrdersDict["price"] = format_numbers10(i.price)
            MyOrdersDict["amnt_base"] = format_numbers10(i.sum1)
            MyOrdersDict["amnt_trade"] = format_numbers10(i.sum1/i.price)
        MyOrdersList.append(MyOrdersDict)

    balance_sell = get_account(user_id=User_id, currency=Current.currency_on)
    balance_buy = get_account(user_id=User_id, currency=Current.currency_from)
    Dict["balance_buy"] = format_numbers_strong(balance_buy.balance)
    Dict["balance_sell"] = format_numbers_strong(balance_sell.balance)
    Dict["your_open_orders"] = MyOrdersList
    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ