Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order submission for single leg orders #85

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

orkhanM
Copy link

@orkhanM orkhanM commented Feb 21, 2025

Was getting strange errors and took a while to debug (error handling should probably expose the api response for easier debugability) some of the issues:

  • it seems like POST /accounts/{accountNumber}/orders returns a 201 response code to indicate success. (see doc)
  • the order quantity in the api request body has to be an integer (see docs).
  • the trailing comma in the LegTemplate was causing issues

I've changed:

  • the order submission to use sonic.Marshal (as it's used in other places in this codebase) instead of fmt.Sprintf .
  • the Quantity for SingleLegOrder to be an int to conform with the api spec
  • the struct to marshal correctly. I noted there are also other structs that don't seem to be fully implemented yet (currently in the works?) so I didn't modify them however if they're in-the-works then it'd make sense to have them follow the same pattern.
  • added 201 as an acceptable response code to agent.Handler

Here is the order submission request body before and after these updates:

Before:

{
  "orderType": "MARKET",
  "session": "NORMAL",
  "duration": "DAY",
  "orderStrategyType": "SINGLE",
  "orderLegCollection": [
    
{
  "instruction": "BUY",
  "quantity": 1.000000,
  "instrument": {
    "symbol": "AAPL",
    "assetType": "EQUITY"
  }
},

  ]
}

{"time":"2025-02-20T20:21:29.210308705-05:00","level":"ERROR","msg":"Failed to submit order","!BADKEY":"server is freaking out: server is freaking out"}

after:

{"orderType":"MARKET","session":"NORMAL","duration":"DAY","orderStrategyType":"SINGLE","orderLegCollection":[{"instruction":"BUY","quantity":1,"instrument":{"symbol":"GOOG","assetType":"EQUITY"}}]}
 
201

🍻

@samjtro
Copy link
Member

samjtro commented Mar 5, 2025

beauty! sorry it's been an insane last few weeks, got really sick and i've been swamped at work. will get this & the other pr merged in tonight.

really appreciate your great work here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants