Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed May 29, 2019
1 parent be40fa6 commit 4fcd5c0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions aat/strategies/sma_crosses_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def onTrade(self, data: MarketData) -> bool:
volume=max(min(1.0, data.volume), .2),
instrument=data.instrument,
order_type=OrderType.MARKET,
exchange=data.exchange,
price=data.price)
# slog.info("requesting buy : %s", req)
self.requestBuy(self.onBuy, req)
Expand All @@ -108,6 +109,7 @@ def onTrade(self, data: MarketData) -> bool:
volume=self.bought_qty,
instrument=data.instrument,
order_type=OrderType.MARKET,
exchange=data.exchange,
price=data.price)
# slog.info("requesting sell : %s", req)
self.requestSell(self.onSell, req)
Expand Down
1 change: 1 addition & 0 deletions aat/tests/strategies/test_sma_crosses_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_sma_buy(self):
def ret(callback, req, callback_failure=None, strat=None):
res = TradeResponse(request=req,
side=req.side,
exchange=ExchangeType.COINBASE,
instrument=Instrument(underlying=PairType.BTCUSD),
price=req.price,
volume=req.volume,
Expand Down
5 changes: 4 additions & 1 deletion aat/tests/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_init(self):

def test_request(self):
from ..execution import Execution
from ..enums import Side, PairType, OrderType
from ..enums import Side, PairType, OrderType, ExchangeType
from ..config import ExecutionConfig
from ..structs import TradeRequest, Instrument

Expand All @@ -44,6 +44,7 @@ def test_request(self):
req = TradeRequest(side=Side.BUY,
instrument=Instrument(underlying=PairType.BTCUSD),
order_type=OrderType.MARKET,
exchange=ExchangeType.COINBASE,
volume=1.0,
price=1.0)

Expand All @@ -52,6 +53,7 @@ def test_request(self):
req = TradeRequest(side=Side.SELL,
instrument=Instrument(underlying=PairType.BTCUSD),
order_type=OrderType.MARKET,
exchange=ExchangeType.COINBASE,
volume=1.0,
price=1.0)

Expand All @@ -60,6 +62,7 @@ def test_request(self):
req = TradeRequest(side=Side.BUY,
instrument=Instrument(underlying=PairType.BTCUSD),
order_type=OrderType.MARKET,
exchange=ExchangeType.COINBASE,
volume=1.0,
price=1.0)

Expand Down
8 changes: 4 additions & 4 deletions aat/tests/test_risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def test_construct_reponse(self):

def test_request(self):
from ..structs import TradeRequest, Instrument
from ..enums import Side, PairType, OrderType
from ..enums import Side, PairType, OrderType, ExchangeType

req = TradeRequest(side=Side.BUY, instrument=Instrument(underlying=PairType.BTCUSD), order_type=OrderType.MARKET, volume=100.0, price=1.0)
req = TradeRequest(side=Side.BUY, instrument=Instrument(underlying=PairType.BTCUSD), order_type=OrderType.MARKET, volume=100.0, price=1.0, exchange=ExchangeType.COINBASE)
resp = self.risk.request(req)
resp = self.risk.requestBuy(req)

Expand All @@ -52,9 +52,9 @@ def test_request(self):

def test_request2(self):
from ..structs import TradeRequest, Instrument
from ..enums import Side, PairType, OrderType
from ..enums import Side, PairType, OrderType, ExchangeType

req = TradeRequest(side=Side.SELL, instrument=Instrument(underlying=PairType.BTCUSD), order_type=OrderType.MARKET, volume=50.0, price=1.0)
req = TradeRequest(side=Side.SELL, instrument=Instrument(underlying=PairType.BTCUSD), order_type=OrderType.MARKET, volume=50.0, price=1.0, exchange=ExchangeType.COINBASE)
resp = self.risk.request(req)
resp = self.risk.requestSell(req)

Expand Down
11 changes: 7 additions & 4 deletions aat/tests/test_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def test_to_dict(self):
assert x == {'type': InstrumentType.PAIR, 'underlying': PairType.BTCUSD}

x = i.to_dict(True)
assert x == {'type': 'InstrumentType.PAIR', 'underlying': 'BTCUSD'}
assert x == {'type': 'InstrumentType.PAIR', 'underlying': 'BTC/USD'}

x = i.to_dict(True, True)
assert x == {'type': 'InstrumentType.PAIR', 'underlying': 'BTCUSD'}
assert x == {'type': 'InstrumentType.PAIR', 'underlying': 'BTC/USD'}

def test_MarketData(self):
from ..structs import MarketData, Instrument
Expand All @@ -49,11 +49,12 @@ def test_MarketData(self):

def test_TradeRequest(self):
from ..structs import TradeRequest, Instrument
from ..enums import Side, OrderType, PairType
from ..enums import Side, OrderType, PairType, ExchangeType
t = TradeRequest(side=Side.BUY,
instrument=Instrument(underlying=PairType.BTCUSD),
order_type=OrderType.MARKET,
volume=1.0,
exchange=ExchangeType.COINBASE,
price=1.0)
assert t
# side = Side
Expand All @@ -66,9 +67,10 @@ def test_TradeRequest(self):

def test_TradeResponse(self):
from ..structs import TradeRequest, TradeResponse, TradeResult, Instrument
from ..enums import Side, OrderType, PairType
from ..enums import Side, OrderType, PairType, ExchangeType
req = TradeRequest(side=Side.BUY,
order_type=OrderType.MARKET,
exchange=ExchangeType.COINBASE,
instrument=Instrument(underlying=PairType.BTCUSD),
volume=1.0,
price=1.0)
Expand All @@ -78,6 +80,7 @@ def test_TradeResponse(self):
volume=0.0,
price=0.0,
status=TradeResult.FILLED,
exchange=ExchangeType.COINBASE,
order_id='1')
assert t
# side = Side
Expand Down
5 changes: 3 additions & 2 deletions aat/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,19 @@ def test_str_to_currency_pair_type(self):

def test_trade_req_to_params(self):
from ..utils import trade_req_to_params
from ..structs import TradeRequest, Instrument
from ..structs import TradeRequest, Instrument, ExchangeType
from ..enums import Side, OrderType, PairType

t = TradeRequest(side=Side.BUY,
volume=1.0,
price=1.0,
instrument=Instrument(underlying=PairType.BTCUSD),
exchange=ExchangeType.COINBASE,
order_type=OrderType.LIMIT)

ret = trade_req_to_params(t)

assert ret['symbol'] == 'BTCUSD'
assert ret['symbol'] == 'BTC/USD'
assert ret['side'] == 'buy'
assert ret['type'] == 'limit'
assert ret['amount'] == 1.0
Expand Down

0 comments on commit 4fcd5c0

Please sign in to comment.