Jump to content
  • 0

Unknown error when placing order on the demo API


stonkyboy

Question

Hello! I've been lurking in the community for a little while and recieved a lot of tips & tricks so thanks to all who have helped me get this far through my project. 

I've built my 1st trading bot in python and i'm trying to test it using the demo API. I've had no issues using most of the endpoints (fetch markets, get open orders, get open positions, etc) but for some reason most of my 'create new position' requests are failing witout explaination. The strange thing is when I try to open positions using the same parameters and same demo credentials on the API companion it succeedes and gives me a deal reference.

About 20% of my open position requests either succeed or return a sensible error like 'MINIMUM_SIZE_ORDER' or 'MARKET_CLOSED_WITH_EDITS' so I think my headers are fine.

I'm wondering if anyone has had a similar issue when trying to work with the demo api? 

Here's what i'm recieving after I try to open a position: 

"Order Failed: {'date': '2020-06-11T14:00:47.022', 'status': None, 'reason': 'UNKNOWN', 'dealStatus': 'REJECTED', 'epic': 'SB.D.EBSUS.DAILY.IP', 'expiry': None, 'dealReference': 'V5NMJXCZUFF44TE', 'dealId': 'DIAAAADW5TZM8BA', 'affectedDeals': [], 'level': None, 'size': None, 'direction': 'BUY', 'stopLevel': None, 'limitLevel': None, 'stopDistance': None, 'limitDistance': None, 'guaranteedStop': False, 'trailingStop': False, 'profit': None, 'profitCurrency': None}"

Here's the python code that i'm using to open a position: 

Connect to API:

data = {"identifier": DEMO_USERNAME, "password": DEMO_PASSWORD, "encryptedPassword":None}

headers = {'Content-Type': 'application/json; charset=utf-8',
           'Accept': 'application/json; charset=utf-8',
           'X-IG-API-KEY': API_KEY,
           'Version': '2'
           }

r = requests.post(API_ENDPOINT, data=json.dumps(data), headers=headers)

headers_json = dict(r.headers)
CST_token = headers_json['CST']
x_sec_token = headers_json["X-SECURITY-TOKEN"]


authenticated_headers = {'Content-Type': 'application/json; charset=utf-8',
                         'Accept': 'application/json; charset=utf-8',
                         'X-IG-API-KEY': API_KEY,
                         'CST': CST_token,
                         'X-SECURITY-TOKEN': x_sec_token}

auth_r = requests.get(base_url, headers=authenticated_headers)
d = json.loads(auth_r.text)

base_url = 'https://demo-api.ig.com/gateway/deal/session'

data = {
    "accountId": DEMO_ACC_ID,
    "defaultAccount": "True"}  # Main Demo acc

auth_r = requests.put(
    base_url,
    data=json.dumps(data),
    headers=authenticated_headers)

Open Position: 

base_url = 'https://demo-api.ig.com/gateway/deal/positions/otc'

data = {
    "epic": "UB.D.INTC.DAILY.IP",
    "expiry": "DFB",
    "direction": "BUY",
    "size": "1.144",
    "orderType": "MARKET",
    "level": None,
    "guaranteedStop": "false",
    "stopLevel": None,
    "stopDistance": "1748",
    "forceOpen": "true",
    "limitLevel": None,
    "limitDistance": None,
    "quoteId": None,
    "currencyCode": "USD"
}

r = requests.post(base_url,data=json.dumps(data),headers=authenticated_headers)

Any help in solving this issue would be greatly appreciated! 

Cheers. 

  • Great! 1
Link to comment

1 answer to this question

Recommended Posts

  • 0

The problem was that I was specifying a size with three decimal places... but the limit is two. Think this limit holds with every number you can provide to the API. Would be good if the tech team could explain that in the API response. 

  • Like 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • Hi guys, happy weekend! Cats TGE is getting closer, and a lot of exchanges have rolled out opportunities for users to make the most of it, especially for those who didn’t farm. I’ll be focusing on Bitget Launch Pool since I just locked some BGB.   Here’s the deal: for those who didn’t meet the requirements for the official airdrop, you can still participate in the ongoing launch pool. You can stake BGB or USDT and earn some CATS. The last time I checked, the APR was in triple digits, and the pool ends in about 6 days.   Personally, I think this is a great opportunity to get involved in the Cats ecosystem. What do you think?
    • This gives more opportunity to users to earn more from this launchpool. 
    • Hey I wanted to share my excitement about the upcoming $CATS airdrop and the Bitget Launchpool event. If you're into crypto like me, you won't want to miss this! $CATS Airdrop Claiming First off, the $CATS airdrop is happening soon, and it's super easy to claim. Exchange like Bitget have partnered with Cats to offer a gas-free airdrop on Telegram. This means you can claim your tokens without worrying about those pesky gas fees! The tokens will be automatically credited to your account before the spot trading begins on October 8th, 2024, at 10:00 UTC. But that's not all! The ongoing Launchpool This is a fantastic opportunity to farm some extra tokens. The total distribution for this event is a whopping 19.5 billion $CATS tokens. If you've participated in Launchpool events before, you know how user-friendly and rewarding they can be. Why I'm Excited As someone who has been using the exchange for a while, I appreciate their transparency and the ease of use of their platform. The fact that they are making the airdrop gas-free is a huge plus. Plus, the Launchpool events are always a great way to earn some extra tokens with minimal effort. If you're as excited as I am, make sure to mark your calendars for these dates. Happy farming and trading, everyone!
×
×
  • Create New...
us