• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Stock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.Stock的典型用法代码示例。如果您正苦于以下问题:Python Stock类的具体用法?Python Stock怎么用?Python Stock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Stock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: show_stock

def show_stock():
  stock = request.args.get('ticker')
  value = request.args.get('value')
  unit = request.args.get('unit')
  stock = Stock(stock)
  if stock.data is not None:
    stock.calc_all()
    format_data = stock.data.reset_index()  # DateTimeIndex to column
    format_data = format_data.to_json(date_format='epoch', orient='records')
    # Markup tells jinja2 that the object is safe for rendering, without
    # escaping the quotes (caused problems when creating JSON object).
    format_data = Markup(format_data)
    # need to redirect instead
    return render_template('chart.html', stock=stock, data=format_data)
  else:
    error = stock.ticker + " is an invalid ticker symbol."
    return render_template('index.html', error = error)
开发者ID:grantbachman,项目名称:chartflux,代码行数:17,代码来源:views.py


示例17: test_create_incoming

    def test_create_incoming(self):
        """Create an incoming record."""
        Category.create(category_id='001', description='Testing Stock')
        create_stock('001', 'Testing stock', 1, '001', 9.99)
        create_incoming_stock(stock="001", date="2015-07-22", quantity=13, price=13.99)
        p = IncomingStock.select().where(IncomingStock.stock == '001')
        q = IncomingStock.delete().where(IncomingStock.stock == '001')
        q.execute()
        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(p), ("<class 'models.IncomingStock'> SELECT `t1`.`id`, `t1`.`stock_id`, "
                                  "`t1`.`date`, `t1`.`price`, `t1`.`cost` FROM `incomingstock` AS t1 WHERE "
                                  "(`t1`.`stock_id` = %s) ['001']"))
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:17,代码来源:test.py


示例18: get_stocks_in_day

def get_stocks_in_day(stock_name, day):
    out = []
    markets = Market.all(keys_only=False).filter("date =", day).filter("ref =", stock_name.market_ref).order('time').fetch(100)
    for market in markets:
        stock = Stock.all().filter("market =", market.key()).filter('name = ', stock_name.key()).get()
        if not stock is None:
            dt = datetime.combine(market.date, market.time)
            out.append((dt, stock, market.exchange_rate))
    return out
开发者ID:fabiomdiniz,项目名称:verdandi,代码行数:9,代码来源:util.py


示例19: get_stocks_days

def get_stocks_days(stock_name, num_days=10):
    days = last_weekdays(num_days)
    out = []
    for day in days:
        market = Market.all(keys_only=False).filter("date =", day.date()).filter("ref =", stock_name.market_ref).order('-time').get()
        if not market is None:
            stock = Stock.all().filter("market =", market.key()).filter('name = ', stock_name.key()).get()
            if not stock is None:
                out.append((day, stock, market.exchange_rate))
    return out
开发者ID:fabiomdiniz,项目名称:verdandi,代码行数:10,代码来源:util.py


示例20: test_create_stock_no_duplicate

 def test_create_stock_no_duplicate(self):
     """Makes sure stock don't have the same stock_id when creating."""
     Category.create(category_id='001', description='Testing Stock')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     from peewee import IntegrityError
     with self.assertRaises(IntegrityError):
         create_stock('001', 'Testing stock', 1, '001', 9.99)
     q = Stock.delete().where(Stock.stock_id == '001')
     q.execute()
     t = Category.delete().where(Category.category_id == '001')
     t.execute()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:11,代码来源:tests.py



注:本文中的models.Stock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Student类代码示例发布时间:2022-05-27
下一篇:
Python models.Status类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap