示例#1
0
 def onUnderlyingIdChanged(self, text):
     if not text:
         return
     order_type = self.manual_create_order.findChild(
         QComboBox, "order_type")
     if order_type.currentIndex() == 0:
         contract_id = self.manual_create_order.findChild(
             QComboBox, "contract_id")
         date = self.manual_create_order.findChild(
             QDateEdit,
             "send_date").dateTime().toString("yyyy-MM-dd 00:00:00")
         contract_id.clear()
         table = "option/contract"
         data = sql.read(
             table,
             where=
             "underlying_symbol='%s' AND maturity_date>='%s' AND listed_date <= '%s' "
             % (text, date, date))
         ids = list(data.order_book_id)
         symbols = list(data.symbol)
         contract_id.addItems(symbols)
         setattr(contract_id, "ids", ids)
     elif order_type.currentIndex() == 1:
         table = "option/underlyings/%s" % text
         date = self.manual_create_order.findChild(
             QDateEdit,
             "send_date").dateTime().toString("yyyy-MM-dd 00:00:00")
         data = sql.read(table, where="date='%s'" % date)
         close_price = data.close
         self.manual_create_order.findChild(
             QDoubleSpinBox, "close_price").setValue(close_price)
     elif order_type.currentIndex() == 2:
         table = "stock/"
示例#2
0
 def _get_future_contract_data(self, name, id):
     table = "future/contracts/%s" % id
     childSubWindow = {
         "title": "%s的当日合约",
         "type": "future_contract_data_table",
         "table_name": "%date%",
         "where": "",
         "select": id,
         "hidden_columns": [],
         "index_column": [],
         "childSubWindow": {},
     }
     hidden_columns = ['total_turnover',
                       'limit_up',
                       'limit_down',
                       'settlement',
                       'prev_settlement',
                       'discount_rate',
                       'acc_net_value',
                       'unit_net_value',
                       'date',
                       'open_interest'
                       ]
     data = sql.read(table)
     if data.empty:
         self.messageBox("数据库中没有该数据")
         return
     else:
         grid_view.GridView(self, name, data, id=id,
                                 hidden_columns=hidden_columns,
                                 index_column='date',
                                 childSubWindow=childSubWindow,
                                 type="option_underlying")
示例#3
0
 def _get_option_contract_by_date(self, underlying_symbol, date):
     showData = pd.DataFrame()
     data = sql.read("option/contract", where="maturity_date>='%s' AND listed_date <= '%s' AND underlying_order_book_id='%s'" % (date, date, underlying_symbol))
     for index, row in data.iterrows():
         order_book_id = row.order_book_id
         symbol = row.symbol
         table = "option/contracts/%s" % order_book_id
         if sql.is_table(table):
             dataRow = sql.read(table, where="date='%s'" % date)
             dataRow["symbol"] = symbol
             showData = showData.append(dataRow, ignore_index=True, sort=True)
     if showData.empty:
         self.messageBox("数据库中没有该数据")
         return
     else:
         grid_view.GridView(self, "标的%s在%s日的期权全部合约" % (underlying_symbol, date), showData, index_column="symbol", hidden_columns=["symbol"], id=1)
示例#4
0
 def _get_option_underlying_data(self, name, id):
     table = "option/underlyings/%s" % id
     childSubWindow = {
         "title": "%s的当日合约",
         "type": "option_contract_table",
         "table_name": "%date%",
         "where":"",
         "select": id,
         "hidden_columns": [],
         "index_column": [],
         "childSubWindow": {},
     }
     hidden_columns = ['total_turnover',
                       'limit_up',
                       'limit_down',
                       'settlement',
                       'prev_settlement',
                       'discount_rate',
                       'acc_net_value',
                       'unit_net_value',
                       'date',
                       'open_interest',
                       'iopv',
                       'num_trades'
                       ]
     if id == "510050.XSHG":
         where = "date > '2015-02-08 00:00:00'"
     else:
         where = None
     if where:
         data = sql.read(table, where=where)
     else:
         data = sql.read(table)
     if data.empty:
         self.messageBox("数据库中没有该数据")
         return
     else:
         grid_view.GridView(self, name, data, id=id,
                                 hidden_columns=hidden_columns,
                                 index_column='date',
                                 childSubWindow=childSubWindow,
                                 type="option_underlying")
示例#5
0
 def onCalendarClicked(self, date, manual_create_order):
     date_str = date.toString("yyyy-MM-dd 00:00:00")
     table = "option/underlyings/510050.XSHG"
     tick = sql.read(table, where="date='%s'" % date_str)
     if tick.empty:
         self.main_widget.messageBox("不是交易日")
         return
     self.manual_create_order.findChild(QDateEdit,
                                        "send_date").setDate(date)
     order_type = manual_create_order.findChild(QComboBox, "order_type")
     text = order_type.currentText()
     self.onOrderTypeChanged(text)
