Interactive Brokers API
Racket implementation for the Interactive Brokers’ Trader Workstation Client API.
This implementation is based on the Java TWS API version 972.18. The protocol used to communicate between the client and server establishes the client version and should allow the server to continue consuming and producing messages compatible with our version even when the server is updated. However, when there are desirable new features added, this library may be updated and its version number updated to reflect the version of the TWS API the new code uses.
The overall design of this library is to use objects to represent the connection and request messages and to use structs to represent response messages. Using objects for the connection and request messages seemed to make the process of creation easier as there are many fields that are often not cared about and can be omitted. We also use an interface and a base class for request messages. For response message, we stick to structs as we don’t care about inheritance, nor do we need an ease-of-use creation method as the library creates the fully-filled-in instances. This is maybe a weird design.
1 Establishing a connection
(require interactive-brokers-api) | |
package: interactive-brokers-api |
The general code flow to establish a (default) connection and send a message is as follows:
(define ibkr (new ibkr-session%)) (send ibkr connect) ; The connection should be established after call to connect ; Doing the below may be useful for testing (require interactive-brokers-api/request-messages) (send ibkr send-msg (new executions-req%))
constructor
(new ibkr-session% [ [client-id client-id] [handle-accounts-rsp handle-accounts-rsp] [handle-contract-details-rsp handle-contract-details-rsp] [handle-err-rsp handle-err-rsp] [handle-execution-rsp handle-execution-rsp] [handle-next-valid-id-rsp handle-next-valid-id-rsp] [handle-open-order-rsp handle-open-order-rsp] [handle-server-time-rsp handle-server-time-rsp] [hostname hostname] [port-no port-no] [write-messages write-messages]]) → (is-a?/c ibkr-session%) client-id : integer? = 0 handle-accounts-rsp : (-> (listof string?) any) = (λ (a) void)
handle-contract-details-rsp : (-> contract-details-rsp? any) = (λ (a) void) handle-err-rsp : (-> err-rsp? any) = (λ (a) void) handle-execution-rsp : (-> execution-rsp? any) = (λ (a) void)
handle-next-valid-id-rsp : (-> next-valid-id-rsp? any) = (λ (a) void)
handle-open-order-rsp : (-> open-order-rsp? any) = (λ (a) void) handle-server-time-rsp : (-> moment? any) = (λ (a) void) hostname : string? = "127.0.0.1" port-no : port-number? = 7497 write-messages : boolean? = #f On construction, we attempt to connect to the TWS server from the specified hostname and port-no. Encryption is not used currently; this library is not recommended to be used over an unsecure network.All response handlers will execute in the same, separate thread from the thread that constructs ibkr-session%.
The write-messages field, when set to #t, will write both request and response messages to the current-output-port.
When called, a thread is created to read from the socket and call the appropriate response handler with the received message. Currently, this thread will die when the connection is interruped. When this happens, I just create a new ibkr-session% to connect again rather than attempt to call connect on the existing session.
method
msg : (is-a?/c req-msg<%>) Sends a message over the established session. See the request-messages section for information on available request messages.
2 Request messages
(require interactive-brokers-api/request-messages) | |
package: interactive-brokers-api |
2.1 Base interface and class
|
2.2 Contract Details
| ||
superclass: ibkr-msg% | ||
|
(send ibkr send-msg (new contract-details-req% [symbol "AAPL"] [security-type 'opt] [strike 200.0]))
constructor
(new contract-details-req% [ [request-id request-id] [contract-id contract-id] [symbol symbol] [security-type security-type] [expiry expiry] [strike strike] [right right] [multiplier multiplier] [exchange exchange] [primary-exchange primary-exchange] [currency currency] [local-symbol local-symbol] [trading-class trading-class] [security-id-type security-id-type] [security-id security-id]]) → (is-a?/c contract-details-req%) request-id : integer? = 0 contract-id : integer? = 0 symbol : string? = ""
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) = #f expiry : (or/c date? #f) = #f strike : rational? = 0 right : (or/c 'call 'put #f) = #f multiplier : (or/c rational? #f) = #f exchange : string? = "" primary-exchange : string? = "" currency : string? = "" local-symbol : string? = "" trading-class : string? = "" security-id-type : (or/c 'cusip 'sedol 'isin 'ric #f) = #f security-id : string? = ""
2.3 Executions (otherwise known as trades)
| ||
superclass: ibkr-msg% | ||
|
(send ibkr send-msg (new executions-req%))
constructor
(new executions-req% [ [request-id request-id] [client-id client-id] [account account] [timestamp timestamp] [symbol symbol] [security-type security-type] [exchange exchange] [side side]]) → (is-a?/c executions-req%) request-id : integer? = 0 client-id : integer? = 0 account : string? = "" timestamp : (or/c moment? #f) = #f symbol : string? = ""
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) = #f exchange : string? = "" side : (or/c 'buy 'sell 'sshort #f) = #f
2.4 Orders
| ||
superclass: ibkr-msg% | ||
|
constructor
| ||
superclass: ibkr-msg% | ||
|
(send ibkr send-msg (new place-order-req% [symbol "AAPL"] [security-type 'stk] [exchange "SMART"] [currency "USD"] [action 'buy] [total-quantity 100] [limit-price 200.0]))
constructor
(new place-order-req% [ [order-id order-id] [contract-id contract-id] [symbol symbol] [security-type security-type] [expiry expiry] [strike strike] [right right] [multiplier multiplier] [exchange exchange] [primary-exchange primary-exchange] [currency currency] [local-symbol local-symbol] [trading-class trading-class] [security-id-type security-id-type] [security-id security-id] [action action] [total-quantity total-quantity] [order-type order-type] [limit-price limit-price] [aux-price aux-price] [time-in-force time-in-force] [oca-group oca-group] [account account] [open-close open-close] [origin origin] [order-ref order-ref] [transmit transmit] [parent-id parent-id] [block-order block-order] [sweep-to-fill sweep-to-fill] [display-size display-size] [trigger-method trigger-method] [outside-rth outside-rth] [hidden hidden] [combo-legs combo-legs] [order-combo-legs order-combo-legs] [smart-combo-routing-params smart-combo-routing-params] [discretionary-amount discretionary-amount] [good-after-time good-after-time] [good-till-date good-till-date] [advisor-group advisor-group] [advisor-method advisor-method] [advisor-percentage advisor-percentage] [advisor-profile advisor-profile] [model-code model-code] [short-sale-slot short-sale-slot] [designated-location designated-location] [exempt-code exempt-code] [oca-type oca-type] [rule-80-a rule-80-a] [settling-firm settling-firm] [all-or-none all-or-none] [minimum-quantity minimum-quantity] [percent-offset percent-offset] [electronic-trade-only electronic-trade-only] [firm-quote-only firm-quote-only] [nbbo-price-cap nbbo-price-cap] [auction-strategy auction-strategy] [starting-price starting-price] [stock-ref-price stock-ref-price] [delta delta] [stock-range-lower stock-range-lower] [stock-range-upper stock-range-upper] [override-percentage-constraints override-percentage-constraints] [volatility volatility] [volatility-type volatility-type] [delta-neutral-order-type delta-neutral-order-type] [delta-neutral-aux-price delta-neutral-aux-price] [continuous-update continuous-update] [reference-price-type reference-price-type] [trailing-stop-price trailing-stop-price] [trailing-percent trailing-percent] [scale-init-level-size scale-init-level-size] [scale-subs-level-size scale-subs-level-size] [scale-price-increment scale-price-increment] [scale-price-adjust-value scale-price-adjust-value] [scale-price-adjust-interval scale-price-adjust-interval] [scale-profit-offset scale-profit-offset] [scale-auto-reset scale-auto-reset] [scale-init-position scale-init-position] [scale-init-fill-quantity scale-init-fill-quantity] [scale-random-percent scale-random-percent] [scale-table scale-table] [active-start-time active-start-time] [active-stop-time active-stop-time] [hedge-type hedge-type] [hedge-param hedge-param] [opt-out-smart-routing opt-out-smart-routing] [clearing-account clearing-account] [clearing-intent clearing-intent] [not-held not-held] [delta-neutral-contract-id delta-neutral-contract-id] [delta-neutral-delta delta-neutral-delta] [delta-neutral-price delta-neutral-price] [algo-strategy algo-strategy] [algo-id algo-id] [what-if what-if] [order-misc-options order-misc-options] [solicited solicited] [randomize-size randomize-size] [randomize-price randomize-price] [reference-contract-id reference-contract-id] [is-pegged-change-amount-decrease is-pegged-change-amount-decrease] [pegged-change-amount pegged-change-amount] [reference-change-amount reference-change-amount] [reference-exchange-id reference-exchange-id] [conditions conditions] [conditions-ignore-rth conditions-ignore-rth] [conditions-cancel-order conditions-cancel-order] [adjusted-order-type adjusted-order-type] [trigger-price trigger-price] [limit-price-offset limit-price-offset] [adjusted-stop-price adjusted-stop-price] [adjusted-stop-limit-price adjusted-stop-limit-price] [adjusted-trailing-amount adjusted-trailing-amount] [adjusted-trailing-unit adjusted-trailing-unit] [ext-operator ext-operator] [soft-dollar-tier-name soft-dollar-tier-name] [soft-dollar-tier-value soft-dollar-tier-value]]) → (is-a?/c place-order-req%) order-id : integer? = 0 contract-id : integer? = 0 symbol : string? = ""
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) = #f expiry : (or/c date? #f) = #f strike : rational? = 0 right : (or/c 'call 'put #f) = #f multiplier : (or/c rational? #f) = #f exchange : string? = "" primary-exchange : string? = "" currency : string? = "" local-symbol : string? = "" trading-class : string? = "" security-id-type : (or/c 'cusip 'sedol 'isin 'ric #f) = #f security-id : string? = "" action : (or/c 'buy 'sell 'sshort) = 'buy total-quantity : rational? = 0 order-type : string? = "LMT" limit-price : (or/c rational? #f) = #f aux-price : (or/c rational? #f) = #f
time-in-force :
(or/c 'day 'gtc 'opg 'ioc 'gtd 'gtt 'auc 'fok 'gtx 'dtc) = 'day oca-group : string? = "" account : string? = "" open-close : (or/c 'open 'close) = 'open origin : (or/c 'customer 'firm) = 'customer order-ref : string? = "" transmit : boolean? = #t parent-id : integer? = 0 block-order : boolean? = #f sweep-to-fill : boolean? = #f display-size : integer? = 0 trigger-method : integer? = 0 outside-rth : boolean? = #f hidden : boolean? = #f combo-legs : (listof combo-leg?) = (list) order-combo-legs : (listof rational?) = (list) smart-combo-routing-params : hash? = (hash) discretionary-amount : (or/c rational? #f) = #f good-after-time : (or/c moment? #f) = #f good-till-date : (or/c date? #f) = #f advisor-group : string? = "" advisor-method : string? = "" advisor-percentage : string? = "" advisor-profile : string? = "" model-code : string? = "" short-sale-slot : (or/c 0 1 2) = 0 designated-location : string? = "" exempt-code : integer? = -1 oca-type : integer? = 0 rule-80-a : string? = "" settling-firm : string? = "" all-or-none : boolean? = #f minimum-quantity : (or/c integer? #f) = #f percent-offset : (or/c rational? #f) = #f electronic-trade-only : boolean? = #f firm-quote-only : boolean? = #f nbbo-price-cap : (or/c rational? #f) = #f
auction-strategy : (or/c 'match 'improvement 'transparent #f) = #f starting-price : rational? = 0 stock-ref-price : rational? = 0 delta : (or/c rational? #f) = #f stock-range-lower : rational? = 0 stock-range-upper : rational? = 0 override-percentage-constraints : boolean? = #f volatility : (or/c rational? #f) = #f volatility-type : (or/c integer? #f) = #f delta-neutral-order-type : string? = "" delta-neutral-aux-price : (or/c rational? #f) = #f continuous-update : integer? = 0 reference-price-type : (or/c integer? #f) = #f trailing-stop-price : (or/c rational? #f) = #f trailing-percent : (or/c rational? #f) = #f scale-init-level-size : (or/c integer? #f) = #f scale-subs-level-size : (or/c integer? #f) = #f scale-price-increment : (or/c rational? #f) = #f scale-price-adjust-value : (or/c rational? #f) = #f scale-price-adjust-interval : (or/c integer? #f) = #f scale-profit-offset : (or/c rational? #f) = #f scale-auto-reset : boolean? = #f scale-init-position : (or/c integer? #f) = #f scale-init-fill-quantity : (or/c integer? #f) = #f scale-random-percent : boolean? = #f scale-table : string? = "" active-start-time : string? = "" active-stop-time : string? = "" hedge-type : string? = "" hedge-param : string? = "" opt-out-smart-routing : boolean? = #f clearing-account : string? = "" clearing-intent : (or/c 'ib 'away 'pta #f) = #f not-held : boolean? = #f delta-neutral-contract-id : (or/c integer? #f) = #f delta-neutral-delta : (or/c rational? #f) = #f delta-neutral-price : (or/c rational? #f) = #f algo-strategy : string? = "" algo-id : string? = "" what-if : boolean? = #f order-misc-options : string? = "" solicited : boolean? = #f randomize-size : boolean? = #f randomize-price : boolean? = #f reference-contract-id : integer? = 0 is-pegged-change-amount-decrease : boolean? = #f pegged-change-amount : rational? = 0 reference-change-amount : rational? = 0 reference-exchange-id : string? = "" conditions : (listof condition?) = (list) conditions-ignore-rth : boolean? = #f conditions-cancel-order : boolean? = #f
adjusted-order-type :
(or/c 'mkt 'lmt 'stp 'stp-limit 'rel 'trail 'box-top 'fix-pegged 'lit 'lmt-+-mkt 'loc 'mit 'mkt-prt 'moc 'mtl 'passv-rel 'peg-bench 'peg-mid 'peg-mkt 'peg-prim 'peg-stk 'rel-+-lmt 'rel-+-mkt 'snap-mid 'snap-mkt 'snap-prim 'stp-prt 'trail-limit 'trail-lit 'trail-lmt-+-mkt 'trail-mit 'trail-rel-+-mkt 'vol 'vwap 'quote 'ppv 'pdv 'pmv 'psv #f) = #f trigger-price : rational? = 0 limit-price-offset : rational? = 0 adjusted-stop-price : rational? = 0 adjusted-stop-limit-price : rational? = 0 adjusted-trailing-amount : rational? = 0 adjusted-trailing-unit : integer? = 0 ext-operator : string? = "" soft-dollar-tier-name : string? = "" soft-dollar-tier-value : string? = "" Please note that the fields action, order-type, time-in-force, open-close, and origin use defaults that are not the #f, 0, or "" typical defaults. Also note that you need to manage order-id on your own. If you do not supply an order-id, it will use 0 and you will likely get an error stating the order ID has already been used.
3 Response messages
(require interactive-brokers-api/response-messages) | |
package: interactive-brokers-api |
struct
(struct contract-details-rsp ( request-id symbol security-type expiry strike right exchange currency local-symbol market-name trading-class contract-id minimum-tick-increment multiplier order-types valid-exchanges price-magnifier underlying-contract-id long-name primary-exchange contract-month industry category subcategory time-zone-id trading-hours liquid-hours ev-rule ev-multiplier) #:extra-constructor-name make-contract-details-rsp) request-id : integer? symbol : string?
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) expiry : (or/c date? #f) strike : (or/c rational? #f) right : (or/c 'call 'put #f) exchange : string? currency : string? local-symbol : string? market-name : string? trading-class : string? contract-id : integer? minimum-tick-increment : rational? multiplier : string? order-types : (listof string?) valid-exchanges : (listof string?) price-magnifier : integer? underlying-contract-id : integer? long-name : string? primary-exchange : string? contract-month : string? industry : string? category : string? subcategory : string? time-zone-id : string? trading-hours : (listof string?) liquid-hours : (listof string?) ev-rule : string? ev-multiplier : string?
struct
(struct err-rsp (id error-code error-msg) #:extra-constructor-name make-err-rsp) id : integer? error-code : integer? error-msg : string?
struct
(struct execution-rsp ( request-id order-id contract-id symbol security-type expiry strike right multiplier exchange currency local-symbol trading-class execution-id timestamp account executing-exchange side shares price perm-id client-id liquidation cumulative-quantity average-price order-reference ev-rule ev-multiplier model-code) #:extra-constructor-name make-execution-rsp) request-id : integer? order-id : integer? contract-id : integer? symbol : string?
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) expiry : (or/c date? #f) strike : (or/c rational? #f) right : (or/c 'call 'put #f) multiplier : (or/c rational? #f) exchange : string? currency : string? local-symbol : string? trading-class : string? execution-id : string? timestamp : moment? account : string? executing-exchange : string? side : string? shares : rational? price : rational? perm-id : integer? client-id : integer? liquidation : integer? cumulative-quantity : integer? average-price : rational? order-reference : string? ev-rule : string? ev-multiplier : (or/c rational? #f) model-code : string?
struct
(struct next-valid-id-rsp (order-id) #:extra-constructor-name make-next-valid-id-rsp) order-id : integer?
struct
(struct open-order-rsp ( order-id contract-id symbol security-type expiry strike right multiplier exchange currency local-symbol trading-class action total-quantity order-type limit-price aux-price time-in-force oca-group account open-close origin order-ref client-id perm-id outside-rth hidden discretionary-amount good-after-time advisor-group advisor-method advisor-percentage advisor-profile model-code good-till-date rule-80-a percent-offset settling-firm short-sale-slot designated-location exempt-code auction-strategy starting-price stock-ref-price delta stock-range-lower stock-range-upper display-size block-order sweep-to-fill all-or-none minimum-quantity oca-type electronic-trade-only firm-quote-only nbbo-price-cap parent-id trigger-method volatility volatility-type delta-neutral-order-type delta-neutral-aux-price delta-neutral-contract-id delta-neutral-settling-firm delta-neutral-clearing-account delta-neutral-clearing-intent delta-neutral-open-close delta-neutral-short-sale delta-neutral-short-sale-slot delta-neutral-designated-location continuous-update reference-price-type trailing-stop-price trailing-percent basis-points basis-points-type combo-legs order-combo-legs smart-combo-routing-params scale-init-level-size scale-subs-level-size scale-price-increment scale-price-adjust-value scale-price-adjust-interval scale-profit-offset scale-auto-reset scale-init-position scale-init-fill-quantity scale-random-percent hedge-type hedge-param opt-out-smart-routing clearing-account clearing-intent not-held delta-neutral-underlying-contract-id delta-neutral-underlying-delta delta-neutral-underlying-price algo-strategy algo-strategy-params solicited what-if status initial-margin maintenance-margin equity-with-loan commission minimum-commission maximum-commission commission-currency warning-text randomize-size randomize-price reference-contract-id is-pegged-change-amount-decrease pegged-change-amount reference-change-amount reference-exchange-id conditions adjusted-order-type trigger-price trail-stop-price limit-price-offset adjusted-stop-price adjusted-stop-limit-price adjusted-trailing-amount adjusted-trailing-unit soft-dollar-tier-name soft-dollar-tier-value soft-dollar-tier-display-name) #:extra-constructor-name make-open-order-rsp) order-id : integer? contract-id : integer? symbol : string?
security-type :
(or/c 'stk 'opt 'fut 'cash 'bond 'cfd 'fop 'war 'iopt 'fwd 'bag 'ind 'bill 'fund 'fixed 'slb 'news 'cmdty 'bsk 'icu 'ics #f) expiry : (or/c date? #f) strike : (or/c rational? #f) right : (or/c 'call 'put #f) multiplier : (or/c rational? #f) exchange : string? currency : string? local-symbol : string? trading-class : string? action : (or/c 'buy 'sell 'sshort) total-quantity : rational? order-type : string? limit-price : (or/c rational? #f) aux-price : (or/c rational? #f)
time-in-force :
(or/c 'day 'gtc 'opg 'ioc 'gtd 'gtt 'auc 'fok 'gtx 'dtc) oca-group : string? account : string? open-close : (or/c 'open 'close #f) origin : (or/c 'customer 'firm) order-ref : string? client-id : integer? perm-id : integer? outside-rth : boolean? hidden : boolean? discretionary-amount : (or/c rational? #f) good-after-time : (or/c moment? #f) advisor-group : string? advisor-method : string? advisor-percentage : string? advisor-profile : string? model-code : string? good-till-date : (or/c date? #f) rule-80-a : string? percent-offset : (or/c rational? #f) settling-firm : string? short-sale-slot : (or/c 0 1 2) designated-location : string? exempt-code : integer? auction-strategy : (or/c 'match 'improvement 'transparent #f) starting-price : (or/c rational? #f) stock-ref-price : (or/c rational? #f) delta : (or/c rational? #f) stock-range-lower : (or/c rational? #f) stock-range-upper : (or/c rational? #f) display-size : (or/c integer? #f) block-order : boolean? sweep-to-fill : boolean? all-or-none : boolean? minimum-quantity : (or/c integer? #f) oca-type : integer? electronic-trade-only : boolean? firm-quote-only : boolean? nbbo-price-cap : (or/c rational? #f) parent-id : integer? trigger-method : integer? volatility : (or/c rational? #f) volatility-type : (or/c integer? #f) delta-neutral-order-type : string? delta-neutral-aux-price : (or/c rational? #f) delta-neutral-contract-id : (or/c integer? #f) delta-neutral-settling-firm : string? delta-neutral-clearing-account : string? delta-neutral-clearing-intent : string? delta-neutral-open-close : (or/c 'open 'close #f) delta-neutral-short-sale : boolean? delta-neutral-short-sale-slot : (or/c integer? #f) delta-neutral-designated-location : string? continuous-update : integer? reference-price-type : (or/c integer? #f) trailing-stop-price : (or/c rational? #f) trailing-percent : (or/c rational? #f) basis-points : (or/c rational? #f) basis-points-type : (or/c integer? #f) combo-legs : (listof combo-leg?) order-combo-legs : (listof rational?) smart-combo-routing-params : hash? scale-init-level-size : (or/c integer? #f) scale-subs-level-size : (or/c integer? #f) scale-price-increment : (or/c rational? #f) scale-price-adjust-value : (or/c rational? #f) scale-price-adjust-interval : (or/c integer? #f) scale-profit-offset : (or/c rational? #f) scale-auto-reset : boolean? scale-init-position : (or/c integer? #f) scale-init-fill-quantity : (or/c integer? #f) scale-random-percent : boolean? hedge-type : string? hedge-param : string? opt-out-smart-routing : boolean? clearing-account : string? clearing-intent : (or/c 'ib 'away 'pta #f) not-held : boolean? delta-neutral-underlying-contract-id : (or/c integer? #f) delta-neutral-underlying-delta : (or/c rational? #f) delta-neutral-underlying-price : (or/c rational? #f) algo-strategy : string? algo-strategy-params : (listof string?) solicited : boolean? what-if : boolean? status : string? initial-margin : (or/c rational? #f) maintenance-margin : (or/c rational? #f) equity-with-loan : (or/c rational? #f) commission : (or/c rational? #f) minimum-commission : (or/c rational? #f) maximum-commission : (or/c rational? #f) commission-currency : string? warning-text : string? randomize-size : boolean? randomize-price : boolean? reference-contract-id : (or/c integer? #f) is-pegged-change-amount-decrease : boolean? pegged-change-amount : (or/c rational? #f) reference-change-amount : (or/c rational? #f) reference-exchange-id : string? conditions : (listof condition?)
adjusted-order-type :
(or/c 'mkt 'lmt 'stp 'stp-limit 'rel 'trail 'box-top 'fix-pegged 'lit 'lmt-+-mkt 'loc 'mit 'mkt-prt 'moc 'mtl 'passv-rel 'peg-bench 'peg-mid 'peg-mkt 'peg-prim 'peg-stk 'rel-+-lmt 'rel-+-mkt 'snap-mid 'snap-mkt 'snap-prim 'stp-prt 'trail-limit 'trail-lit 'trail-lmt-+-mkt 'trail-mit 'trail-rel-+-mkt 'vol 'vwap 'quote 'ppv 'pdv 'pmv 'psv #f) trigger-price : (or/c rational? #f) trail-stop-price : (or/c rational? #f) limit-price-offset : (or/c rational? #f) adjusted-stop-price : (or/c rational? #f) adjusted-stop-limit-price : (or/c rational? #f) adjusted-trailing-amount : (or/c rational? #f) adjusted-trailing-unit : integer? soft-dollar-tier-name : string? soft-dollar-tier-value : string? soft-dollar-tier-display-name : string?
4 Base Structs
(require interactive-brokers-api/base-structs) | |
package: interactive-brokers-api |
These structs are used for placing complex orders. You must require the module to use them.
struct
(struct combo-leg ( contract-id ratio action exchange open-close short-sale-slot designated-location exempt-code) #:extra-constructor-name make-combo-leg) contract-id : integer? ratio : integer? action : (or/c 'buy 'sell 'sshort) exchange : string? open-close : (or/c 'same 'open 'close #f) short-sale-slot : (or/c 0 1 2) designated-location : string? exempt-code : integer?
struct
(struct condition ( type boolean-operator comparator value contract-id exchange trigger-method) #:extra-constructor-name make-condition)
type :
(or/c 'price 'time 'margin 'execution 'volume 'percent-change) boolean-operator : (or/c 'and 'or) comparator : (or/c 'less-than 'greater-than) value : (or/c rational? moment?) contract-id : (or/c integer? #f) exchange : (or/c string? #f)
trigger-method :
(or/c 'default 'double-bid/ask 'last 'double-last 'bid/ask 'last-of-bid/ask 'mid-point #f)