當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Stock類代碼示例

本文整理匯總了Python中models.Stock的典型用法代碼示例。如果您正苦於以下問題:Python Stock類的具體用法?Python Stock怎麽用?Python Stock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Stock類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_symbols

def update_symbols():
    """
    update the symbol list calling myinvestorshub.com
    """
    from finance_game.models import Stock

    def get_countries():
        url = "http://www.myinvestorshub.com/yahoo_stock_list.php"
        countries_html = urllib2.urlopen(url).read()
        index_root = lxml.html.fromstring(countries_html)
        for country in index_root.cssselect("option"):
            yield country.text

    symbol_url_base = "http://www.myinvestorshub.com/yahoo_list.php"
    for country in get_countries():
        if country == "United Kingdom":
            data = urllib.urlencode({"cnt": country})
            binary_data = data.encode('utf-8')
            request = urllib2.Request(symbol_url_base, binary_data)
            response = urllib2.urlopen(request)
            index_root = lxml.html.fromstring(response.read().decode('utf-8'))
            table = index_root.cssselect("table")[3]
            stock_rows = table.cssselect("tr")
            for stock_row in stock_rows[1:]:
                _, company_name, symbol, exchange, country = list(map(lambda s: s.text, stock_row.cssselect("td")))
                if company_name and symbol and exchange and country:
                    print(company_name, symbol, exchange, country)
                    stock = Stock(name=company_name, symbol=symbol, exchange=exchange, country=country)
                    # stock.update_values()
                    stock.save()
開發者ID:antonigno,項目名稱:finance-game,代碼行數:30,代碼來源:utils.py

示例2: portfolio_add_stock

def portfolio_add_stock(request, portfolio_id, portfolio, symbol, stock):
    if stock is None:
        stock = Stock(yahoo_symbol=symbol)
        stock.save()
    portfolio.stocks.add(stock)
    portfolio.save()
    return HttpResponse('')
開發者ID:Mandibull,項目名稱:django_stock_portfolio,代碼行數:7,代碼來源:views.py

示例3: _update_stocks

def _update_stocks(symbols):
    """
    Update models.Stock entities.
    :param symbols: Iterable of stock symbols to update.
    :return: dict mapping symbols to new prices, dict mapping symbols to (old price, new price) for changed symbols.
    """

    to_put = []
    symbol_price_updated_dict = {}

    if symbols is None:
        stocks_ = list(Stock.query())
        symbols = [s.key.id() for s in stocks_]
    else:
        stocks_ = [Stock.get_by_id(s) for s in symbols]

    symbol_price_dict = stocks.get_stock_prices(symbols)

    for stock in stocks_:
        if stock is None:
            continue

        symbol = stock.key.id()
        price = symbol_price_dict.get(symbol, None)

        if stock.price != price:
            symbol_price_updated_dict[symbol] = (stock.price, price)
            stock.price = price
            to_put.append(stock)

    ndb.put_multi(to_put)

    return symbol_price_dict, symbol_price_updated_dict
開發者ID:jalexvig,項目名稱:stock_tracker,代碼行數:33,代碼來源:db.py

示例4: agregar_stock

def agregar_stock(detalle, almacen):
  if existe_stock(detalle.producto, almacen):
    stock = Stock.objects.get(producto = detalle.producto, en_almacen = almacen)
    stock.unidades = stock.unidades + detalle.cantidad
    stock.save()
  else:
    stock = Stock(producto = detalle.producto, en_almacen = almacen, unidades = detalle.cantidad)
    stock.save()
開發者ID:soncco,項目名稱:distri,代碼行數:8,代碼來源:utils.py

示例5: BeginToTrade

def BeginToTrade(request):
    RequestUser = request.user
    RequestGroup = RequestUser.group
    context={
        "form":SearchForm(),
        "sear":True
    }
    if request.method=="POST":
        Post = request.POST.dict()
        if Post.has_key("StockName"):
            StockName=str(Post["StockName"])
        else:
            StockName=""
        if Post.has_key("Volume"):
            Volume=Post["Volume"]
        else:
            Volume=0
        if Post.has_key("TransactionType"):
            TransactionType=Post["TransactionType"]
        else:
            TransactionType=None
        print Post

        context={
            "form":OrderForm(),
            "sear":False
            
            }
        
        stock = Stock.objects.filter(StockName=StockName)
        if len(stock)==0:
            print "123123"
            stock = Stock(StockName=StockName)
            stock.save()
            context["StockData"] = jsonpickle.encode(stock.Get_data())
        else:
             context["StockData"] = jsonpickle.encode(stock[0].Get_data())

        if Volume!="" and TransactionType != None:
            RequestUser.group.UpdateAcount()
            stockprice = stock[0].Get_Price()
            if TransactionType=="buy":
                if RequestUser.group.Cash >= stockprice*float(Volume):
                    RequestGroup.transaction_set.create(TransType = TransactionType,StockOfTrans = stock[0], Volume=Volume, PriceAtTrans=stock[0].Get_Price() )
                    context["mess"] = "Succesfully making transaction"
                else:
                    context["mess"] = "You don't have enough money"
            else:
                asset = RequestUser.group.AllAsset
                if asset[StockName] >= float(Volume):
                    RequestGroup.transaction_set.create(TransType = TransactionType,StockOfTrans = stock[0], Volume=Volume, PriceAtTrans=stock[0].Get_Price() )
                    context["mess"] = "Succesfully making transaction"
                else:
                    context["mess"] = "You don't have enough this stock to sell"
        
    return render(request, "BeginToTrade.html", context)