示例#6
0
 def onOrderTypeChanged(self, text):
     underlying_id = self.manual_create_order.findChild(
         QComboBox, "underlying_id")
     underlying_id.clear()
     if text == "期权合约":
         underlying_ids = []
         for index in range(self.main_widget.option_list.rowCount()):
             underlying_ids.append(
                 self.main_widget.option_list.item(index, 1).text())
         underlying_id.addItems(underlying_ids)
         self.manual_create_order.findChild(QComboBox,
                                            "contract_id").setEnabled(True)
     elif text == "期权标的":
         date = self.manual_create_order.findChild(
             QDateEdit,
             "send_date").dateTime().toString("yyyy-MM-dd 00:00:00")
         table = "option/contract"
         data = sql.read(
             table,
             where="maturity_date>='%s' AND listed_date <= '%s' " %
             (date, date))
         ids = [
             id for id, group in data.groupby(["underlying_order_book_id"])
         ]
         # underlying_ids = []
         # for index in range(self.option_list.rowCount()):
         #     underlying_ids.append(self.option_list.item(index, 1).text())
         self.manual_create_order.findChild(QComboBox,
                                            "underlying_id").addItems(ids)
         self.manual_create_order.findChild(QComboBox,
                                            "contract_id").setEnabled(False)
     elif text == "股票":
         # date = self.manual_create_order.findChild(QDateEdit, "send_date").dateTime().toString("yyyy-MM-dd 00:00:00")
         table = "stock/contract"
         data = sql.read(table)
         ids = [id for id in data["order_book_id"]]
         self.manual_create_order.findChild(QComboBox,
                                            "underlying_id").addItems(ids)
         self.manual_create_order.findChild(QComboBox,
                                            "contract_id").setEnabled(False)
示例#7
0
 def _get_option_contract(self, name, id):
     table = "option/contract"
     data = sql.read(table, where="underlying_symbol='%s'" % id)
     hidden_columns = ['index',
                       'contract_multiplier',
                       'de_listed_date',
                       'exchange',
                       'exercise_type',
                       'listed_date',
                       'market_tplus',
                       'maturity_date',
                       'option_type',
                       'order_book_id',
                       'round_lot',
                       'strike_price',
                       'symbol',
                       'trading_hours',
                       'underlying_order_book_id'
                       ]
     data.dropna(axis=0, how='any', inplace=True)
     data.drop_duplicates("underlying_order_book_id", inplace=True)
     data.index = [i for i in range(int(len(data.index)))]
     if data.empty:
         self.messageBox("数据库中没有该数据")
         return
     else:
         grid_view.GridView(self, name, data, id=id,
                                 hidden_columns=hidden_columns,
                                 index_column="underlying_order_book_id",
                                 childSubWindow={
                                     "title":id,
                                     "type":"option_underlying_table",
                                     "table_name": "option/underlyings/%underlying_order_book_id%",
                                     "hidden_columns": ['total_turnover',
                                                        'limit_up',
                                                        'limit_down',
                                                        'settlement',
                                                        'prev_settlement',
                                                        'discount_rate',
                                                        'acc_net_value',
                                                        'unit_net_value',
                                                        'date',
                                                        'open_interest'],
                                     "index_column":"date",
                                 })
示例#8
0
 def onContractIdChanged(self, text):
     contract_id = self.manual_create_order.findChild(
         QComboBox, "contract_id")
     if not hasattr(contract_id, "ids"):
         return
     ids = getattr(contract_id, "ids")
     if ids == []:
         return
     index = contract_id.currentIndex()
     text = ids[index]
     date = self.manual_create_order.findChild(
         QDateEdit, "send_date").dateTime().toString("yyyy-MM-dd 00:00:00")
     table = "option/contracts/%s" % text
     data = sql.read(table, where="date='%s'" % date)
     if data.empty:
         return
     close_price = data.close
     self.manual_create_order.findChild(QDoubleSpinBox,
                                        "close_price").setValue(close_price)
示例#9
0
def is_option_contract_need_update(table):
    order_book_id = table.split("/")[-1]
    maturity_date_string = sql.read("option/contract",
                                    where="order_book_id='%s'" %
                                    order_book_id).loc[0, "maturity_date"]
    maturity_date_datetime = datetime.datetime(
        year=int(maturity_date_string[0:4]),
        month=int(maturity_date_string[5:7]),
        day=int(maturity_date_string[8:10]))
    if maturity_date_datetime < TODAY:
        return False
    df = sql.read_latest_row(table)
    if df.empty:
        return False
    last_date = df.loc[0, "date"]
    last_date_datetime = datetime.datetime(year=int(last_date[0:4]),
                                           month=int(last_date[5:7]),
                                           day=int(last_date[8:10]))
    start_date_string = (last_date_datetime + DELTA).strftime('%Y%m%d')
    if TODAY > last_date_datetime:
        return True
    else:
        return False