Skip to content

Commit

Permalink
Merge pull request #116 from AsyncAlgoTrading/coinbase
Browse files Browse the repository at this point in the history
Coinbase updates
  • Loading branch information
timkpaine committed Nov 2, 2020
2 parents a7c2ee5 + 51516e0 commit 0cd3871
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 153 deletions.
20 changes: 12 additions & 8 deletions aat/core/data/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def _make_cpp_order(volume, price, side, instrument, exchange=ExchangeType(""), notional=0.0, order_type=OrderType.MARKET, flag=OrderFlag.NONE, stop_target=None):
'''helper method to ensure all arguments are setup'''
return OrderCpp(0, datetime.now(), volume, price, side, instrument, exchange, notional, order_type, flag, stop_target)
return OrderCpp("0", datetime.now(), volume, price, side, instrument, exchange, notional, order_type, flag, stop_target)


class Order(object):
Expand Down Expand Up @@ -69,8 +69,8 @@ def __init__(self, volume, price, side, instrument, exchange=ExchangeType(""), n
assert (order_type != OrderType.STOP and stop_target is None) or (isinstance(stop_target, Order) and order_type == OrderType.STOP and stop_target.order_type != OrderType.STOP)
assert order_type != OrderType.STOP or (isinstance(stop_target.instrument, Instrument))

self.__volume = volume
self.__price = price
self.__volume = round(volume, 8)
self.__price = round(price, 4)
self.__side = side
self.__notional = notional
self.__order_type = order_type
Expand Down Expand Up @@ -138,13 +138,13 @@ def finish(self) -> None:
# Read/write #
# ***********#
@property
def id(self) -> int:
def id(self) -> str:
return self.__id

@id.setter
def id(self, id: int) -> None:
assert isinstance(id, int)
self.__id = id
def id(self, id: Union[str, int]) -> None:
assert isinstance(id, (int, str))
self.__id = str(id)

@property
def timestamp(self) -> datetime:
Expand All @@ -163,7 +163,10 @@ def volume(self) -> float:
def volume(self, volume: float) -> None:
assert isinstance(volume, (int, float))
assert volume < float('inf') and (volume > 0 or self.order_type == OrderType.STOP)
volume = round(volume, 8)

assert volume >= self.filled

self.__volume = volume

@property
Expand All @@ -173,6 +176,7 @@ def filled(self) -> float:
@filled.setter
def filled(self, filled: float) -> None:
assert isinstance(filled, (int, float))
filled = round(filled, 8)
assert filled <= self.volume
self.__filled = filled

Expand Down Expand Up @@ -239,7 +243,7 @@ def fromJson(jsn):
@staticmethod
def perspectiveSchema() -> Mapping[str, Type]:
return {
"id": int,
"id": str,
"timestamp": int,
"volume": float,
"price": float,
Expand Down
10 changes: 5 additions & 5 deletions aat/core/data/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __new__(cls, *args, **kwargs):
return super(Trade, cls).__new__(cls)

def __init__(self, volume, price, maker_orders, taker_order):
self.__id = -1 # on construction, provide no ID until exchange assigns one
self.__id = "" # on construction, provide no ID until exchange assigns one
self.__type = DataType.TRADE

assert(isinstance(price, (float, int)))
Expand Down Expand Up @@ -101,13 +101,13 @@ def finished(self):
# Read/write #
# ***********#
@property
def id(self) -> int:
def id(self) -> str:
return self.__id

@id.setter
def id(self, id: int) -> None:
assert isinstance(id, int)
self.__id = id
def id(self, id: str) -> None:
assert isinstance(id, (str, int))
self.__id = str(id)

@property
def maker_orders(self) -> List[Order]:
Expand Down
4 changes: 2 additions & 2 deletions aat/cpp/include/aat/core/data/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace aat::config;
namespace aat {
namespace core {
struct Order : public _EventTarget {
Order(uint_t id, timestamp_t timestamp, double volume, double price, Side side, Instrument& instrument,
Order(str_t id, timestamp_t timestamp, double volume, double price, Side side, Instrument& instrument,
ExchangeType& exchange = NullExchange, double notional = 0.0, OrderType order_type = OrderType::MARKET,
OrderFlag flag = OrderFlag::NONE, std::shared_ptr<Order> stop_target = nullptr);

Expand All @@ -26,7 +26,7 @@ namespace core {
virtual json toJson() const;
virtual json perspectiveSchema() const;

uint_t id;
str_t id;
timestamp_t timestamp;
const DataType type;
const Instrument instrument;
Expand Down
4 changes: 2 additions & 2 deletions aat/cpp/include/aat/core/data/trade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace aat::config;
namespace aat {
namespace core {
struct Trade : public _EventTarget {
Trade(uint_t id, double volume, double price,
Trade(str_t id, double volume, double price,
std::deque<std::shared_ptr<Order>> maker_orders = std::deque<std::shared_ptr<Order>>(),
std::shared_ptr<Order> taker_order = nullptr)
: id(id)
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace core {
virtual json toJson() const;
virtual json perspectiveSchema() const;

uint_t id;
str_t id;
timestamp_t timestamp;
const DataType type;

Expand Down
4 changes: 2 additions & 2 deletions aat/cpp/include/aat/python/binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ PYBIND11_MODULE(binding, m) {
.def_readonly("target", &Event::target);

py::class_<Order, std::shared_ptr<Order>>(m, "OrderCpp")
.def(py::init<uint_t, timestamp_t, double, double, Side, Instrument&, ExchangeType&, double, OrderType, OrderFlag,
.def(py::init<str_t, timestamp_t, double, double, Side, Instrument&, ExchangeType&, double, OrderType, OrderFlag,
std::shared_ptr<Order>>(),
py::arg("id").none(false), py::arg("timestamp").none(false), py::arg("volume").none(false),
py::arg("price").none(false), py::arg("side").none(false), py::arg("instrument").none(false),
Expand All @@ -213,7 +213,7 @@ PYBIND11_MODULE(binding, m) {
.def_readwrite("notional", &Order::notional);

py::class_<Trade, std::shared_ptr<Trade>>(m, "TradeCpp")
.def(py::init<uint_t, double, double, std::deque<std::shared_ptr<Order>>, std::shared_ptr<Order>>())
.def(py::init<str_t, double, double, std::deque<std::shared_ptr<Order>>, std::shared_ptr<Order>>())
.def("__repr__", &Trade::toString)
.def("slippage", &Trade::slippage)
.def("transactionCost", &Trade::transactionCost)
Expand Down
4 changes: 2 additions & 2 deletions aat/cpp/src/core/data/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace aat::common;

namespace aat {
namespace core {
Order::Order(uint_t id, timestamp_t timestamp, double volume, double price, Side side, Instrument& instrument,
Order::Order(str_t id, timestamp_t timestamp, double volume, double price, Side side, Instrument& instrument,
ExchangeType& exchange, double notional, OrderType order_type, OrderFlag flag, std::shared_ptr<Order> stop_target)
: id(id)
, timestamp(timestamp)
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace core {
json
Order::perspectiveSchema() const {
json ret;
ret["id"] = "int";
ret["id"] = "str";
ret["timestamp"] = "int";
ret["volume"] = "float";
ret["price"] = "float";
Expand Down
2 changes: 1 addition & 1 deletion aat/cpp/src/core/data/trade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace core {
json
Trade::perspectiveSchema() const {
json ret;
ret["id"] = "int";
ret["id"] = "str";
ret["timestamp"] = "int";
ret["volume"] = "float";
ret["price"] = "float";
Expand Down
2 changes: 1 addition & 1 deletion aat/cpp/src/core/order_book/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace core {
throw AATCPPException("Accumulation error occurred");
}

push(std::make_shared<Event>(EventType::TRADE, std::make_shared<Trade>(0, price, volume, orders, taker_order)));
push(std::make_shared<Event>(EventType::TRADE, std::make_shared<Trade>("", price, volume, orders, taker_order)));
this->taker_order = taker_order;
}

Expand Down
1 change: 0 additions & 1 deletion aat/engine/dispatch/risk/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def risk(self, position=None):
# *********************
async def newOrder(self, strategy, order: Order):
# TODO
print('adding order: {}'.format(order))
self._active_orders.append(order) # TODO use strategy
return order, True

Expand Down

0 comments on commit 0cd3871

Please sign in to comment.