Skip to content

Commit

Permalink
Merge pull request #56 from AsyncAlgoTrading/windows
Browse files Browse the repository at this point in the history
starting on windows support
  • Loading branch information
timkpaine committed Jun 14, 2020
2 parents af4bac5 + 5f1de86 commit 0aee0f9
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__/

# C extensions
*.so
*.dll

# Distribution / packaging
.Python
Expand Down
42 changes: 19 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.7.2)
project(aat)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -141,23 +139,29 @@ endif()
# VANILLA CPP BUILD #
#####################
if(CMAKE_BUILD_TYPE_LOWER STREQUAL debug)
set(OPT_FLAGS " \
set(FLAGS " \
-O1 \
-DEBUG
-g3 \
")
else()
set(OPT_FLAGS " \
set(FLAGS " \
-O3 \
-DNDEBUG
-g0 \
")
endif()

set(CMAKE_CXX_FLAGS " \
${CMAKE_CXX_FLAGS} \
${EXTENDED_FLAGS} \
${OPT_FLAGS} \
")
set(CMAKE_C_FLAGS " \
${CMAKE_C_FLAGS} \
${OPT_FLAGS} \
")


message(WARNING "${BUILD_MESSAGE}")

if(WIN32)
Expand Down Expand Up @@ -197,25 +201,17 @@ build_dep("json-pybind" "${AAT_CMAKE_MODULE_PATH}/Json_pybind.txt.in")
build_dep("date" "${AAT_CMAKE_MODULE_PATH}/date.txt.in")

if(MACOS)
# on mac, use the vanilla pybind11 finder
find_package(pybind11)
if(pybind11_FOUND)
# Homebrew install pybind11
set(PYTHON_PYBIND_FOUND pybind11_FOUND)
else()
# see if python installed pybind11 is available
find_package(Pybind)
if(PYTHON_PYBIND_FOUND)
# Need to add extra flags due to pybind weirness
# https://github.com/pybind/pybind11/blob/7830e8509f2adc97ce9ee32bf99cd4b82089cc4c/tools/pybind11Tools.cmake#L103
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()
# see if python installed pybind11 is available
find_package(Pybind)
if(PYTHON_PYBIND_FOUND)
# Need to add extra flags due to pybind weirness
# https://github.com/pybind/pybind11/blob/7830e8509f2adc97ce9ee32bf99cd4b82089cc4c/tools/pybind11Tools.cmake#L103
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()

else()
# on linux or in docker, use our custom pybind finder to look
# for just the python installed pybind
find_package(Pybind)
find_package(Pybind11)
endif()

if(NOT PYTHON_PYBIND_FOUND)
Expand All @@ -237,7 +233,7 @@ include_directories( ${PYTHON_NUMPY_INCLUDE_DIR})
#####################

if (WIN32)
set(CMAKE_CXX_FLAGS " /EHsc")
set(CMAKE_CXX_FLAGS " /EHsc -DHAVE_SNPRINTF")
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
Expand Down Expand Up @@ -267,8 +263,8 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")
include_directories("${CMAKE_SOURCE_DIR}/cpp/include")

set(SOURCE_FILES
${CMAKE_SOURCE_DIR}/cpp/src/config/enums.cpp
${CMAKE_SOURCE_DIR}/cpp/src/config/parser.cpp
${CMAKE_SOURCE_DIR}/cpp/src/config/enums.cpp
${CMAKE_SOURCE_DIR}/cpp/src/config/parser.cpp
${CMAKE_SOURCE_DIR}/cpp/src/core/instrument/instrument.cpp
${CMAKE_SOURCE_DIR}/cpp/src/core/exchange/exchange.cpp
${CMAKE_SOURCE_DIR}/cpp/src/core/models/data.cpp
Expand Down
31 changes: 16 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
PYTHON=python3.7
CONFIG=./config/synthetic.cfg


run: build ## Clean and make target, run target
python3 -m aat $(CONFIG)
$(PYTHON) -m aat $(CONFIG)

runcpp: build ## Clean and make target, run target
AAT_USE_CPP=1 python3 -m aat $(CONFIG)
AAT_USE_CPP=1 $(PYTHON) -m aat $(CONFIG)

rundebug: debug ## Clean and make debug target, run target
python3 -m aat $(CONFIG)
$(PYTHON) -m aat $(CONFIG)

buildext: ## build the package extensions
python3 setup.py build_ext
$(PYTHON) setup.py build_ext

build: ## build the package
python3 setup.py build
$(PYTHON) setup.py build

debug: ## build debug build of the package
DEBUG=1 python3 setup.py build
DEBUG=1 $(PYTHON) setup.py build

js: ## build the js assets
cd js; yarn build

install: ## install the package
python3 -m pip install .
$(PYTHON) -m pip install .

tests: build testpy ## Make unit tests

testpy: ## Make unit tests
python3 -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch
$(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch

testpycpp: ## Make unit tests
# AAT_USE_CPP=1 python3 -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch --capture=no
AAT_USE_CPP=1 python3 -m pytest -s ./aat/tests
# AAT_USE_CPP=1 $(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch --capture=no
AAT_USE_CPP=1 $(PYTHON) -m pytest -s ./aat/tests

testjs: ## Make js tests
cd js; yarn test

lint: lintpy lintjs lintcpp ## run all linters

lintpy: ## run python linter
python3 -m flake8 aat setup.py
$(PYTHON) -m flake8 aat setup.py

lintjs: ## run js linter
cd js; yarn lint
Expand All @@ -51,7 +52,7 @@ lintcpp: ## run cpp linter
fix: fixpy fixjs fixcpp ## run all fixers

fixpy: ## run autopep8 fix
python3 -m autopep8 --in-place -r -a -a aat/ setup.py
$(PYTHON) -m autopep8 --in-place -r -a -a aat/ setup.py

fixcpp: ## run clang-format
clang-format -i -style=file `find ./cpp -name "*.*pp"`
Expand All @@ -60,18 +61,18 @@ fixjs: ## run clang-format
cd js; yarn fix

annotate: ## MyPy type annotation check
python3 -m mypy aat
$(PYTHON) -m mypy aat

annotate_l: ## MyPy type annotation check - count only
python3 -m mypy -s aat | wc -l
$(PYTHON) -m mypy -s aat | wc -l

docs: ## Build the sphinx docs
make -C docs html
open ./docs/_build/html/index.html

dist: ## dist to pypi
rm -rf dist build
python3 setup.py sdist bdist_wheel
$(PYTHON) setup.py sdist bdist_wheel
twine check dist/* && twine upload dist/*

clean: ## clean the repository
Expand Down
5 changes: 4 additions & 1 deletion aat/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from .order_book import OrderBook # noqa: F401
from .table import TableHandler # noqa: F401

from ..binding import InstrumentCpp, DataCpp, EventCpp, OrderCpp, TradeCpp, OrderBookCpp # noqa: F401
try:
from ..binding import InstrumentCpp, DataCpp, EventCpp, OrderCpp, TradeCpp, OrderBookCpp # noqa: F401
except ImportError:
pass

# import last
from .engine import TradingEngine # noqa: F401
18 changes: 13 additions & 5 deletions aat/core/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from traitlets.config.application import Application # type: ignore
from traitlets import validate, TraitError, Unicode, Bool, List, Instance # type: ignore
from tornado.web import StaticFileHandler, RedirectHandler, Application as TornadoApplication
from perspective import PerspectiveManager, PerspectiveTornadoHandler # type: ignore

try:
from perspective import PerspectiveManager, PerspectiveTornadoHandler # type: ignore
except ImportError:
PerspectiveManager, PerspectiveTornadoHandler = None, None # type: ignore

from .manager import Manager
from ..execution import ExecutionManager
Expand Down Expand Up @@ -48,7 +52,8 @@ class TradingEngine(Application):

api_application = Instance(klass=TornadoApplication)
api_handlers = List(default_value=[])
table_manager = Instance(klass=PerspectiveManager, args=(), kwargs={})

table_manager = Instance(klass=PerspectiveManager or object, args=(), kwargs={}) # failover to object

aliases = {
'port': 'AAT.port',
Expand Down Expand Up @@ -108,9 +113,12 @@ def __init__(self, **config):
# install webserver
if self.api:
self.log.critical('Installing API handlers')
table_handler = TableHandler()
table_handler.installTables(self.table_manager)
self.registerHandler(table_handler)

if PerspectiveManager is not None:
table_handler = TableHandler()
table_handler.installTables(self.table_manager)
self.registerHandler(table_handler)

self.api_handlers.append((r"/", RedirectHandler, {"url": "/index.html"}))
self.api_handlers.append((r"/api/v1/ws", PerspectiveTornadoHandler, {"manager": self.table_manager, "check_origin": True}))
self.api_handlers.append((r"/static/js/(.*)", StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__), '..', '..', 'ui', 'assets', 'static', 'js')}))
Expand Down
14 changes: 13 additions & 1 deletion aat/core/table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from typing import Tuple
from .models import Event, Order, Trade
from .handler import EventHandler
from perspective import Table # type: ignore

try:
from perspective import Table # type: ignore
except ImportError:
class Table(object):
def __init__(*args, **kwargs):
pass

def update(self, *args):
pass

def remove(self, *args):
pass


class TableHandler(EventHandler):
Expand Down
120 changes: 74 additions & 46 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,49 +132,77 @@ jobs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/*coverage.xml'

# - job: 'Windows'
# pool:
# vmImage: 'vs2017-win2016'

# strategy:
# matrix:
# Python37:
# python.version: '3.7'

# steps:
# - task: UsePythonVersion@0
# inputs:
# versionSpec: '$(python.version)'
# displayName: 'Use Python $(python.version)'

# - script: |
# which python > python.txt
# set /p PYTHON=<python.txt
# ln -s %PYTHON% %PYTHON%$(python.version)
# python --version
# which python$(python.version)
# displayName: "Which python"

# - script: |
# python -m pip install --upgrade pip
# pip install -e .[dev]
# displayName: 'Install dependencies'

# - script: |
# make lint
# displayName: 'Lint'

# - script: |
# make tests
# displayName: 'Test'

# - task: PublishTestResults@2
# condition: succeededOrFailed()
# inputs:
# testResultsFiles: 'python_junit.xml'
# testRunTitle: 'Publish test results for Python $(python.version) $(manylinux_flag)'

# - task: PublishCodeCoverageResults@1
# inputs:
# codeCoverageTool: Cobertura
# summaryFileLocation: '$(System.DefaultWorkingDirectory)/*coverage.xml'
- job: 'Windows'
pool:
vmImage: 'vs2017-win2016'

strategy:
matrix:
Python37:
python.version: '3.7'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
which python > python.txt
set /p PYTHON=<python.txt
ln -s %PYTHON% %PYTHON%$(python.version)
python --version
which python$(python.version)
displayName: "Which python"
- task: NodeTool@0
inputs:
versionSpec: '12.x'

- bash: npm install -g yarn
displayName: "Install Yarn"

- bash: cd js; yarn
displayName: 'Install JS dependencies'

- script: |
python -m pip install --upgrade pip numpy pyarrow==0.15.1 cpplint
pip install -e .[dev]
displayName: 'Install Python Dependencies'
env:
# Set `BOOST_ROOT` manually, as `BOOST_ROOT` is removed in the VM:
# https://github.com/actions/virtual-environments/issues/687
BOOST_ROOT: "C:/hostedtoolcache/windows/Boost/1.69.0/"
BOOST_INCLUDEDIR: "C:/hostedtoolcache/windows/Boost/1.69.0/include"
BOOST_LIBRARYDIR: "C:/hostedtoolcache/windows/Boost/1.69.0/libs"
- script: |
make lintpy
displayName: 'Lint Python'
- script: |
make lintjs
displayName: 'Lint JS'
- script: |
make lintcpp
displayName: 'Lint C++'
- script: |
make tests
displayName: 'Test'
- script: |
make testpycpp
displayName: 'Test C++'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: 'python_junit.xml'
testRunTitle: 'Publish test results for Python $(python.version) $(manylinux_flag)'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/*coverage.xml'
File renamed without changes.

0 comments on commit 0aee0f9

Please sign in to comment.