The orders
module can be described as the most exciting module in wstrade-api
because you have the ability to:
- buy and sell securities (Market, Limit, and Stop limit all supported)
- cancel one or all pending orders
- View pending, cancelled, filled, or all orders
Note: All operations in orders
module require talking to Wealthsimple Trade endpoints. So make sure you are authenticated through the auth
module.
Collects orders (filled, pending, cancelled) for the provided page and account id. A page is a maximum of 20 orders.
page
must be>=1
. An empty list will be returned by orders.page
if the page exceeds the total number of pages.accountId
must be one returned by accounts.all
orders.page(accountId, page) -> Promise<any>
* This is not the full returned object - it has been cut.
{
total: 170,
orders: [
{
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
external_order_id: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
order_type: 'sell_quantity',
order_sub_type: 'market',
status: 'posted',
quantity: 7,
fill_quantity: 7,
symbol: 'AAPL',
security_name: 'Apple Inc',
...
},
19 more items...
]
}
See also: accounts.all
Collects all orders (filled, pending, cancelled) for the specific open account.
accountId
must be one returned by accounts.all
orders.all(accountId) -> Promise<any>
* This is not the full returned object - it has been cut.
{
total: 170,
orders: [
{
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
external_order_id: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
order_type: 'sell_quantity',
order_sub_type: 'market',
status: 'posted',
quantity: 7,
fill_quantity: 7,
symbol: 'AAPL',
security_name: 'Apple Inc',
...
},
70 more items...
]
}
See also: accounts.all
Retrieves pending orders for the specified security in the open account. If ticker
is provided, only pending orders that match the security are returned.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.
orders.pending(accountId, [ticker]) -> Promise<any>
* This is not the full returned object - it has been cut.
{
total: 3,
orders: [
{
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
external_order_id: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
order_type: 'sell_quantity',
order_sub_type: 'market',
status: 'submitted',
quantity: 7,
symbol: 'AAPL',
security_name: 'Apple Inc',
...
},
2 more items...
]
}
See also: accounts.all
Retrieves filled orders for the specified security in the open account. If ticker
is provided, only filled orders that match the security are returned.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.
orders.filled(accountId, [ticker]) -> Promise<any>
* This is not the full returned object - it has been cut.
{
total: 9,
orders: [
{
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
external_order_id: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
order_type: 'sell_quantity',
order_sub_type: 'market',
status: 'posted',
quantity: 7,
fill_quantity: 7,
symbol: 'AAPL',
security_name: 'Apple Inc',
...
},
8 more items...
]
}
See also: accounts.all
Retrieves cancelled orders for the specified security in the open account. If ticker
is provided, only cancelled orders that match the security are returned.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.
orders.cancelled(accountId, [ticker]) -> Promise<any>
* This is not the full returned object - it has been cut.
{
total: 2,
orders: [
{
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
external_order_id: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
order_type: 'sell_quantity',
order_sub_type: 'market',
status: 'cancelled',
quantity: 7,
symbol: 'AAPL',
security_name: 'Apple Inc',
...
},
1 more item...
]
}
See also: accounts.all
Cancels the pending order specified by the order id.
orderId
may be retrieved from orders.page
, orders.all
, orders.pending
, orders.filled
, or orders.cancelled
.
orders.cancel(orderId) -> Promise<any>
* This is not the full returned object - it has been cut.
{
order: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
response: {} // The API returns nothing.
}
See also: orders.page
, orders.all
, orders.pending
, orders.filled
, orders.cancelled
Cancels all pending orders under the open account specified by accountId
accountId
must be one returned by accounts.all
orders.cancelPending(accountId) -> Promise<any>
* This is not the full returned object - it has been cut.
[
// Cancelled Order 1
{
order: 'order-zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzz',
response: {} // The API returns nothing.
},
// Cancelled Order 2
{
order: 'order-yyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyy',
response: {} // The API returns nothing.
},
...
]
See also: accounts.all
Purchase a security with a market order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.quantity
is the number of shares you wish to purchase
orders.marketBuy(accountId, ticker, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the market buy
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all
Purchase a security with a limit order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.limit
is the highest price you are willing to pay for the securityquantity
is the number of shares you wish to purchase
orders.limitBuy(accountId, ticker, limit, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the limit buy
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all
Purchase a security with a stop limit order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.stop
is the price of the security at which the order converts to a limit orderlimit
is the highest price you are willing to pay for the securityquantity
is the number of shares you wish to purchase
orders.stopLimitBuy(accountId, ticker, stop, limit, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the stop limit buy
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all
Sell a security with a market order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.quantity
is the number of shares you wish to sell
orders.marketSell(accountId, ticker, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the market sell
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all
Sell a security with a limit order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.limit
is the lowest price you are willing to sell the security forquantity
is the number of shares you wish to sell
orders.limitSell(accountId, ticker, limit, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the limit sell
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all
Sell a security with a stop limit order.
accountId
must be one returned by accounts.all
ticker
is an identifier for a security. Read this document to learn how to construct a valid ticker.stop
is the price of the security at which the order converts to a limit orderlimit
is the lowest price you are willing to sell the security forquantity
is the number of shares you wish to sell
orders.stopLimitSell(accountId, ticker, stop, limit, quantity) -> Promise<any>
* This is not the full returned object - it has been cut.
{
// Confirmation and details of the stop limit sell
object: 'order',
created_at: '1970-01-01T13:42:52.422Z',
completed_at: null,
user_id: 00000,
account_id: 'tfsa-zzzzzzz',
...
}
See also: accounts.all