コード例 #1
0
ファイル: stocks_db.py プロジェクト: RayLong/stock_roll
 def insert_stock(self, stock_code, stock_name, data, quantity_change_history=[]):
     stocks=StockList.objects.filter(stock_code=stock_code)
     if not stocks.exists():
        stock=StockList(stock_code=stock_code, stock_name=stock_name, gradient=0)
        stock.save()
     else:
        stock=stocks[0]
     
     for row in data:
          stock_data_item=StockData.objects.filter(stock_ref=stock, trade_date=row[0])
          if stock_data_item.count()==0 :
              stock_data_item=StockData(stock_ref=stock,
                           trade_date=row[0],
                           open_price=row[1],
                           high_price=row[2],
                           low_price=row[3],
                           close_price=row[4],
                           volume=row[5],
                           quantity=row[6])
          else:
              stock_data_item=stock_data_item[0]
          stock_data_item.open_price=row[1]
          stock_data_item.high_price=row[2]
          stock_data_item.low_price=row[3]
          stock_data_item.close_price=row[4]
          stock_data_item.volume=row[5]
          stock_data_item.quantity=row[6]
          stock_data_item.save()
コード例 #2
0
ファイル: stocks_db.py プロジェクト: RayLong/stock_roll
 def add_stock_name(self, stock_code, stock_name):
     trend=StockTrend(stock_code=stock_code, a=0, b=0, k=0)
     trend.save()
     stock=StockList(stock_code=stock_code, stock_name=stock_name, gradient=0, trend=trend)
     stock.save()