Petersoj / alpaca-java

A Java API for Alpaca, the commission free, algo friendly, stock trading broker. https://alpaca.markets
https://petersoj.github.io/alpaca-java/
MIT License
198 stars 84 forks source link

Support for "held" OrderStatus #101

Closed zhemaituk closed 3 years ago

zhemaituk commented 3 years ago

Even though Alpaca documentation does not even mention status "held" ( https://alpaca.markets/docs/trading-on-alpaca/orders/#order-lifecycle )

It still happens on practice for bracket (e.g. OTO) orders: https://forum.alpaca.markets/t/half-of-bracket-order-held/2727

Currently alpaca-java maps held to null in OrderStatus. It would be more predictable to have own OrderStatus.HELD value.

Sample request body after alpacaAPI.orders().requestOrder: at 2021-07-14T09:57:52.760-04:00:

{
    "symbol": "ALXN",
    "side": "buy",
    "type": "market",
    "time_in_force": "day",
    "qty": "351.0",
    "order_class": "oto",
    "stop_loss": {
        "stop_price": 185.19
    }
}

Sample response from Alpaca after alpacaAPI.orders().get(id, false): at 2021-07-14T09:57:52.822-04:00:

{
    "id": "b27014fb-9ee7-4d63-a9d2-535347ecceaa",
    "client_order_id": "1e6a038e-8d7e-43d0-907c-a676db5206ef",
    "created_at": "2021-07-14T13:57:52.805404Z",
    "updated_at": "2021-07-14T13:57:52.812205Z",
    "submitted_at": "2021-07-14T13:57:52.79776Z",
    "filled_at": null,
    "expired_at": null,
    "canceled_at": null,
    "failed_at": null,
    "replaced_at": null,
    "replaced_by": null,
    "replaces": null,
    "asset_id": "1855127e-54da-4909-929a-83c316ba4b89",
    "symbol": "ALXN",
    "asset_class": "us_equity",
    "notional": null,
    "qty": "351",
    "filled_qty": "0",
    "filled_avg_price": null,
    "order_class": "oto",
    "order_type": "market",
    "type": "market",
    "side": "buy",
    "time_in_force": "day",
    "limit_price": null,
    "stop_price": null,
    "status": "accepted",
    "extended_hours": false,
    "legs": [
        {
            "id": "916fba91-67c4-4948-8b4c-702611048d75",
            "client_order_id": "d003ad83-0073-441d-b4b0-4e7e8c705564",
            "created_at": "2021-07-14T13:57:52.805404Z",
            "updated_at": "2021-07-14T13:57:52.805404Z",
            "submitted_at": "2021-07-14T13:57:52.79776Z",
            "filled_at": null,
            "expired_at": null,
            "canceled_at": null,
            "failed_at": null,
            "replaced_at": null,
            "replaced_by": null,
            "replaces": null,
            "asset_id": "1855127e-54da-4909-929a-83c316ba4b89",
            "symbol": "ALXN",
            "asset_class": "us_equity",
            "notional": null,
            "qty": "351",
            "filled_qty": "0",
            "filled_avg_price": null,
            "order_class": "oto",
            "order_type": "stop",
            "type": "stop",
            "side": "sell",
            "time_in_force": "day",
            "limit_price": null,
            "stop_price": "185.19",
            "status": "held",
            "extended_hours": false,
            "legs": null,
            "trail_percent": null,
            "trail_price": null,
            "hwm": null
        }
    ],
    "trail_percent": null,
    "trail_price": null,
    "hwm": null
}
Petersoj commented 3 years ago

Sounds good. I'll add that order status in this next patch release.

Petersoj commented 3 years ago

Fixed in 3872b97f1414a9275b5aeefdf39a70efdfbff70f