[Mod] add combobox for setting spread min_volume
This commit is contained in:
parent
47b256ea90
commit
b056901a38
@ -119,9 +119,6 @@ class SpreadTakerAlgo(SpreadAlgoTemplate):
|
|||||||
active_traded
|
active_traded
|
||||||
)
|
)
|
||||||
|
|
||||||
self.write_log(
|
|
||||||
f"active {active_leg.vt_symbol} traded: {active_traded} hedge_volume: {hedge_volume}")
|
|
||||||
|
|
||||||
# Calculate passive leg target volume and do hedge
|
# Calculate passive leg target volume and do hedge
|
||||||
for leg in self.spread.passive_legs:
|
for leg in self.spread.passive_legs:
|
||||||
passive_traded = self.leg_traded[leg.vt_symbol]
|
passive_traded = self.leg_traded[leg.vt_symbol]
|
||||||
@ -131,8 +128,6 @@ class SpreadTakerAlgo(SpreadAlgoTemplate):
|
|||||||
leg.vt_symbol,
|
leg.vt_symbol,
|
||||||
hedge_volume
|
hedge_volume
|
||||||
)
|
)
|
||||||
self.write_log(
|
|
||||||
f"hedge {leg.vt_symbol} traded: {passive_traded} target: {passive_target}")
|
|
||||||
|
|
||||||
leg_order_volume = passive_target - passive_traded
|
leg_order_volume = passive_target - passive_traded
|
||||||
if leg_order_volume:
|
if leg_order_volume:
|
||||||
|
@ -129,7 +129,8 @@ class SpreadData:
|
|||||||
price_multipliers: Dict[str, int],
|
price_multipliers: Dict[str, int],
|
||||||
trading_multipliers: Dict[str, int],
|
trading_multipliers: Dict[str, int],
|
||||||
active_symbol: str,
|
active_symbol: str,
|
||||||
inverse_contracts: Dict[str, bool]
|
inverse_contracts: Dict[str, bool],
|
||||||
|
min_volume: float
|
||||||
):
|
):
|
||||||
""""""
|
""""""
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
@ -138,7 +139,7 @@ class SpreadData:
|
|||||||
self.active_leg: LegData = None
|
self.active_leg: LegData = None
|
||||||
self.passive_legs: List[LegData] = []
|
self.passive_legs: List[LegData] = []
|
||||||
|
|
||||||
self.min_volume = 0.001
|
self.min_volume: float = min_volume
|
||||||
|
|
||||||
# For calculating spread price
|
# For calculating spread price
|
||||||
self.price_multipliers: Dict[str, int] = price_multipliers
|
self.price_multipliers: Dict[str, int] = price_multipliers
|
||||||
|
@ -116,6 +116,7 @@ class SpreadDataEngine:
|
|||||||
spread_setting["name"],
|
spread_setting["name"],
|
||||||
spread_setting["leg_settings"],
|
spread_setting["leg_settings"],
|
||||||
spread_setting["active_symbol"],
|
spread_setting["active_symbol"],
|
||||||
|
spread_setting.get("min_volume", 1),
|
||||||
save=False
|
save=False
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -251,6 +252,7 @@ class SpreadDataEngine:
|
|||||||
name: str,
|
name: str,
|
||||||
leg_settings: List[Dict],
|
leg_settings: List[Dict],
|
||||||
active_symbol: str,
|
active_symbol: str,
|
||||||
|
min_volume: float,
|
||||||
save: bool = True
|
save: bool = True
|
||||||
) -> None:
|
) -> None:
|
||||||
""""""
|
""""""
|
||||||
@ -278,7 +280,8 @@ class SpreadDataEngine:
|
|||||||
price_multipliers,
|
price_multipliers,
|
||||||
trading_multipliers,
|
trading_multipliers,
|
||||||
active_symbol,
|
active_symbol,
|
||||||
inverse_contracts
|
inverse_contracts,
|
||||||
|
min_volume
|
||||||
)
|
)
|
||||||
self.spreads[name] = spread
|
self.spreads[name] = spread
|
||||||
|
|
||||||
|
@ -383,6 +383,17 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
self.name_line = QtWidgets.QLineEdit()
|
self.name_line = QtWidgets.QLineEdit()
|
||||||
self.active_line = QtWidgets.QLineEdit()
|
self.active_line = QtWidgets.QLineEdit()
|
||||||
|
|
||||||
|
self.min_volume_combo = QtWidgets.QComboBox()
|
||||||
|
self.min_volume_combo.addItems([
|
||||||
|
"1",
|
||||||
|
"0.1",
|
||||||
|
"0.01",
|
||||||
|
"0.001",
|
||||||
|
"0.0001",
|
||||||
|
"0.00001",
|
||||||
|
"0.000001",
|
||||||
|
])
|
||||||
|
|
||||||
self.grid = QtWidgets.QGridLayout()
|
self.grid = QtWidgets.QGridLayout()
|
||||||
|
|
||||||
button_add = QtWidgets.QPushButton("创建价差")
|
button_add = QtWidgets.QPushButton("创建价差")
|
||||||
@ -392,15 +403,17 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
grid = QtWidgets.QGridLayout()
|
grid = QtWidgets.QGridLayout()
|
||||||
grid.addWidget(Label("价差名称"), 0, 0)
|
grid.addWidget(Label("价差名称"), 0, 0)
|
||||||
grid.addWidget(self.name_line, 0, 1, 1, 3)
|
grid.addWidget(self.name_line, 0, 1, 1, 4)
|
||||||
grid.addWidget(Label("主动腿代码"), 1, 0)
|
grid.addWidget(Label("主动腿代码"), 1, 0)
|
||||||
grid.addWidget(self.active_line, 1, 1, 1, 3)
|
grid.addWidget(self.active_line, 1, 1, 1, 4)
|
||||||
|
grid.addWidget(Label("最小交易量"), 2, 0)
|
||||||
|
grid.addWidget(self.min_volume_combo, 2, 1, 1, 4)
|
||||||
|
|
||||||
grid.addWidget(Label(""), 2, 0)
|
grid.addWidget(Label(""), 3, 0)
|
||||||
grid.addWidget(Label("本地代码"), 3, 1)
|
grid.addWidget(Label("本地代码"), 4, 1)
|
||||||
grid.addWidget(Label("价格乘数"), 3, 2)
|
grid.addWidget(Label("价格乘数"), 4, 2)
|
||||||
grid.addWidget(Label("交易乘数"), 3, 3)
|
grid.addWidget(Label("交易乘数"), 4, 3)
|
||||||
grid.addWidget(Label("合约模式"), 3, 4)
|
grid.addWidget(Label("合约模式"), 4, 4)
|
||||||
|
|
||||||
int_validator = QtGui.QIntValidator()
|
int_validator = QtGui.QIntValidator()
|
||||||
|
|
||||||
@ -417,11 +430,11 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
inverse_combo = QtWidgets.QComboBox()
|
inverse_combo = QtWidgets.QComboBox()
|
||||||
inverse_combo.addItems(["正向", "反向"])
|
inverse_combo.addItems(["正向", "反向"])
|
||||||
|
|
||||||
grid.addWidget(Label("腿{}".format(i + 1)), 4 + i, 0)
|
grid.addWidget(Label("腿{}".format(i + 1)), 5 + i, 0)
|
||||||
grid.addWidget(symbol_line, 4 + i, 1)
|
grid.addWidget(symbol_line, 5 + i, 1)
|
||||||
grid.addWidget(price_line, 4 + i, 2)
|
grid.addWidget(price_line, 5 + i, 2)
|
||||||
grid.addWidget(trading_line, 4 + i, 3)
|
grid.addWidget(trading_line, 5 + i, 3)
|
||||||
grid.addWidget(inverse_combo, 4 + i, 4)
|
grid.addWidget(inverse_combo, 5 + i, 4)
|
||||||
|
|
||||||
d = {
|
d = {
|
||||||
"symbol": symbol_line,
|
"symbol": symbol_line,
|
||||||
@ -431,8 +444,8 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
}
|
}
|
||||||
self.leg_widgets.append(d)
|
self.leg_widgets.append(d)
|
||||||
|
|
||||||
grid.addWidget(Label(""), 4 + leg_count, 0,)
|
grid.addWidget(Label(""), 5 + leg_count, 0,)
|
||||||
grid.addWidget(button_add, 5 + leg_count, 0, 1, 4)
|
grid.addWidget(button_add, 6 + leg_count, 0, 1, 5)
|
||||||
|
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
@ -449,6 +462,7 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
active_symbol = self.active_line.text()
|
active_symbol = self.active_line.text()
|
||||||
|
min_volume = float(self.min_volume_combo.currentText())
|
||||||
|
|
||||||
leg_settings = {}
|
leg_settings = {}
|
||||||
for d in self.leg_widgets:
|
for d in self.leg_widgets:
|
||||||
@ -492,7 +506,8 @@ class SpreadDataDialog(QtWidgets.QDialog):
|
|||||||
self.spread_engine.add_spread(
|
self.spread_engine.add_spread(
|
||||||
spread_name,
|
spread_name,
|
||||||
list(leg_settings.values()),
|
list(leg_settings.values()),
|
||||||
active_symbol
|
active_symbol,
|
||||||
|
min_volume
|
||||||
)
|
)
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user