-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Trader livemocking. * Add test and validation of tradetype input. * Move MockExchange separately.
- Loading branch information
Showing
7 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ccxt | ||
|
||
|
||
class MockOrder(dict): | ||
def __str__(self): | ||
return f"mocked order: {self.get('amount')} {self['pair_str']}" | ||
|
||
|
||
class MockExchange(ccxt.Exchange): | ||
def create_market_buy_order(self, pair_str, amount): | ||
return MockOrder( | ||
{ | ||
"order_type": "buy", | ||
"amount": str(amount), | ||
"pair_str": pair_str, | ||
} | ||
) | ||
|
||
def create_market_sell_order(self, pair_str, position_size): | ||
return MockOrder( | ||
{ | ||
"order_type": "sell", | ||
"position_size": str(position_size), | ||
"pair_str": pair_str, | ||
} | ||
) | ||
|
||
def __str__(self): | ||
return "mocked exchange" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import ccxt | ||
|
||
from pdr_backend.util.mocks import MockExchange, MockOrder | ||
|
||
|
||
def test_mock_order(): | ||
mock_order = MockOrder( | ||
{ | ||
"order_type": "buy", | ||
"amount": "0.1", | ||
"pair_str": "BTC/USDT", | ||
} | ||
) | ||
assert str(mock_order) == "mocked order: 0.1 BTC/USDT" | ||
assert isinstance(mock_order, dict) | ||
|
||
|
||
def test_mock_exchange(): | ||
mock_exchange = MockExchange() | ||
assert str(mock_exchange) == "mocked exchange" | ||
assert isinstance(mock_exchange, ccxt.Exchange) | ||
assert isinstance(mock_exchange.create_market_buy_order("BTC/USDT", 0.1), MockOrder) | ||
assert isinstance( | ||
mock_exchange.create_market_sell_order("BTC/USDT", 0.1), MockOrder | ||
) |