開發者ID:Alchemyst2802,項目名稱:SES-Group,代碼行數:56,代碼來源:views.py

示例6: get_all_stocks

def get_all_stocks(name=None):
    search_name = request.args.get('name')
    if search_name:
        stock = Stock.find_one({'name': search_name}, test_mode=app.testing)
        return jsonify(stock=stock)
    industry = request.args.get('industry')
    if industry:
        stocks = Stock.find({'industry': industry}, test_mode=app.testing)
        return jsonify(stocks=stocks)
    # Get all stocks
    stocks = Stock.find_all(test_mode=app.testing)
    return jsonify(stocks=stocks['stocks'])
開發者ID:bertrade,項目名稱:bertrade-api,代碼行數:12,代碼來源:api.py

示例7: stock

def stock():
    if not account.user_is_logged_in():
        return redirect(url_for("login"))
    ticker = request.args.get("ticker", "AAPL") # TODO: no ticker is error...

    # Find the stock.
    stock = Stock.get_stock_from_db(ticker)

    # Check for errors.
    if stock == -1:
        N_STOCKS = 20 # number of stocks to retrieve
        tickers = Stock.get_all_tickers()
        stocks = Stock.get_stocks(N_STOCKS, True) # default: list of stocks by alpha order

        return render_template("home.html",
                               error="No ticker matching that name could be found.",
                               tickers = tickers, stocks = stocks,
                               metric = "alpha", order = True,
                               has_recs = account.user_has_recommendations())

    # Get the prices with corresponding dates.
    # Produce formatted date strings to paste into HTML.
    price_time_series = Stock.get_time_series(ticker, 7)
    price_dates = price_time_series.keys()
    price_dates.sort()
    price_dates_str = []
    price_values = []
    for curr_date in price_dates:
        price_values.append(price_time_series[curr_date])
        price_dates_str.append(curr_date.strftime("%m-%d"))

    # Compute price change now-- consistent with time series data!
    price_change = price_values[-1] - price_values[-2]

    # Put a blurb in the stock page if it is recommended.
    stock_is_recommended = False
    if account.user_has_recommendations():
        if stock.ticker in Stock.recommended_tickers:
            stock_is_recommended = True

    return render_template("stock.html", ticker = stock.ticker,
                           name = stock.name, latest_price = stock.cur_price,
                           pe_ratio = stock.pe, market_cap = stock.cap,
                           dividends = stock.dividends,
                           beta = stock.beta,
                           sustainability = stock.sustainability,
                           socialgood = stock.socialgood,
                           american = stock.american,
                           price_change = price_change,
                           price_series_dates = price_dates_str,
                           price_series_values = price_values,
                           recommended = stock_is_recommended)
開發者ID:damlaren,項目名稱:investorscope-app,代碼行數:52,代碼來源:views.py

示例8: test_create_stock

 def test_create_stock(self):
     """Make sure it create a stock."""
     Category.create(category_id='001', description='Testing Stock')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     s = Stock.select().where(Stock.stock_id == '001')
     t = Stock.delete().where(Stock.stock_id == '001')
     t.execute()
     t = Category.delete().where(Category.category_id == '001')
     t.execute()
     self.assertEqual(str(s), ("<class 'models.Stock'> SELECT `t1`.`id`,"
                               " `t1`.`stock_id`, `t1`.`description`,"
                               " `t1`.`quantity`, `t1`.`category_id`,"
                               " `t1`.`price` FROM `stock` AS t1"
                               " WHERE (`t1`.`stock_id` = %s) ['001']"))
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:14,代碼來源:tests.py

示例9: test_create_outgoing

 def test_create_outgoing(self):
     """Create an outgoing record."""
     Category.create(category_id='001', description='Testing Stock')
     Project.create(project_id='001', project_description="Testing")
     Role.create(role_name='Admin')
     User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='JayPalm',
                 password='jfresh13', email='[email protected]')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='JayPalm')
     OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
     Stock.get(Stock.category == '001').delete_instance()
     User.get(User.username == 'JayPalm').delete_instance()
     Role.get(Role.role_name == 'Admin').delete_instance()
     Project.get(Project.project_id == '001').delete_instance()
     Category.get(Category.category_id == '001').delete_instance()
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:15,代碼來源:tests.py

示例10: add_existing_stock

def add_existing_stock(pk_id, to_add):
    """Increase quantity for a specified record by pk_id.
    pk_id: primary key id
    """
    stock = Stock.get(
        Stock.id == pk_id
    )
    current_quantity = stock.quantity
    new_quantity = current_quantity + to_add
    query = Stock.update(
        quantity=new_quantity
    ).where(
        Stock.id == pk_id
    )
    return query.execute()
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:15,代碼來源:stock.py

示例11: show_stock

def show_stock(request, symbol):
    stks = Stock.objects.filter(symbol=symbol)
    if stks.count() == 0:
        stk = Stock(symbol=symbol, price=0.0)
        stk.save()
    elif stks.count() == 1:
        stk = stks[0]
    else:
        return HttpResponse("%s" % stks.count())
    try:
        ss = stk.history.order_by('date')[0]
    except:
        update(stk)
        ss = stk.history.order_by('date')[0]
    return render_to_response('stock.html', {'stock': stk, 'status': ss})
開發者ID:sapenagamero0,項目名稱:teststock2,代碼行數:15,代碼來源:views.py

示例12: _process_removed_stocks

def _process_removed_stocks(sheet, ssheet_id, symbols):
    """
    Update database to reflect sheet's new stocks, changed bounds, or changed order.
    :param sheet: Instance of models.Sheet to modify.
    :param ssheet_id: Spreadsheet id.
    :param symbols: Iterable of symbols.
    :return: list of ndb Entities to put, list of ndb Entities to delete.
    """

    to_put, to_delete = [], []

    symbols_old = {k.id() for k in sheet.stock_keys}

    for symbol in symbols_old - set(symbols):
        stock = Stock.get_by_id(symbol)
        sheetstock_key = ndb.Key('SheetStock', '_'.join([ssheet_id, symbol]))

        to_delete.append(sheetstock_key)

        if stock and sheet.key in stock.sheet_keys:
            stock.sheet_keys.remove(sheet.key)
            if stock.sheet_keys:
                to_put.append(stock)
            else:
                to_delete.append(stock.key)

    return to_put, to_delete
開發者ID:jalexvig,項目名稱:stock_tracker,代碼行數:27,代碼來源:db.py

示例13: test_fuzzy_text_search_industry_name

    def test_fuzzy_text_search_industry_name(self):
        stocks = Stock.find({'industry': 'consumer'}, test_mode=True)
        stock = stocks[0]
        self._assert_first_stock(stock)

        stock_2 = stocks[1]
        self._assert_second_stock(stock_2)
開發者ID:bertrade,項目名稱:bertrade-api,代碼行數:7,代碼來源:test_unit_stock.py

示例14: stock_add

def stock_add(request):
    from app.remote.stocks import StockHistoryClient
    from app.forms import StockWizardForm
    from app.models import Company, Stock

    if request.method == "POST":
        form = StockWizardForm(request.POST)
        pprint(form.is_valid())
        if form.is_valid():
            # save
            company = Company()
            company.name = form.cleaned_data['company_name']
            company.country = form.cleaned_data['company_country']
            company.save()

            stock = Stock()
            stock.company = company
            stock.name = form.cleaned_data['name']
            stock.wkn = form.cleaned_data['wkn']
            stock.isin = form.cleaned_data['isin']
            stock.symbol = form.cleaned_data['symbol']
            stock.type = form.cleaned_data['type']
            stock.default_stock_exchange = form.cleaned_data['default_stock_exchange']
            stock.save()

            return HttpResponseRedirect(reverse('stock', args=(stock.symbol,)))
        else:
            pprint(form.errors)
    else:
        data = None
        if 'wkn_or_isin' in request.GET:
            shc = StockHistoryClient()
            data = shc.get_basics_by_wkn_or_isin(wkn_or_isin=request.GET['wkn_or_isin'])

            data['company_country'] = data['country']
            data['company_name'] = data['name']

        form = StockWizardForm(initial=data)

    return render_to_response(
        'stock_wizard_add.html',
        {
            'form': form
        },
        context_instance=RequestContext(request)
    )
開發者ID:mrcrgl,項目名稱:stockstore,代碼行數:46,代碼來源:views.py

示例15: test_find_all_stocks

    def test_find_all_stocks(self):
        stocks = Stock.find_all(test_mode=True)
        stocks = stocks['stocks']
        stock_1 = stocks[0]
        self._assert_first_stock(stock_1)

        stock_2 = stocks[1]
        self._assert_second_stock(stock_2)
開發者ID:bertrade,項目名稱:bertrade-api,代碼行數:8,代碼來源:test_unit_stock.py


注:本文中的models.Stock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。