Jump to content


  • Content count

  • Joined

  • Last visited

  1. UpdateTrade

    Hello PM, First off, thanks so much for the prompt and clear replies. I really appreciate it! Yeah, as you pointed out, my systems could trade opposite directions, hedging/flatting my account position, while they each believe they are still in the market. Obviously I'm not making a lot of money when that's going on, but the systems do manage themselves and will close out what they think is their position at some point, always resulting in a true zero position in the platform. So I coded up a new workflow which I think solves most of my problems. When my platform submits an new order/trade via the REST APIs, it correlates the returned broker order ID to my platform's internal ID. I track those orders, including those which were last known as active. Any time I get an order update via the LS interface, I query the REST APIs for all active orders. I compare the new list of active orders vs my most recent list of active orders. Determine what's gone, whether or not it was because they were filled or cancelled, and forward the updates to my platform. I then also go through the active orders and make sure they are in the same state they were last time I tracked them. Any changes are forwarded to the platform. This seems to get past a lot of the issues. It's not pretty/ideal, but not dealing with a pretty/ideal situation (special thanks to my government!). What it doesn't solve is the opposite order sizing issue. AKA question #3 above, which you confirmed is the case. I'm left wondering if I should open a second trading account if I really want/need to go both directions as a US customer. I could set the platform to use account X for all systems attempting to long the market and account Y for all systems attempting to short the market. When running lots of systems together in the past, I have been put in the market both directions, sometimes with varying contract sizings, on the same forex pair. Trying to get ahead of that, even if the answer is there is simply no way to do it. That leaves me with question #4 ... can an individual have two accounts? Thanks!
  2. UpdateTrade

    PM, Thanks for the response. The US client rules make it quite difficult to code multiple algorithms to trade against the APIs. I'll take some solace in the fact that I'm seeing what's expected, I suppose The platform I've written runs many systems at the same time. This US client mechanic is problematic. If system X enters the market, then system Y enters the market, then system Y hits an exit condition, I'll see system X's orders get the fill notifications. I've been playing with some other angles of attack. The platform keeps records of all orders it places. My best thought at this point is to, any time I get an order update from LS, query the REST APIs for all active orders (including stops/limits). Compare what I know I've placed and was most recently active vs what I get back from the APIs. There's still room for error there, unfortunately. But it seems to be my best shot, from what I can tell. Question 1: Should there be any concerns with that that you know about? I have another question as well. I was testing out doing this in some fashion last night and came upon another mechanic that surprised me. Here's what I did: Placed a market buy for 1000 on the GBPUSD Placed a market buy for 1000 on the GBPUSD Placed a market buy for 1000 on the GBPUSD Placed a sell limit for 1500 on the GBPUSD I wanted to see if I'd get the first order's position fully closed + the second order's position half closed. I did confirm that through the web interface - when my sell limit triggered, the first buy closed completely and the second buy had half quantity remaining. What surprised me was that I didn't receive any notification on the first order being filled. When my sell limit triggered, my platform only received a notification of the second market buy having half of its position closed. There was nothing about the first order sent back to me at any point. Question 2: Is that expected? Even if, as a US client, I'm forced to move against my position by forex pair, it seems odd that I wouldn't get a notification when one of my orders gets closed. If this is expected, can you suggest how I should determine what I got filled at on the closed position I got no callback on? Is it safe to assume the fill price is exactly the same as the order I did get a callback on? Do I have to query a closed order API or something along those lines? Last question. If I do the same setup as above - put three market buy orders on for 1000 on the GBPUSD, it seems I can't then put on a market sell order against the GBPUSD for any position which does not fully close one or more of those original market buy orders. In other words, I can't put a market sell order on the GBPUSD for 1500 or 2250 or 750. I can only put it on for 1000, 2000, or 3000. Question 3: Can you confirm this is expected? This one seems particularly nasty in that if I have multiple systems running on my platform and one decides to short a given market while others are currently long - something which would not at all be unexpected with algorithmic trading - I could face rejections which interrupt trading. Sorry for all the questions. I've never faced so many oddities when integrating with a broker before. I understand it's my account limitations, being a US citizen, and not your platform. Just trying to figure them all out. I'm really being thrown for a loop! Thanks!
  3. UpdateTrade

    Hello, I'm having a hard time achieving what I'd like to do. First off, although it doesn't matter most likely: I'm writing in Python. Using the REST APIs for creating orders, capturing status from the orders feed with LS. US customer. I'm performing the operations below via a python script. I'm placing all of these orders against the GBP/USD FOREX pair. I put buy trade A on for quantity X. I put buy trade B on for quantity X. I put a stop order on, referencing trade B's order ID, for quantity X. When I look at my response on putting that stop order on, however, is that the stop order's quantity is actually 2X. I look at the web interface for my account for confirmation. I see both of my trades as separate positions, each with their own order ID. I see both of them have a stop order attached to them. The web interface confirms what I see coming out of my script. For some actual data ... when I ran my script just now, I got back order ID 716173586 for the first trade, order ID 716173589 for the second trade. The script then submitted the following parameters to the update trade API (I x'd out my trading ID for the post here; it's a valid ID when I actually submit it to the API): {'OrderId': 716173589, 'MarketId': 401484392, 'Currency': None, 'AutoRollover': False, 'Direction': 'buy', 'Quantity': 1000, 'QuoteId': None, 'PositionMethodId': 1, 'AuditId': None, 'TradingAccountId': xxx, 'IfDone': [{'Stop': {'Direction': 'sell', 'Applicability': 'gtc', 'Guaranteed': False, 'Quantity': 1000, 'TriggerPrice': 1.27393}}], 'Close': [], 'Reference': 'GCAPI', 'AllocationProfileId': None, 'OrderReference': None, 'Source': None} It got back the following response: {'Status': 1, 'StatusReason': 1, 'OrderId': 716173589, 'Orders': [{'OrderId': 716173589, 'StatusReason': 1, 'Status': 3, 'OrderTypeId': 1, 'Price': 1.27593, 'Quantity': 1000.0, 'TriggerPrice': 0.0, 'CommissionCharge': 0.0, 'IfDone': [], 'GuaranteedPremium': 0.0, 'OCO': None, 'AssociatedOrders': {'Stop': None, 'Limit': None}, 'Associated': False}, {'OrderId': 716173590, 'StatusReason': 1, 'Status': 2, 'OrderTypeId': 2, 'Price': 0.0, 'Quantity': 2000.0, 'TriggerPrice': 1.27393, 'CommissionCharge': 0.0, 'IfDone': [], 'GuaranteedPremium': 0.0, 'OCO': None, 'AssociatedOrders': {'Stop': None, 'Limit': None}, 'Associated': False}], 'Quote': None, 'Actions': [], 'ErrorMessage': None} From what I can tell, the response is telling me I successfully altered order ID 716173589 (which is my second trade). In the orders section, I can see information on my second trade and information on my new stop order. The trade information looks right, although has no IfDone curiously. The stop order has an order ID and target which looks correct but it's quantity is not what I asked for. Instead, it is enough to cover my total position in the market on the GBPUSD pair. I also tried running the script with putting on three trades, then the stop against the third trade. The stop ends up having 3X quantity when I do this. Is it possible for me to attach a stop to just a single trade by its order ID? From what I can tell, I can only attach the stop to all open positions against a given FOREX pair. Please help! Thanks in advance.