Skip to content

Commit

Permalink
rename to _enums
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jun 7, 2019
1 parent 1ed6783 commit fd7f96c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 97 deletions.
20 changes: 8 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,21 @@ add_library(binding SHARED
${HEADER_FILES})
set_target_properties(binding PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/aat)
target_link_libraries(binding ${BOOST_PYTHON})
target_link_libraries(binding ${BOOST_NUMPY})
target_link_libraries(binding ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_link_libraries(binding ${PYTHON_LIBRARIES})

add_library(_cpp_helpers SHARED
${CMAKE_SOURCE_DIR}/cpp/src/_cpp_helpers.cpp)
set_target_properties(_cpp_helpers PROPERTIES
add_library(_enums SHARED
${CMAKE_SOURCE_DIR}/cpp/src/enums.cpp)
set_target_properties(_enums PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/aat)
target_link_libraries(_cpp_helpers binding)
target_link_libraries(_cpp_helpers ${BOOST_PYTHON})
target_link_libraries(_cpp_helpers ${BOOST_NUMPY})
target_link_libraries(_cpp_helpers ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
# target_link_libraries(_enums binding)
target_link_libraries(_enums ${PYTHON_LIBRARIES})
########################

if(CPP_BUILD_STRICT AND NOT WIN32)
target_compile_options(binding PRIVATE -Wall -Werror)
target_compile_options(binding PRIVATE $<$<CONFIG:DEBUG>:-fPIC -O0>)
target_compile_options(_cpp_helpers PRIVATE -Wall -Werror)
target_compile_options(_cpp_helpers PRIVATE $<$<CONFIG:DEBUG>:-fPIC -O0>)
target_compile_options(_enums PRIVATE -Wall -Werror)
target_compile_options(_enums PRIVATE $<$<CONFIG:DEBUG>:-fPIC -O0>)
endif()


Expand Down
9 changes: 4 additions & 5 deletions aat/structs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from dataclasses import dataclass, field, fields, asdict
from dataclasses import dataclass, asdict
from enum import Enum
from .enums import Side, \
ExchangeType, \
Expand All @@ -25,11 +25,9 @@ def to_dict(self, serializable=False, str_timestamp=False, **kwargs) -> dict:
ret[item] = ret[item].strftime('%y-%m-%d %H:%M:%S')
else:
ret[item] = round(ret[item].timestamp())
elif isinstance(ret[item], Struct) or \
isinstance(getattr(self, item), Struct):
elif isinstance(ret[item], Struct) or isinstance(getattr(self, item), Struct):
ret[item] = getattr(self, item).to_dict(serializable, str_timestamp, **kwargs)
elif isinstance(ret[item], Enum) or \
isinstance(getattr(self, item), Enum):
elif isinstance(ret[item], Enum) or isinstance(getattr(self, item), Enum):
ret[item] = str(getattr(self, item))
elif isinstance(ret[item], float):
if ((ret[item] >= float('inf')) is False) and \
Expand Down Expand Up @@ -191,6 +189,7 @@ def __str__(self):
def __lt__(self, other):
return self.price < other.price


@dataclass
class TradeRequest(Struct):
side: Side
Expand Down
2 changes: 1 addition & 1 deletion aat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import pytz
from datetime import datetime
from enum import Enum
from functools import lru_cache
from .enums import ExchangeType, CurrencyType, OrderType, Side, PairType
from .exceptions import AATException
Expand All @@ -17,6 +16,7 @@
MANUAL as mlog, \
ERROR as elog


@lru_cache(None)
def parse_date(indate: str) -> datetime:
try:
Expand Down
78 changes: 0 additions & 78 deletions cpp/include/aat/_cpp_helpers.hpp

This file was deleted.

85 changes: 85 additions & 0 deletions cpp/include/aat/enums.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma once

#include <iostream>
#include <unordered_map>
#include <pybind11/pybind11.h>
#include "common.h"

namespace py = pybind11;

namespace aat {
namespace enums {

enum class TickType {
TRADE,
OPEN,
FILL,
CANCEL,
CHANGE,
ERROR,
ANALYZE,
HALT,
CONTINUE,
EXIT,
HEARTBEAT,
};

static const char *TickTypeNames[] = {
"TRADE",
"OPEN",
"FILL",
"CANCEL",
"CHANGE",
"ERROR",
"ANALYZE",
"HALT",
"CONTINUE",
"EXIT",
"HEARTBEAT",
};

const char *to_string(TickType type)
{
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},
};

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


PYBIND11_MODULE(_enums, m)
{
m.doc() = "C++ enums";
using namespace aat::enums;
py::enum_<TickType>(m, "TickType", py::arithmetic())
.value("TRADE", TickType::TRADE)
.value("OPEN", TickType::OPEN)
.value("FILL", TickType::FILL)
.value("CANCEL", TickType::CANCEL)
.value("CHANGE", TickType::CHANGE)
.value("ERROR", TickType::ERROR)
.value("ANALYZE", TickType::ANALYZE)
.value("HALT", TickType::HALT)
.value("CONTINUE", TickType::CONTINUE)
.value("EXIT", TickType::EXIT)
.value("HEARTBEAT)", TickType::HEARTBEAT);

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

}
1 change: 0 additions & 1 deletion cpp/src/_cpp_helpers.cpp

This file was deleted.

1 change: 1 addition & 0 deletions cpp/src/enums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <aat/enums.hpp>

0 comments on commit fd7f96c

Please sign in to comment.