### Request Account Data Example Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Example function to request account updates. This function will continue until the same request is made with 'false' instead of 'true'. ```clojure (defn example-account-data-request [] ;will keep going until you send the same request with false instead of true (cs/request-account-updates (:ecs connection) true account)) ``` -------------------------------- ### Place Order (Interop) Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Example of placing an order using interop with the IB client library. ```APIDOC ## example-sending-order-interop ### Description Example call to place an order using interop. ### Parameters - `order-id`: The ID for the order. - `connection`: The connection object. - `MSFT-contract`: Contract object. - `safe-limit-buy-order-order`: Order object. ``` -------------------------------- ### Connection Setup Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Establishes a connection to the Interactive Brokers gateway. Requires a client ID, host, port, and a message handler function. ```clojure (def connection (gateway/connect 2 "localhost" default-port println)) ;you may need to change the port ``` -------------------------------- ### SyntaxHighlighter Highlighter Initialization Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Initializes the highlighter instance. Constructor is not used for initialization to prevent execution during brush inheritance setup. ```javascript init: function(params) { this.id = guid(); // register this instance in the highlighters list storeHighlighter(this); // local params take precedence over defaults this.params = merge(sh.defaults, params || {}) // process light mode if (this.getParam('light') == true) this.params.toolbar = this.params.gutter = false; } ``` -------------------------------- ### Comparison Utilities in REPL Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Provides example REPL commands for comparing the old text-based EWrapper methods with the new JavaParser-based methods, and for inspecting the generated reification forms. ```clojure (comment "To compare old vs new implementations in REPL: ; See parsed methods from JavaParser: (take 5 ewrapper-methods) ; See old text-parsed methods: (take 5 ewrapper-java-methods) ; Compare method counts: (count ewrapper-methods) ; NEW JavaParser-based (count ewrapper-java-methods) ; OLD text-based ; See generated reification forms: (take 10 reification) ; OLD ``` -------------------------------- ### Cancel Order Example Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Example function to cancel an order using a provided order ID. ```clojure (defn example-order-cancel [order-id] ;need to submit same order-id as above (cs/cancel-order (:ecs connection) order-id)) ``` -------------------------------- ### request-real-time-bars Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Start receiving real time bar results. ```APIDOC ## request-real-time-bars ### Description Starts receiving real-time bar data for a specified contract. ### Parameters - **ecs**: The execution context. - **request-id**: The unique identifier for the request. - **contract**: The contract details. - **what-to-show**: The type of data to show (e.g., :trades, :midpoint). - **use-regular-trading-hours?**: Boolean indicating whether to use regular trading hours. ``` -------------------------------- ### Request Historical Data (Interop) Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Example of requesting historical data using interop with the IB client library. ```APIDOC ## example-historical-request-interop ### Description Example call to request historical data using interop. ### Parameters - `connection`: The connection object. - `requests`: Atom for tracking request count. - `ESH6-contract`: Contract object. - `"20251610 00:00:00 UTC"`: End time for the data. - `"10 D"`: Duration. - `"1 day"`: Bar size. - `"TRADES"`: What to show. - `1`: Use regular trading hours flag. - `1`: Bar size unit. - `1`: Unknown parameter. - `false`: Unknown parameter. - `nil`: Unknown parameter. ``` -------------------------------- ### Request Scanner Subscription Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Starts receiving market scanner results. Requires the ECS instance, ticker ID, subscription details, and optional options. ```clojure (defn request-scanner-subscription [ecs ticker-id subscription subscription-options subscription-filter-options] (.reqScannerSubscription ecs ticker-id (map-> com.ib.client.ScannerSubscription subscription) subscription-options subscription-filter-options)) ``` -------------------------------- ### XRegExp Add Token Examples Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Demonstrates how to add custom tokens to XRegExp for extended regular expression capabilities. These tokens handle specific patterns like capturing groups and conditional expressions. ```javascript XRegExp.addToken(/\((?!\?)/,function(){this.captureNames.push(null);return"("});XRegExp.addToken(/\(\?<(\[$\w\]+)>/,function(p){this.captureNames.push(p[1]);this.hasNamedCapture=true;return"("});XRegExp.addToken(/\\k<(\[\w$]*)>/,function(q){var p=l(this.captureNames,q[1]);return p>-1?"\\"+(p+1)+(isNaN(q.input.charAt(q.index+q[0].length))?"":"(?:)"):q[0]});XRegExp.addToken(/\\\[\\^?\\]/,function(p){return p[0]==="[ ]"?"\\b\\B":"[\\s\\S]"});XRegExp.addToken(/^\(\?(\[imsx\]+)\)/,function(p){this.setFlag(p[1]);return""});XRegExp.addToken(/(?:\s+|#.*)+/,function(p){return m.test.call(n,p.input.slice(p.index+p[0].length))?"":"(?:)"},XRegExp.OUTSIDE_CLASS,function(){return this.hasFlag("x")});XRegExp.addToken(/\./,function(){return"[\\s\\S]"},XRegExp.OUTSIDE_CLASS,function(){return this.hasFlag("s")}) ``` -------------------------------- ### request-scanner-subscription Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Call this method to start receiving market scanner results through the scannerData() EWrapper method. ```APIDOC ## request-scanner-subscription ### Description Starts receiving market scanner results. ### Parameters - **ecs**: The execution context. - **ticker-id**: The ticker ID for the subscription. - **subscription**: The scanner subscription details. - **subscription-options**: Additional subscription options. - **subscription-filter-options**: Filter options for the subscription. ``` -------------------------------- ### Request Real Time Bars Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Starts receiving real-time bar results. Requires ECS, contract details, and display options. The `5` parameter is currently ignored. ```clojure (defn request-real-time-bars [ecs request-id contract what-to-show use-regular-trading-hours?] (.reqRealTimeBars ecs request-id (map-> com.ib.client.Contract contract) 5 ; currently being ignored (.name (translate :to-ib :what-to-show what-to-show)) use-regular-trading-hours? nil)) ``` -------------------------------- ### Get Market Snapshot Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Returns a snapshot of the market for the specified contract. Handles data, errors, and end events to populate the result. ```clojure (defn market-snapshot [connection contract] (let [result (promise) data (atom nil) handlers {:data (fn [{:keys [field value]}] (swap! data assoc field value)) :error #(reset! data %) :end #(deliver result @data)}] (g/request-market-data connection contract nil true handlers) @result)) ``` -------------------------------- ### Connect to IB Gateway or TWS Source: https://context7.com/alex314159/ib-re-actor-976-plus/llms.txt Opens a socket connection, starts the message-processing thread, and returns connection details. An optional listener function can receive all callback messages. ```clojure (require '[ib-re-actor-976-plus.gateway :as gateway]) ;; Connect to live TWS (port 7496) or paper (port 7497) (def conn (gateway/connect 1 "localhost" 7497 println)) ;; => {:ecs #object[EClientSocket], :subscribers #atom[...], :next-id #atom[1]} ;; Check connection state (gateway/is-connected? conn) ;; => true ;; Disconnect cleanly (does NOT cancel live orders) (gateway/disconnect conn) ``` -------------------------------- ### gateway/connect Source: https://context7.com/alex314159/ib-re-actor-976-plus/llms.txt Opens a socket connection to IB Gateway or TWS, starts the EReader message-processing thread, and returns a connection map. An optional initial listener function receives every callback message as a Clojure map. ```APIDOC ## gateway/connect — Connect to IB Gateway or TWS ### Description Opens a socket connection to IB Gateway or TWS, starts the `EReader` message-processing thread, and returns a connection map containing `:ecs` (the underlying `EClientSocket`), `:subscribers` (an atom of listener functions), and `:next-id` (an auto-incrementing request/order ID atom). An optional initial listener function receives every callback message as a Clojure map. ### Usage ```clojure (require '[ib-re-actor-976-plus.gateway :as gateway]) ;; Connect to live TWS (port 7496) or paper (port 7497) (def conn (gateway/connect 1 "localhost" 7497 println)) ;; => {:ecs #object[EClientSocket], :subscribers #atom[...], :next-id #atom[1]} ;; Check connection state (gateway/is-connected? conn) ;; => true ;; Disconnect cleanly (does NOT cancel live orders) (gateway/disconnect conn) ``` ``` -------------------------------- ### Function Utilities: guid, proxy, access Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Includes functions for managing unique IDs, creating function proxies with context and arguments, and accessing or setting properties on elements. ```javascript guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=F.call(arguments,2),g=function(){return a.apply(c,f.concat(F.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g} ``` ```javascript access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;kmap]]) (require '[ib-re-actor-976-plus.translation :as t]) (require '[clojure.tools.logging :as log]) (def state (atom {})) (defmulti listener (fn [account msg] (:type msg))) (defmethod listener :next-valid-id [account msg] (swap! state assoc-in [:order-ids account] (:order-id msg))) (defmethod listener :update-account-value [account msg] (let [{:keys [key value currency]} msg avk (t/translate :from-ib :account-value-key key) val (cond (t/numeric-account-value? avk) (parse-double value) (t/integer-account-value? avk) (parse-long value) (t/boolean-account-value? avk) (parse-boolean value) :else value)] (swap! state assoc-in [:account-data account avk] val))) (defmethod listener :historical-data [account msg] (let [{:keys [req-id bar]} msg {:keys [time open high low close volume]} (->map bar)] (swap! state update-in [:bars req-id] conj [time open high low close volume]))) (defmethod listener :error [account msg] (let [{:keys [id code message]} msg] (if (#{2104 2106 2158} code) (log/trace account code message) (log/warn account id code message)))) (defmethod listener :default [account msg] (log/info (name account) msg)) ``` ```clojure ;; Connect multiple accounts (def accounts {:U1234567 {:client-id 1 :port 7496} :U9876543 {:client-id 2 :port 7490}}) (doseq [[acct {:keys [client-id port]}] accounts] (swap! state assoc-in [:connections acct] (gateway/connect client-id "localhost" port (fn [msg] (listener acct msg))))) ``` -------------------------------- ### Request Account Updates Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Starts receiving account values, portfolio, and last update time. The subscribe? flag determines whether to subscribe or unsubscribe. account-code specifies the account to query. ```clojure (defn request-account-updates [ecs subscribe? account-code] (.reqAccountUpdates ecs subscribe? account-code)) ``` -------------------------------- ### Request Account Updates Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Call this function to start getting account values, portfolio, and last update time information. The account data will be fed back through the updateAccountTime(), updateAccountValue() and updatePortfolio() EWrapper methods. ```APIDOC ## request-account-updates ### Description Starts receiving account values, portfolio, and last update time information. ### Method (defn request-account-updates [ecs subscribe? account-code]) ``` -------------------------------- ### Request News Bulletins Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Starts receiving news bulletins. Each bulletin is sent as a :news-bulletin, :exchange-unavailable, or :exchange-available message. Set all-messages? to true to receive all bulletins. ```clojure (defn request-news-bulletins (\[ecs all-messages?] (.reqNewsBulletins ecs all-messages?))) ``` -------------------------------- ### Get Element Height Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Gets the height of an element, including padding. If no argument is provided, it returns the current height. ```javascript f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null} ``` -------------------------------- ### Get Outer Element Height Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Gets the height of an element, including padding and border. Optionally includes margin if specified. ```javascript f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null} ``` -------------------------------- ### Find Index in Array Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Finds the index of an element in an array, starting from a specified index. Ensures the starting index is non-negative. ```javascript function indexOf(array, searchElement, fromIndex) { fromIndex = Math.max(fromIndex || 0, 0); for (var i = fromIndex; i < array.length; i++) if(array[i] == searchElement) return i; return -1; } ``` -------------------------------- ### Connect to IB Gateway/TWS (Simple) Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Establishes a simple connection to the IB Gateway or TWS, accepting only one listener function set at creation. Returns an immutable connection object. ```clojure (defn connect-simple ([client-id] (connect-simple client-id "localhost" default-paper-port println)) ([client-id host port listener-function] (try (let [wr (wrapper/create (fn [message] (try (listener-function message) (catch Throwable t (log/error t "Error dispatching" message))))) signal (EJavaSignal.) ecs (cs/connect wr signal host port client-id)] (when-not (= :error default-server-log-level) (cs/set-server-log-level ecs default-server-log-level)) {:ecs ecs}) (catch Exception ex (log/error "Error trying to connect to " host ":" port ": " ex))))) ``` -------------------------------- ### Create EWrapper Wrapper Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Demonstrates creating a wrapper for the EWrapper interface using both old and new methods. This is useful for testing wrapper creation. ```clojure (take 10 reification-new) ; NEW ; Test creating wrapper (both should work): (def test-cb (fn [msg] (println \"Got:\ ``` -------------------------------- ### jQuery CSS: Get Element Dimensions Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Retrieves the computed width or height of an element. This function is used internally to get accurate dimensions, considering various box models. ```javascript function bC(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bx:by,g=0,h=e.l ``` -------------------------------- ### Main Function Entry Point Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html The main entry point for the application. Currently, it prints the detected TWS API version. ```clojure (defn -main [& args] (println "Detected TWS API version" translation/tws-version)) ``` -------------------------------- ### Syntax Highlighter Initialization Source: https://github.com/alex314159/ib-re-actor-976-plus/blob/master/docs/uberdoc.html Initializes the SyntaxHighlighter with optional parameters and highlights code elements. It handles brush selection and applies parameters like title and brush name. ```javascript sh.highlight = function(params) { params = params || {}; var tags = document.getElementsByTagName('script'); for (var i = 0; i < tags.length; i++) { var target = tags[i]; if (!/syntaxhighlighter/.test(target.className)) continue; var brushName = target.className.match(/brush: (\w+)/); if (!brushName) continue; brushName = brushName[1]; var propertyName = 'innerHTML'; var highlighter = null; if (target.justContent) propertyName = 'justContent'; var code = target[propertyName]; if (code == null || code == '') { code = target.text; // IE if (code == null) continue; } var highlighter = null; if (brushName) { var brush = findBrush(brushName); if (brush) highlighter = new brush(); else continue; } else { highlighter = new SyntaxHighlighter(); } code = target[propertyName]; // remove CDATA from