forked from erdewit/ib_insync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest | ||
pytest-asyncio |
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,20 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
import ib_insync as ibi | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def event_loop(): | ||
loop = asyncio.get_event_loop() | ||
yield loop | ||
loop.close() | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
async def ib(): | ||
ib = ibi.IB() | ||
await ib.connectAsync() | ||
yield ib | ||
ib.disconnect() |
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,17 @@ | ||
import pytest | ||
|
||
import ib_insync as ibi | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_request_error_raised(ib): | ||
contract = ibi.Stock('MMM', 'SMART', 'USD') | ||
order = ibi.MarketOrder('BUY', 100) | ||
orderState = await ib.whatIfOrderAsync(contract, order) | ||
assert orderState.commission > 0 | ||
|
||
ib.RaiseRequestErrors = True | ||
badContract = ibi.Stock('XXX') | ||
with pytest.raises(ibi.RequestError) as exc_info: | ||
await ib.whatIfOrderAsync(badContract, order) | ||
assert exc_info.value.code == 321 |