import unittest from action import Action from orderbook import Orderbook from order import Order from order_type import OrderType from order_side import OrderSide orderbook = Orderbook(extraFeatures=False) orderbook.loadFromFile('test_orderbook_10s.tsv') class MatchEngineMock(): def matchOrder(self, order, seconds=None): trades = [] qtyRemain = 0 index = 1 return trades, qtyRemain, index class ActionMock(Action): def __init__(self, a, runtime): Action.__init__(self, a, runtime) def getMatchEngine(self, orderbook): return MatchEngineMock() class ActionTest(unittest.TestCase): def testRun(self): a = 1 i = 1.0
from orderbook import Orderbook import numpy as np import pandas as pd import os book = 'query_result_test.tsv' tmp = 'feature.tsv' orderbook = Orderbook() orderbook.loadFromFile(book) states = orderbook.getStates() def stateDiff(start, end): """Calculate time difference between two states.""" consumed = (end.getTimestamp() - start.getTimestamp()).total_seconds() return consumed def getPastState(i, t): """Find state at index i - time t.""" endState = states[i] state = endState while (stateDiff(state, endState) < t): i = i - 1 if i < 0: raise Exception("Not enough states available for diff.") state = states[i] return i def traverse(f, g, default=0.0, t=60):