After making a client object i.e. client = schwabdev.Client(...) we can place orders using the client.order_place(...) method.
Syntax:
client.order_place(account_hash, order)
Params:Return:
- account_hash(str): account hash to get place order on.
- order(dict): Order dict to place, there are examples in below and in the Schwab documentation.
(request.Response) Response object.
Note:
Get the order id by checking the headers.
order_id = resp.headers.get('location', '/').split('/')[-1]
If order is immediately filled then the id might not be returned
Syntax:
print(client.order_details(account_hash, order_id)
Params:Return:
- account_hash(str): account hash that order was placed on.
- order_id(int): order id to get details of.
(request.Response) Details of the order.
Syntax:
client.order_cancel(account_hash, order_id)
Params:Return:
- account_hash(str): account hash that order was placed on.
- order_id(int): order id to cancel.
(request.Response) Empty if successful.
Syntax:
client.order_replace(account_hash, orderID, order)
Params:Return:
- account_hash(str): account hash that order was placed on.
- orderID(int): order id to be replace.
- order(dict): Order dict to replace orderID with.
(request.Response) Empty if successful.
Please adjust for your usage.
order = {"orderType": "MARKET",
"session": "NORMAL",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "BUY",
"quantity": 10,
"instrument": {
"symbol": "AMD",
"assetType": "EQUITY"
}
}
]
}
order = {"orderType": "LIMIT",
"session": "NORMAL",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"price": '10.00',
"orderLegCollection": [
{"instruction": "BUY",
"quantity": 4,
"instrument": {
"symbol": "INTC",
"assetType": "EQUITY"
}
}
]
}
Symbol format: Underlying Symbol (6 chars including spaces) + Expiration (YYMMDD, 6 chars) + Call/Put (1 char) + Strike Price (5+3=8 chars)
order = {'orderType': 'LIMIT',
'session': 'NORMAL',
'price': 1.0,
'duration': 'GOOD_TILL_CANCEL',
'orderStrategyType': 'SINGLE',
'complexOrderStrategyType': 'NONE',
'orderLegCollection': [
{'instruction': 'SELL_TO_OPEN',
'quantity': 3,
'instrument': {'symbol': 'AAPL 240517P00190000',
'assetType': 'OPTION'
}
}
]
}
Symbol format: Underlying Symbol (6 chars including spaces) + Expiration (YYMMDD, 6 chars) + Call/Put (1 char) + Strike Price (5+3=8 chars)
order = {'orderType': 'LIMIT',
'session': 'NORMAL',
'price': 0.1,
'duration': 'GOOD_TILL_CANCEL',
'orderStrategyType': 'SINGLE',
'complexOrderStrategyType': 'NONE',
'orderLegCollection': [
{'instruction': 'BUY_TO_OPEN',
'quantity': 3,
'instrument': {'symbol': 'AAPL 240517P00190000',
'assetType': 'OPTION'
}
}
]
}
order = {
"orderType": "NET_DEBIT",
"session": "NORMAL",
"price": "0.10",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "BUY_TO_OPEN",
"quantity": 2,
"instrument": {
"symbol": "XYZ 240315P00045000",
"assetType": "OPTION"
}
},
{
"instruction": "SELL_TO_OPEN",
"quantity": 2,
"instrument": {
"symbol": "XYZ 240315P00043000",
"assetType": "OPTION"
}
}
]
}
order = {"orderType": "LIMIT",
"session": "NORMAL",
"price": "34.97",
"duration": "DAY",
"orderStrategyType": "TRIGGER",
"orderLegCollection": [
{
"instruction": "BUY",
"quantity": 10,
"instrument": {
"symbol": "XYZ",
"assetType": "EQUITY"
}
}
],
"childOrderStrategies": [
{
"orderType": "LIMIT",
"session": "NORMAL",
"price": "42.03",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 10,
"instrument": {
"symbol": "ABC",
"assetType": "EQUITY"
}
}
]
}
]
}
order = {"orderStrategyType": "OCO",
"childOrderStrategies": [
{
"orderType": "LIMIT",
"session": "NORMAL",
"price": "45.97",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 2,
"instrument": {
"symbol": "XYZ",
"assetType": "EQUITY"
}
}
]
},
{
"orderType": "STOP_LIMIT",
"session": "NORMAL",
"price": "37.00",
"stopPrice": "37.03",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 2,
"instrument": {
"symbol": "ABC",
"assetType": "EQUITY"
}
}
]
}
]
}
order = {"orderStrategyType": "TRIGGER",
"session": "NORMAL",
"duration": "DAY",
"orderType": "LIMIT",
"price": 14.97,
"orderLegCollection": [
{
"instruction": "BUY",
"quantity": 5,
"instrument": {
"assetType": "EQUITY",
"symbol": "XYZ"
}
}
],
"childOrderStrategies": [
{
"orderStrategyType": "OCO",
"childOrderStrategies": [
{
"orderStrategyType": "SINGLE",
"session": "NORMAL",
"duration": "GOOD_TILL_CANCEL",
"orderType": "LIMIT",
"price": 15.27,
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 5,
"instrument": {
"assetType": "EQUITY",
"symbol": "ABC"
}
}
]
},
{
"orderStrategyType": "SINGLE",
"session": "NORMAL",
"duration": "GOOD_TILL_CANCEL",
"orderType": "STOP",
"stopPrice": 11.27,
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 5,
"instrument": {
"assetType": "EQUITY",
"symbol": "IJK"
}
}
]
}
]
}
]
}
order = {"complexOrderStrategyType": "NONE",
"orderType": "TRAILING_STOP",
"session": "NORMAL",
"stopPriceLinkBasis": "BID",
"stopPriceLinkType": "VALUE",
"stopPriceOffset": 10,
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "SELL",
"quantity": 10,
"instrument": {
"symbol": "XYZ",
"assetType": "EQUITY"
}
}
]
}
order = {
"orderStrategyType": "SINGLE",
"orderType": "NET_CREDIT",
"price": price,
"orderLegCollection": [
{
"instruction": "SELL_TO_OPEN",
"quantity": quantity,
"instrument": {
"assetType": "OPTION",
"symbol": short_call_symbol
}
},
{
"instruction": "BUY_TO_OPEN",
"quantity": quantity,
"instrument": {
"assetType": "OPTION",
"symbol": long_call_symbol
}
},
{
"instruction": "SELL_TO_OPEN",
"quantity": quantity,
"instrument": {
"assetType": "OPTION",
"symbol": short_put_symbol
},
},
{
"instruction": "BUY_TO_OPEN",
"quantity": quantity,
"instrument": {
"assetType": "OPTION",
"symbol": long_put_symbol
},
}
],
"complexOrderStrategyType": "CUSTOM",
"duration": "DAY",
"session": "NORMAL"
}