mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
python: get type from str
This commit is contained in:
parent
7dcdecc4d7
commit
c9792e21ee
|
@ -11,6 +11,6 @@ class ChannelType(Enum):
|
|||
BALANCE = 4
|
||||
ORDER = 5
|
||||
|
||||
@staticmethod
|
||||
def from_str(s: str) -> ChannelType:
|
||||
return {t.name.lower(): t for t in ChannelType}[s]
|
||||
@classmethod
|
||||
def from_str(cls, s: str) -> ChannelType:
|
||||
return {t.name.lower(): t for t in cls}[s.lower()]
|
||||
|
|
|
@ -10,3 +10,7 @@ class DepthType(Enum):
|
|||
DEPTH_1 = '1'
|
||||
DEPTH_5 = '5'
|
||||
DEPTH_20 = '20'
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, s: str) -> DepthType:
|
||||
return {t.name.lower(): t for t in cls}[s.lower()]
|
||||
|
|
|
@ -11,3 +11,7 @@ class EventType(Enum):
|
|||
UPDATE = 4
|
||||
AUTHENTICATED = 5
|
||||
ERROR = 99
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, s: str) -> EventType:
|
||||
return {t.name.lower(): t for t in cls}[s.lower()]
|
||||
|
|
|
@ -10,3 +10,7 @@ class OrderType(Enum):
|
|||
STOP_LIMIT = 3
|
||||
POST_ONLY = 4
|
||||
IOC_LIMIT = 5
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, s: str) -> OrderType:
|
||||
return {t.name.lower(): t for t in cls}[s.lower()]
|
||||
|
|
|
@ -6,3 +6,7 @@ from enum import Enum
|
|||
class SideType(Enum):
|
||||
BUY = 0
|
||||
SELL = 1
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, s: str) -> SideType:
|
||||
return {t.name.lower(): t for t in cls}[s.lower()]
|
||||
|
|
|
@ -27,7 +27,7 @@ class Stream(object):
|
|||
self.event_handlers = []
|
||||
|
||||
def subscribe(self, exchange: str, channel: str, symbol: str, depth: str = None, interval: str = None):
|
||||
subscription = Subscription(exchange=exchange, channel=ChannelType(channel), symbol=symbol)
|
||||
subscription = Subscription(exchange=exchange, channel=ChannelType.from_str(channel), symbol=symbol)
|
||||
|
||||
if depth is not None:
|
||||
subscription.depth = DepthType(depth)
|
||||
|
|
Loading…
Reference in New Issue
Block a user