Как подключить twsapi к @stoqey/ib в clojurescripJavascript

Форум по Javascript
Ответить
Anonymous
 Как подключить twsapi к @stoqey/ib в clojurescrip

Сообщение Anonymous »

При выполнении скрипта в JavaScript он нормально, как и ожидалось,
с использованием @stoqey /ib с Clojurescript безуспешно. < /p>
  • Пожалуйста. Прокомментируйте, как правильно получить доступ к конструктору @Stoqey/IB с Clojurescript. @stoqey/ib правильно
section npm-deps в deps.edn
;; Specify npm dependencies
:npm-deps {mathjs "^14.0.0"
;; "@stoqey/ib" "^1.4.4"

}}

при выполнении следующего Clojurescript в Repl,
**
;; Create IBApi object with configuration
(def ib
(IBApi. #js {:port 7497}))
;; You can uncomment and set these options if needed
;; {:clientId 0
;; :host "127.0.0.1"
;; :port 7497})

столкнулся с ошибкой.
Execution error (TypeError) at (:1).
; module$node_modules$$stoqey$ib$dist$index.IBApi is not a constructor

**
версия в Clojurescript
(ns trading-system.core
(:require
["@stoqey/ib" :refer [IBApi EventName]]))

;; Create IBApi object with configuration
(def ib
(IBApi. #js {:port 7497}))
;; You can uncomment and set these options if needed
;; {:clientId 0
;; :host "127.0.0.1"
;; :port 7497})

;; Initialize a mutable counter for positions
(def positions-count (atom 0))

;; Register event handler for errors
(.on ib EventName.error
(fn [err code reqId]
(js/console.error
(str (.-message err) " - code: " code " - reqId: " reqId))))

;; Register event handler for each position received
(.on ib EventName.position
(fn [account contract pos avgCost]
(js/console.log
(str account ": " pos " x " (.-symbol contract) " @ " avgCost))
(swap! positions-count inc)))

;; Register a one-time event handler for the end of positions
(.once ib EventName.positionEnd
(fn []
(js/console.log
(str "Total: " @positions-count " positions."))
;; Disconnect from the IB API after processing
(.disconnect ib)))

;; Connect to the IB API
(.connect ib)

;; Request the current portfolio positions
(.reqPositions ib)

;; Start the connection and process
;;(start)
;; Call the start function to execute
;; (load-file "src/trading_system/core.cljs")
;; (-main)
< /code>
Версия в javascript < /h2>
/* Example: Print all portfolio positions to console. */

import { IBApi, EventName } from "@stoqey/ib";

// Create IBApi object
const ib = new IBApi({
// clientId: 0, // Optional: specify clientId if needed
// host: '127.0.0.1', // Optional: specify host if different
port: 7497, // Default port for TWS
});

// Register event handlers
let positionsCount = 0;

ib
.on(EventName.error, (err, code, reqId) => {
console.error(`${err.message} - code: ${code} - reqId: ${reqId}`);
})
.on(EventName.position, (account, contract, pos, avgCost) => {
console.log(`${account}: ${pos} x ${contract.symbol} @ ${avgCost}`);
positionsCount++;
})
.once(EventName.positionEnd, () => {
console.log(`Total: ${positionsCount} positions.`);
ib.disconnect();
});

// Connect to the IB API and request positions
ib.connect();
ib.reqPositions();


Подробнее здесь: https://stackoverflow.com/questions/793 ... ojurescrip
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»