I'm still reviewing breaking sample code during the migration to v20 REST API, these sample codes are subject to be changed soon
The clojure wrapper for OANDA REST API
- Installation
- A mini example
- Reference
- Setup Header
- Initiate api Instance
- Instrument Management
- Account Management
- Order Management
- Trade Management
- Position Management
- Transaction Management
- Pricing
- [Utility Functions] (#utility-functions)
- Development Reference
- Clone the code and complie a jar
- download a jar package
$ java -jar cloanda-0.1.0-standalone.jar [args]
;; setup a request header
(def my-header (gen-headers "your token" ))
;; pick a trading env by a hash-map
;; production
(:production server_env)
;; practice
(:practice server_env)
;; setup api instance
(def oanda_api (init-api (:practice server_env) my-header))
;; get available accounts
(.get-accounts oanda_api)
;; other stuff
;; setup token in headers
(def my-header (gen-header "Your tokens here") )
(def oanda_api (init-api (:practice server_env) my-header))
;;Get all available trading instruments
(.get-account-instruments oanda_api "account id")
;; response
;; {:instruments [{:tradeUnitsPrecision 0,:minimumTradeSize "1",:maximumPositionSize "0", :displayName "EUR/DKK",:pipLocation -4,:name "EUR_DKK",:maximumTrailingStopDistance "1.00000", :type "CURRENCY",..............
;; Get current quote for a given instrument
(.get-pricing-inst oanda_api "account id" {"instruments" "EUR_USD"})
;; response
;; {:prices [{:bids [{:price "1.14211", :liquidity 10000000}],:instrument "EUR_USD", :closeoutBid "1.14196",
(.get-instrument-history oanda_api "EUR_USD" )
;; Get history prices
;; get history prices of instrument "EUR_USD"
;; by default it will return 500 periods & 5 seconds as granularity
;; getting EUR/USD last 15 ticks with granularity = 5 minutes
(.get-instrument-history oanda_api "EUR_USD" {"count" "5" "granularity" "M5"})
;; response
;; {:instrument "EUR_USD", :granularity "S5", :candles [{:highBid 1.24052, :time "1442495330000000", :lowBid 1.24052, :openAsk 1.24066, :closeAsk 1.24066, :openBid 1.24052, :volume 1, :highAsk 1.24066, :complete true, :closeBid 1.24052, :lowAsk 1.24066} {:highBid 1.24052, :time "1442495335000000", :lowBid 1.24044, :openAsk 1.24065, :closeAsk 1.24063, :openBid 1.24052, :volume 9, :highAsk 1.24066, :complete true, :closeBid 1.24044, :lowAsk 1.24063} {:highBid 1.24045, :time "1442495340000000", :lowBid 1.24044, :openAsk 1.24061, :closeAsk 1.24061, :openBid 1.24045, :volume 2, :highAsk 1.24061, :complete false, :closeBid 1.24044, :lowAsk 1.24061}]}
;; getting 50 periods by passing an option map
(.get-instrument-history oanda_api "EUR_USD" {"count" 50})
;; map can contains more than one parameter, "D" stands for "Day"
(.get-instrument-history oanda_api "EUR_USD" {"count" 50 "granularity" "D"})
;; get all accounts associate with current login
(.get-accounts oanda_api)
;; response
;; .... :body {:accounts [{:id "ACCOUNT ID", :tags []}]} ....
;; get all tradable instruments under a given account
(.get-account-instruments oanda_api "ACCOUNT ID")
;; get detail account information for given account id
(.get-account-info oanda_api "ACCOUNT ID")
;; response
;; {:marginUsed 0, :accountCurrency "USD", :accountName "Primary", :realizedPl 0, :unrealizedPl 0, :balance 100000, :marginAvail 100000, :openTrades 0, :accountId 8055333, :marginRate 0.05, :openOrders 0}
;; get summary account information for given account id
(.get-account-summary oanda_api "ACCOUNT ID")
;; get current account state and changes since a transaction id
(.get-account-changes oanda_api "ACCOUNT ID" {"sinceTransactionID" "1523"})
;; list all orders under a account
(.get-orders-by-account oanda_api "ACCOUNT ID")
;; place an buy market order
(.create-order api "ACCOUNT ID" "EUR_USD" "1000" "buy" "MARKET" {})
;; getting an order info under an account
(.get-order-info api "ACCOUNT ID" "order_id")
;; get all pending orders in a given account
(.get-pending-orders api "ACCOUNT ID")
;; change an order via a map
(.replace-order api account_id order_id params)
;; cancel an order
(.cancel-order api account_id order_id)
;; list all trades given an account id
(.get-open-trades api account_id)
;; list all trades associate with a given account
(.get-trades api account_id)
;; get detail trade info by trade id
(.get-trade-info api account_id trade_id)
;; update a trade by a map
(.update-trade api account_id trade_id {})
;; close a trade by trade id
(.close-trade api account_id trade_id)
;; list all position under a given account id
(.get-open-position api account_id)
;; list all position of an account
(.get-position api account_id)
;; get position of given instrument and account id
(.get-position-by-inst api account_id "EUR_USD")
;; close position of given instrument and account id
(.close-position api account_id "EUR_USD")
;; list all transaction history of a given account
(.get-txn-history api account_id)
;; get a detail information of a given transaction id
(.get-txn-info api account_id txn_id)
;; list account history by given account id
(.get-account-history api account_id)
;; get pricing information for a specified list of instruments within an Account
(.get-pricing-int api accound_id {"instruments" ""} )
;; get a stream of account pricies starting from when the request is made
(.get-pricing-stream api accound_id {"instruments" ""} )
http://developer.oanda.com/rest-live-v20/development-guide/
Please drop an email to [email protected]
- No quality guarantee for any functionality or effectiveness or correct mapping of OANDA API.
- Any user shall use this library by his/her own discretion and be responsible for any losses caused by this library.
- Copyright © 2015/2016/2017 Xiaoyu
- Distributed under the Eclipse Public License either version 1.0 or any later version.