Skip to content

Commit 15877c6

Browse files
Merge pull request #230 from bug-or-feature/guaranteed_stoploss_fix
Guaranteed stop loss fix
2 parents 212ffba + e2e2fb3 commit 15877c6

8 files changed

Lines changed: 59 additions & 137 deletions

File tree

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/source/faq.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ If you're sure that the problem is with this library, please:
251251
An issue without all this information may be ignored and/or closed without response
252252

253253

254-
Why are there both ``setup.py`` and ``pyproject.toml`` files?
254+
What happened to ``setup.py`` and ``requirements.txt``?
255255
-------------------------------------------------------------
256-
Early versions of this project used the standard ``setup.py`` config. `Poetry <https://python-poetry.org/>`_
257-
support was added with version 0.0.10 (July 2021). The old style config will remain during transition, but be
258-
removed in a future release
256+
Early versions of this project used the standard ``setup.py`` config, with a ``requirements.txt`` file describing
257+
dependencies. `Poetry <https://python-poetry.org/>`_
258+
support was added with version 0.0.10 (July 2021). The old style config was removed with version 0.0.14
259259

260260

261261
Why is ``pandas`` an optional dependency in ``pyproject.toml``?

requirements-test.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 102 deletions
This file was deleted.

tests/test_integration.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,59 @@ def test_create_working_order(self, ig_service: IGService):
500500
assert delete_result['dealStatus'] == 'ACCEPTED'
501501
assert delete_result['reason'] == 'SUCCESS'
502502

503+
def test_create_working_order_guaranteed_stop_loss(self, ig_service: IGService):
504+
505+
epic = 'CS.D.GBPUSD.TODAY.IP'
506+
market_info = ig_service.fetch_market_by_epic(epic)
507+
status = market_info.snapshot.marketStatus
508+
min_bet = market_info.dealingRules.minDealSize.value
509+
offer = market_info.snapshot.offer
510+
bid = market_info.snapshot.bid
511+
512+
logging.info(f"min bet: {min_bet}")
513+
logging.info(f"offer: {offer}")
514+
logging.info(f"bid: {bid}")
515+
516+
if status != 'TRADEABLE':
517+
pytest.skip('Skipping create working order test, market not open')
518+
519+
create_result = ig_service.create_working_order(
520+
epic=epic, direction='BUY', currency_code='GBP', order_type='LIMIT', expiry='DFB', guaranteed_stop='true',
521+
time_in_force='GOOD_TILL_CANCELLED', size=min_bet, level=offer * 0.90, limit_level=None,
522+
limit_distance=None, stop_distance=200, stop_level=None)
523+
524+
logging.info(f"result: {create_result['dealStatus']}, reason {create_result['reason']}")
525+
526+
assert create_result['dealStatus'] == 'ACCEPTED'
527+
assert create_result['reason'] == 'SUCCESS'
528+
assert create_result['guaranteedStop']
529+
530+
time.sleep(10)
531+
532+
update_result = ig_service.update_working_order(
533+
good_till_date=None,
534+
level=offer * 0.85,
535+
limit_distance=None,
536+
limit_level=None,
537+
stop_distance=None,
538+
stop_level=offer * 0.80,
539+
guaranteed_stop='true',
540+
time_in_force='GOOD_TILL_CANCELLED',
541+
order_type='LIMIT',
542+
deal_id=create_result['dealId'])
543+
544+
logging.info(f"result: {update_result['dealStatus']}, reason {update_result['reason']}")
545+
546+
assert update_result['dealStatus'] == 'ACCEPTED'
547+
assert update_result['reason'] == 'SUCCESS'
548+
assert update_result['guaranteedStop']
549+
550+
time.sleep(10)
551+
552+
delete_result = ig_service.delete_working_order(create_result['dealId'])
553+
assert delete_result['dealStatus'] == 'ACCEPTED'
554+
assert delete_result['reason'] == 'SUCCESS'
555+
503556
def test_fetch_transaction_history(self, ig_service: IGService):
504557
data = ig_service.fetch_transaction_history()
505558
assert type(data) is pd.DataFrame

trading_ig/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@ def update_working_order(
10481048
limit_level,
10491049
stop_distance,
10501050
stop_level,
1051+
guaranteed_stop,
10511052
time_in_force,
10521053
order_type,
10531054
deal_id,
@@ -1064,6 +1065,7 @@ def update_working_order(
10641065
"limitLevel": limit_level,
10651066
"stopDistance": stop_distance,
10661067
"stopLevel": stop_level,
1068+
"guaranteedStop": guaranteed_stop,
10671069
"timeInForce": time_in_force,
10681070
"type": order_type,
10691071
}

0 commit comments

Comments
 (0)