Skip to content

Commit

Permalink
moving ticktype to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jun 7, 2019
1 parent fd7f96c commit 0b93f86
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 47 deletions.
19 changes: 1 addition & 18 deletions aat/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import lru_cache
from enum import Enum
from ._enums import TickType, to_string as TickType_to_string, from_string as TickType_from_string # noqa: F401


class BaseEnum(Enum):
Expand All @@ -8,24 +9,6 @@ def members(cls):
return cls.__members__.keys()


class TickType(BaseEnum):
# Messages
TRADE = 'TRADE' # Match
OPEN = 'OPEN' # New Order
FILL = 'FILL' # Order completed - filled
CANCEL = 'CANCEL' # Order completed - cancelled
CHANGE = 'CHANGE' # Order modified

ERROR = 'ERROR' # Internal error
ANALYZE = 'ANALYZE' # Internal

HALT = 'HALT' # Trading halt
CONTINUE = 'CONTINUE' # Trading continue
EXIT = 'EXIT' # System exit

HEARTBEAT = 'HEARTBEAT' # Exchange heartbeat


class TradingType(BaseEnum):
NONE = 'NONE'
SANDBOX = 'SANDBOX'
Expand Down
4 changes: 2 additions & 2 deletions aat/exchanges/utils/coinbase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from ...enums import OrderType, OrderSubType, PairType, TickType
from ...enums import OrderType, OrderSubType, PairType, TickType, TickType_from_string
from ...structs import MarketData, Instrument
from ...utils import parse_date, str_to_currency_pair_type, str_to_side, str_to_order_type

Expand Down Expand Up @@ -41,7 +41,7 @@ def strToTradeType(self, s: str, reason: str = '') -> TickType:
return TickType.CANCEL
elif reason == 'filled':
return TickType.FILL
return TickType(s.upper())
return TickType_from_string(s.upper())
else:
return TickType.ERROR

Expand Down
4 changes: 2 additions & 2 deletions aat/exchanges/utils/gemini.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from ...enums import Side, OrderType, OrderSubType, PairType, TickType
from ...enums import Side, OrderType, OrderSubType, PairType, TickType, TickType_from_string
from ...structs import MarketData, Instrument
from ...utils import str_to_currency_pair_type, str_to_side

Expand Down Expand Up @@ -44,7 +44,7 @@ def strToTradeType(self, s: str) -> TickType:
return TickType.TRADE
elif s in ('AUCTION_INDICATIVE', 'AUCTION_OPEN'):
return TickType.OPEN
return TickType(s)
return TickType_from_string(s)

def reasonToTradeType(self, s: str) -> TickType:
s = s.upper()
Expand Down
3 changes: 3 additions & 0 deletions aat/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
OrderType, \
OrderSubType, \
TickType, \
TickType_to_string, \
TradeResult, \
InstrumentType, \
RiskReason
Expand All @@ -29,6 +30,8 @@ def to_dict(self, serializable=False, str_timestamp=False, **kwargs) -> dict:
ret[item] = getattr(self, item).to_dict(serializable, str_timestamp, **kwargs)
elif isinstance(ret[item], Enum) or isinstance(getattr(self, item), Enum):
ret[item] = str(getattr(self, item))
elif isinstance(ret[item], TickType):
ret[item] = TickType_to_string(ret[item])
elif isinstance(ret[item], float):
if ((ret[item] >= float('inf')) is False) and \
((ret[item] <= float('inf')) is False):
Expand Down
53 changes: 28 additions & 25 deletions cpp/include/aat/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace aat {
namespace enums {

enum class TickType {
TRADE,
OPEN,
FILL,
CANCEL,
CHANGE,
ERROR,
ANALYZE,
HALT,
CONTINUE,
EXIT,
HEARTBEAT,
TRADE = 0,
OPEN = 1,
FILL = 2,
CANCEL = 3,
CHANGE = 4,
ERROR = 5,
ANALYZE = 6,
HALT = 7,
CONTINUE = 8,
EXIT = 9,
HEARTBEAT = 10
};

static const char *TickTypeNames[] = {
Expand All @@ -43,21 +43,24 @@ namespace enums {
return TickTypeNames[static_cast<int>(type)];
}

static std::unordered_map<const char *, TickType> _mapping = {
{(const char *)"TRADE", TickType::TRADE},
{(const char *)"OPEN", TickType::OPEN},
{(const char *)"FILL", TickType::FILL},
{(const char *)"CANCEL", TickType::CANCEL},
{(const char *)"CHANGE", TickType::CHANGE},
{(const char *)"ERROR", TickType::ERROR},
{(const char *)"ANALYZE", TickType::ANALYZE},
{(const char *)"HALT", TickType::HALT},
{(const char *)"CONTINUE", TickType::CONTINUE},
{(const char *)"EXIT", TickType::EXIT},
{(const char *)"HEARTBEAT", TickType::HEARTBEAT},
static std::unordered_map<std::string, TickType> _mapping = {
{"TRADE", TickType::TRADE},
{"OPEN", TickType::OPEN},
{"FILL", TickType::FILL},
{"CANCEL", TickType::CANCEL},
{"CHANGE", TickType::CHANGE},
{"ERROR", TickType::ERROR},
{"ANALYZE", TickType::ANALYZE},
{"HALT", TickType::HALT},
{"CONTINUE", TickType::CONTINUE},
{"EXIT", TickType::EXIT},
{"HEARTBEAT", TickType::HEARTBEAT},
};

TickType from_string(char *s){ return _mapping[s]; }
TickType from_string(char *s)
{
return _mapping[s];
}
}
}

Expand All @@ -77,7 +80,7 @@ PYBIND11_MODULE(_enums, m)
.value("HALT", TickType::HALT)
.value("CONTINUE", TickType::CONTINUE)
.value("EXIT", TickType::EXIT)
.value("HEARTBEAT)", TickType::HEARTBEAT);
.value("HEARTBEAT", TickType::HEARTBEAT);

m.def("to_string", &to_string, "TickType enum to string");
m.def("from_string", &from_string, "string to TickType enum");
Expand Down

0 comments on commit 0b93f86

Please sign in to comment.