Skip to content

Commit

Permalink
simplify logic of commission & margin of future
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuizi7 committed Dec 5, 2018
1 parent 016e2e8 commit 1bb9a6e
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 1,991 deletions.
11 changes: 2 additions & 9 deletions rqalpha/data/base_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,8 @@ def available_data_range(self, frequency):
s, e = self._day_bars[self.INSTRUMENT_TYPE_MAP['INDX']].get_date_range('000001.XSHG')
return convert_int_to_date(s).date(), convert_int_to_date(e).date()

def get_margin_info(self, instrument):
return {
'margin_type': MARGIN_TYPE.BY_MONEY,
'long_margin_ratio': instrument.margin_rate,
'short_margin_ratio': instrument.margin_rate,
}

def get_commission_info(self, instrument):
return CN_FUTURE_INFO[instrument.underlying_symbol]['speculation']
return CN_FUTURE_INFO[instrument.underlying_symbol]

def get_ticks(self, order_book_id, date):
raise NotImplementedError
Expand All @@ -231,7 +224,7 @@ def get_tick_size(self, instrument):
elif instrument.type in ['ETF', 'LOF', 'FenjiB', 'FenjiA', 'FenjiMu']:
return 0.001
elif instrument.type == 'Future':
return CN_FUTURE_INFO[instrument.underlying_symbol]['speculation']['tick_size']
return CN_FUTURE_INFO[instrument.underlying_symbol]['tick_size']
else:
# NOTE: you can override get_tick_size in your custom data source
raise RuntimeError(_("Unsupported instrument type for tick size"))
9 changes: 0 additions & 9 deletions rqalpha/data/data_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,6 @@ def tick_fields_for(ins):
def available_data_range(self, frequency):
return self._data_source.available_data_range(frequency)

def get_margin_info(self, order_book_id):
instrument = self.instruments(order_book_id)
margin_info = self._data_source.get_margin_info(instrument)

if "long_margin_ratio" in margin_info and np.isnan(margin_info["long_margin_ratio"]):
raise RuntimeError("Long margin ratio of {} is not supposed to be nan".format(order_book_id))

return margin_info

def get_commission_info(self, order_book_id):
instrument = self.instruments(order_book_id)
return self._data_source.get_commission_info(instrument)
Expand Down

0 comments on commit 1bb9a6e

Please sign in to comment.