SPREADBET vs CFD orders

3 posts / 0 new
Last post
JK1
SPREADBET vs CFD orders

I am struggling to get the basics of placing an order using my SPREADBET demo account. It works fine with the CFD account. I am then able to switch to the SPREADBET account successfully. I change the epic appropriately, and leave everything else the same. I receive a reject due to "REJECT_CFD_ORDER_ON_SPREADBET_ACCOUNT". I.e. despite changing the epic, the API still thinks I'm placing a CFD order.

Any tips for what to change in the order parameters?

(The API companion accepts the SPREADBET order after changing only the epic (after changing the account type)).

Python code and output below:

from trading_ig import IGService

ig_service = IGService(
username, password, api_key, acc_type
)

def switch_accounts(ig_service, target):
accounts = ig_service.fetch_accounts()
target_id = accounts.loc[accounts['accountType']==target]['accountId']
pref = accounts.loc[accounts['accountType']==target]['preferred']
if not pref.iloc[0]:
account_info = ig_service.switch_account(target_id.iloc[0], True, None)

def buy_one(target):
if target == "SPREADBET":
epic = "CS.D.EURUSD.TODAY.IP"
elif target == "CFD":
epic = 'CS.D.EURUSD.CFD.IP'
else:
print("Invalid account type")
return
currency_code="USD"
direction="BUY"
expiry="-"
force_open=False
guaranteed_stop=False
level=None
limit_distance=None
limit_level=None
order_type="MARKET"
quote_id=None
size="1"
stop_distance=None
stop_level=None
session=None
response = ig_service.create_open_position(currency_code, direction, epic, expiry,
force_open, guaranteed_stop, level,
limit_distance,limit_level, order_type,
quote_id, size, stop_distance, stop_level,
None)
print(response)

ig_service.create_session()
switch_accounts(ig_service, 'CFD')
accounts = ig_service.fetch_accounts()
print("accounts:\n%s" % accounts)
buy_one("CFD")
switch_accounts(ig_service, 'SPREADBET')
accounts = ig_service.fetch_accounts()
print("accounts:\n%s" % accounts)
buy_one("SPREADBET")

Output:

accounts:
accountAlias accountId accountName accountType canTransferFrom \
0 None XX CFD CFD True
1 None XX Spread bet SPREADBET True

canTransferTo currency preferred status available balance deposit \
0 True GBP True ENABLED 7046.12 9971.88 2914.16
1 True GBP False ENABLED 10000.00 10000.00 0.00

profitLoss
0 -11.6
1 0.0
{'date': '2019-02-18T23:12:28.808', 'status': 'OPEN', 'reason': 'SUCCESS', 'dealStatus': 'ACCEPTED', 'epic': 'CS.D.EURUSD.CFD.IP', 'expiry': '-', 'dealReference': '3DXR2FXJMXUL4TE', 'dealId': 'DIAAAACHVLLZNA5', 'affectedDeals': [{'dealId': 'DIAAAACHVLLZNA5', 'status': 'OPENED'}], 'level': 1.13125, 'size': 1.0, 'direction': 'BUY', 'stopLevel': None, 'limitLevel': None, 'stopDistance': None, 'limitDistance': None, 'guaranteedStop': False, 'trailingStop': False, 'profit': None, 'profitCurrency': None}
accounts:
accountAlias accountId accountName accountType canTransferFrom \
0 None XX CFD CFD True
1 None XX Spread bet SPREADBET True

canTransferTo currency preferred status available balance deposit \
0 True GBP False ENABLED 4120.3 9971.88 5828.37
1 True GBP True ENABLED 10000.0 10000.00 0.00

profitLoss
0 -23.21
1 0.00
{'date': '2019-02-18T23:12:29.566', 'status': None, 'reason': 'REJECT_CFD_ORDER_ON_SPREADBET_ACCOUNT', 'dealStatus': 'REJECTED', 'epic': 'CS.D.EURUSD.TODAY.IP', 'expiry': None, 'dealReference': 'DYENMURNM8TL4TE', 'dealId': 'DIAAAACHVMTNCAV', 'affectedDeals': [], 'level': None, 'size': None, 'direction': 'BUY', 'stopLevel': None, 'limitLevel': None, 'stopDistance': None, 'limitDistance': None, 'guaranteedStop': False, 'trailingStop': False, 'profit': None, 'profitCurrency': None}

JK1
Figured it out.

As per the IG help desk, as well as changing the epic for the spreadbet position, you also need to change the expiry. This should be "DFB" for the spreadbet, and "-" for the CFD.

So this code now works for submitting a CFD order and then a spreadbet order:

config = Config_demo()
from trading_ig import IGService
ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)

def switch_accounts(ig_service, target):
accounts = ig_service.fetch_accounts()
target_id = accounts.loc[accounts['accountType']==target]['accountId']
pref = accounts.loc[accounts['accountType']==target]['preferred']
if not pref.iloc[0]:
account_info = ig_service.switch_account(target_id.iloc[0], True, None)

def buy_one(target):
if target == "SPREADBET":
epic = "CS.D.EURUSD.TODAY.IP"
expiry="DFB"
currency_code="GBP"
elif target == "CFD":
epic = 'CS.D.EURUSD.CFD.IP'
expiry="-"
currency_code="USD"
direction="BUY"
force_open=False
guaranteed_stop=False
level=None
limit_distance=None
limit_level=None
order_type="MARKET"
quote_id=None
size="1"
stop_distance=None
stop_level=None
session=None
response = ig_service.create_open_position(currency_code, direction, epic, expiry,
force_open, guaranteed_stop, level,
limit_distance,limit_level, order_type,
quote_id, size, stop_distance, stop_level,
None)
print(response)

ig_service.create_session()
account_types = ['CFD','SPREADBET']
for account_type in account_types:
switch_accounts(ig_service, account_type)
accounts = ig_service.fetch_accounts()
print("accounts:\n%s" % accounts)
buy_one(account_type)

JK1
The API Companion accepted my

The API Companion accepted my SPREADBET order with the expiry set to "-" (the CFD setting), which I would say is a bug, as the API won't accept that parameter.

Log in or register to post comments