-
Notifications
You must be signed in to change notification settings - Fork 0
Tick Scheme
Loren1166 edited this page Sep 25, 2024
·
1 revision
Defines a scheme for modeling the tick space for various instruments. 定义用于对各种工具的跳动空间建模的方案。
class FixedTickScheme(TickScheme):
"""
Represents a fixed precision tick scheme such as for Forex or Crypto.
表示固定精度的跳动方案,例如外汇或加密货币。
Parameters:
参数:
name (str) – The name of the tick scheme.
跳动方案的名称。
price_precision (int) – The instrument price precision.
工具价格精度。
min_tick (Price) – The minimum possible tick Price.
最小可能的跳动价格。
max_tick (Price) – The maximum possible tick Price.
最大可能的跳动价格。
increment (float , optional) – The tick increment.
跳动增量。
Raises:
引发:
ValueError – If name is not a valid string.
如果名称不是有效的字符串。
"""
def __init__(
self,
name: str,
price_precision: int,
min_tick: Price,
max_tick: Price,
increment: float | None = None
):
...
@property
def increment(self) -> Price:
"""
The tick scheme price increment.
跳动方案价格增量。
Returns: Price
"""
...
@property
def max_price(self) -> Price:
"""
The maximum valid price for the scheme.
方案的最大有效价格。
Returns: Price
"""
...
@property
def min_price(self) -> Price:
"""
The minimum valid price for the scheme.
方案的最小有效价格。
Returns: Price
"""
...
@property
def name(self) -> str:
"""
The name of the scheme.
方案的名称。
Returns: str
"""
...
def next_ask_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n ask ticks away from value.
返回距离 value n 个卖出跳动的价格。
If a given price is between two ticks, n=0 will find the nearest ask tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的卖出跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
def next_bid_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n bid ticks away from value.
返回距离 value n 个买入跳动的价格。
If a given price is between two ticks, n=0 will find the nearest bid tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的买入跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
@property
def price_precision(self) -> int:
"""
The tick scheme price precision.
跳动方案价格精度。
Returns: int
"""
...
class TieredTickScheme(TickScheme):
"""
Represents a tick scheme where tick levels change based on price level, such as various financial exchanges.
表示基于价格级别而跳动级别发生变化的跳动方案,例如各种金融交易所。
Parameters:
参数:
name (str) – The name of the tick scheme.
跳动方案的名称。
tiers (list *[*tuple *(*start , stop , step ) ]) – The tiers for the tick scheme. Should be a list of (start, stop, step) tuples.
跳动方案的层级。应为 (start, stop, step) 元组的列表。
max_ticks_per_tier (int , default 100) – The maximum number of ticks per tier.
每层最大跳动数。
Raises:
引发:
ValueError – If name is not a valid string.
如果名称不是有效的字符串。
"""
def __init__(
self,
name: str,
tiers: list,
price_precision: int,
max_ticks_per_tier: int = 100
):
...
def find_tick_index(self, value: float) -> int:
...
@property
def max_price(self) -> Price:
"""
The maximum valid price for the scheme.
方案的最大有效价格。
Returns: Price
"""
...
@property
def min_price(self) -> Price:
"""
The minimum valid price for the scheme.
方案的最小有效价格。
Returns: Price
"""
...
@property
def name(self) -> str:
"""
The name of the scheme.
方案的名称。
Returns: str
"""
...
def next_ask_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n ask ticks away from value.
返回距离 value n 个卖出跳动的价格。
If a given price is between two ticks, n=0 will find the nearest ask tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的卖出跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
def next_bid_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n bid ticks away from value.
返回距离 value n 个买入跳动的价格。
If a given price is between two ticks, n=0 will find the nearest bid tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的买入跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
@property
def ticks(self):
...
class TickScheme:
"""
Represents an instrument tick scheme.
表示工具跳动方案。
Maps the valid prices available for an instrument.
映射工具可用的有效价格。
Parameters:
参数:
name (str) – The name of the tick scheme.
跳动方案的名称。
min_tick (Price) – The minimum possible tick Price.
最小可能的跳动价格。
max_tick (Price) – The maximum possible tick Price.
最大可能的跳动价格。
Raises:
引发:
ValueError – If name is not a valid string.
如果名称不是有效的字符串。
"""
def __init__(self, name: str, min_tick: Price, max_tick: Price):
...
@property
def max_price(self) -> Price:
"""
The maximum valid price for the scheme.
方案的最大有效价格。
Returns: Price
"""
...
@property
def min_price(self) -> Price:
"""
The minimum valid price for the scheme.
方案的最小有效价格。
Returns: Price
"""
...
@property
def name(self) -> str:
"""
The name of the scheme.
方案的名称。
Returns: str
"""
...
def next_ask_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n ask ticks away from value.
返回距离 value n 个卖出跳动的价格。
If a given price is between two ticks, n=0 will find the nearest ask tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的卖出跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
def next_bid_price(self, value: float, n: int = 0) -> Price:
"""
Return the price n bid ticks away from value.
返回距离 value n 个买入跳动的价格。
If a given price is between two ticks, n=0 will find the nearest bid tick.
如果给定价格介于两个跳动之间,则 n=0 将找到最近的买入跳动。
Parameters:
参数:
value (double) – The reference value.
参考值。
n (int , default 0) – The number of ticks to move.
要移动的跳动数。
Return type: Price
"""
...
def get_tick_scheme(name: str) -> TickScheme:
...
def list_tick_schemes() -> list:
...
def register_tick_scheme(tick_scheme: TickScheme) -> None:
...
def round_down(value: float, base: float) -> float:
"""
Returns a value rounded down to a specific number of decimal places.
返回向下舍入到特定小数位数的值。
"""
...
def round_up(value: float, base: float) -> float:
"""
Returns a value rounded down to a specific number of decimal places.
返回向下舍入到特定小数位数的值。
"""
...