buy

Generates a new buy order

(buy {asset} shares options?)

Description

The buy function generates a buy order for a specified symbol and number of units. It returns an order object containing information about the buy action. The function also supports additional options to control order generation based on existing open positions.

Returns

The buy function returns an order object containing information about the buy action. If the order is not generated due to existing open positions, it may return null

Parameters

{asset} (asset) - asset to be bought

shares (number) - the number of units (shares, contracts, etc.) to be bought.

options (optional, object) - target: checks openPositions and generates order to balance portfolio

Examples

(buy {AAPL} 1)            ;; buys one share of AAPL
;;=> order {symbol: "AAPL", action: "buy", units: 1, ....}

;; openPositions = [{symbol: "AAPL", side: "long", units: 1}]
(buy {AAPL} 1 {target: true})
;; will not generate a order because openPositions allready has
;; 1 share of AAPL long

Was this helpful?