Last active
March 29, 2021 01:21
-
-
Save jjttjj/d26288a26ab599c90bb011a5ecf2f5ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.core.async :as a | |
:refer [<! >! alt! alts! chan go go-loop poll! <!! >!!]]) | |
(import | |
com.paritytrading.philadelphia.FIXConfig | |
com.paritytrading.philadelphia.FIXConnection | |
com.paritytrading.philadelphia.FIXConfig$Builder | |
com.paritytrading.philadelphia.FIXConnection | |
com.paritytrading.philadelphia.FIXConnectionStatusListener | |
com.paritytrading.philadelphia.FIXMessage | |
com.paritytrading.philadelphia.FIXMessageListener | |
com.paritytrading.philadelphia.FIXValue | |
com.paritytrading.philadelphia.FIXVersion | |
com.paritytrading.philadelphia.FIXMessageListener | |
java.io.Closeable | |
java.io.IOException | |
[java.net SocketAddress InetSocketAddress] | |
java.net.StandardSocketOptions | |
java.nio.channels.SocketChannel | |
com.paritytrading.philadelphia.coinbase.Coinbase | |
[com.paritytrading.philadelphia.coinbase CoinbaseTags] | |
com.paritytrading.philadelphia.fix42.FIX42MsgTypes | |
com.paritytrading.philadelphia.fix42.FIX42Tags | |
[com.paritytrading.philadelphia.fix42 | |
FIX42Enumerations | |
FIX42Enumerations$EncryptMethodValues]) | |
(def msg-listener | |
(reify FIXMessageListener | |
(message [this message] | |
(println "new msg:" message)))) | |
(def status-listener | |
(reify FIXConnectionStatusListener | |
(close [this connection message] | |
(println "close" connection message)) | |
(sequenceReset [this connection] | |
(println "sequenceReset" connection)) | |
(tooLowMsgSeqNum [this connection receivedMsgSeqNum expectedMsgSeqNum] | |
(println "tooLowMsgSeqNum" connection receivedMsgSeqNum expectedMsgSeqNum)) | |
(heartbeatTimeout [this connection] | |
(println "heartbeatTimeout" connection)) | |
(reject [this connection message] | |
(println "reject" connection message)) | |
(logon [this connection message] | |
(println "logon" connection message)) | |
(logout [this connection message] | |
(println "logout" connection message)))) | |
(do | |
(def sch (SocketChannel/open)) | |
(.connect sch (InetSocketAddress. #_host #_ port "localhost" local-port)) | |
(def b | |
(doto (FIXConfig$Builder.) | |
(.setVersion FIXVersion/FIX_4_2) | |
(.setSenderCompID (:key cb-creds)) | |
(.setTargetCompID "Coinbase") | |
(.setHeartBtInt 30))) | |
(def conn (FIXConnection. sch (.build b) msg-listener status-listener)) | |
(do | |
(def msg (.create conn)) | |
(.prepare conn msg FIX42MsgTypes/Logon) | |
(-> msg | |
(.addField FIX42Tags/EncryptMethod) | |
(.setInt FIX42Enumerations$EncryptMethodValues/None)) | |
(-> msg | |
(.addField FIX42Tags/HeartBtInt) | |
(.setInt 30)) | |
(-> msg | |
(.addField CoinbaseTags/Password) | |
(.setString (:passphrase cb-creds))) | |
(Coinbase/sign msg (:secret cb-creds)) | |
(.send conn msg)) | |
(def pill (chan 1)) | |
(a/thread | |
(loop [] | |
(if (poll! pill) | |
(println "stopping") | |
(do (when-some [r (.receive conn)] | |
(if (neg? r) | |
(println "stopping2") | |
(do (println "new line:" r) | |
(recur)))) | |
))))) | |
(def omsg (.create conn)) | |
(.prepare conn omsg FIX42MsgTypes/OrderSingle) | |
(do | |
(-> omsg | |
(.addField FIX42Tags/Symbol) | |
(.setString "BTC-USD")) | |
(-> omsg | |
(.addField FIX42Tags/ClOrdID) | |
;;(.set (m/random-uuid)) | |
(.setString (str (m/random-uuid))) | |
) | |
(-> omsg | |
(.addField FIX42Tags/Price) | |
(.setInt 40000)) | |
(-> omsg | |
(.addField FIX42Tags/Side) | |
(.setInt 1)) | |
(-> omsg | |
(.addField FIX42Tags/OrdType) | |
(.setInt 2)) | |
(-> omsg | |
(.addField FIX42Tags/OrderQty) | |
(.setString "0.001"))) | |
(.send conn omsg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment