Class: Excoin::API
- Inherits:
-
Object
- Object
- Excoin::API
- Defined in:
- lib/excoin/api.rb
Constant Summary collapse
- API_VERSION =
config["api_version"]
- API_KEY =
config["api_key"]
- API_SECRET =
config["api_secret"]
- API_REPLAY_STRATEGY =
config["api_replay_strategy"]
- NONCE_MULTIPLIER =
config["nonce_multiplier"].to_i
- EXPIRE_INTERVAL =
config["expire_interval"].to_i
- EXCOIN_API_BASE_URL =
"https://api.exco.in/v#{API_VERSION}/"
- ACCOUNT_INACCESSIBLE_ERROR =
"Account inaccessible, valid API key not provided."
- NO_REPLAY_STRATEGY =
"Account inaccessible, valid replay strategy not provided."
- NO_REPLAY_STRATEGY_PARAM =
"Account inaccessible, valid replay strategy paramter not provided."
- CONNECTION_REFUSED =
"Connection refused."
Instance Method Summary collapse
- #account_cancel_order(order_id) ⇒ Object
- #account_generate_deposit_address(coin) ⇒ Object
- #account_issue_order(currency, commodity, type, amount, price) ⇒ Object
- #account_open_orders(currency = nil, commodity = nil, type = nil) ⇒ Object
-
#account_summary ⇒ Object
Account API.
- #account_trades(count = 100) ⇒ Object
- #account_view_order(order_id) ⇒ Object
- #account_withdraw(currency, address, amount) ⇒ Object
- #exchange_candlestick_chart_data(currency, commodity, duration = nil) ⇒ Object
- #exchange_open_orders(currency, commodity, type_or_count = nil) ⇒ Object
- #exchange_order_depth_chart_data(currency, commodity) ⇒ Object
- #exchange_recent_trades(currency, commodity, limit_type = "count", limit = 100) ⇒ Object
- #exchange_summary(currency, commodity) ⇒ Object
- #excoin_wallet_reserves(coin) ⇒ Object
-
#excoin_wallets_summary(coin = nil) ⇒ Object
Reserves API.
-
#initialize(api_key = nil, api_secret = nil, replay_strategy = nil, strategy_parameter = nil) ⇒ API
constructor
A new instance of API.
-
#multiple_exchange_summary(currency = nil) ⇒ Object
Exchange API.
Constructor Details
#initialize(api_key = nil, api_secret = nil, replay_strategy = nil, strategy_parameter = nil) ⇒ API
Returns a new instance of API.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/excoin/api.rb', line 24 def initialize(api_key = nil, api_secret = nil, replay_strategy = nil, strategy_parameter = nil) @api_key = api_key @api_key ||= API_KEY if API_KEY =~ /\A[\w|-]{42,}/ @api_secret = api_secret @api_secret ||= API_SECRET if API_SECRET =~ /\A[\w|-]{42,}/ @account_accessible = !(@api_key.nil? or @api_secret.nil?) @api_replay_strategy = replay_strategy @api_replay_strategy ||= API_REPLAY_STRATEGY @api_replay_strategy_parameter = strategy_parameter @api_replay_strategy_parameter ||= ((EXPIRE_INTERVAL if @api_replay_strategy == "expire") or (NONCE_MULTIPLIER if @api_replay_strategy == "nonce")) end |
Instance Method Details
#account_cancel_order(order_id) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/excoin/api.rb', line 133 def account_cancel_order(order_id) if @account_accessible self.get("account/order/#{order_id}/cancel") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_generate_deposit_address(coin) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/excoin/api.rb', line 93 def account_generate_deposit_address(coin) if @account_accessible self.get("account/#{coin}/generate_address") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_issue_order(currency, commodity, type, amount, price) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/excoin/api.rb', line 117 def account_issue_order(currency, commodity, type, amount, price) if @account_accessible self.get("account/orders/issue/#{currency}/#{commodity}/#{type}/#{amount}/#{price}") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_open_orders(currency = nil, commodity = nil, type = nil) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/excoin/api.rb', line 109 def account_open_orders(currency = nil, commodity = nil, type = nil) if @account_accessible self.get("account/orders#{'/' + currency if currency}#{'/' + commodity if commodity}#{'/' + type if type }") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_summary ⇒ Object
Account API
77 78 79 80 81 82 83 |
# File 'lib/excoin/api.rb', line 77 def account_summary if @account_accessible self.get("account/summary") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_trades(count = 100) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/excoin/api.rb', line 101 def account_trades(count = 100) if @account_accessible self.get("account/trades/#{count}") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_view_order(order_id) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/excoin/api.rb', line 125 def account_view_order(order_id) if @account_accessible self.get("account/order/#{order_id}") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#account_withdraw(currency, address, amount) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/excoin/api.rb', line 85 def account_withdraw(currency, address, amount) if @account_accessible self.get("account/withdraw/#{currency}/#{address}/#{amount}") else return{:error => ACCOUNT_INACCESSIBLE_ERROR} end end |
#exchange_candlestick_chart_data(currency, commodity, duration = nil) ⇒ Object
67 68 69 |
# File 'lib/excoin/api.rb', line 67 def exchange_candlestick_chart_data(currency, commodity, duration = nil) self.get("exchange/#{currency}/#{commodity}/chart/candlestick#{ '/' + duration if duration }") end |
#exchange_open_orders(currency, commodity, type_or_count = nil) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/excoin/api.rb', line 59 def exchange_open_orders(currency, commodity, type_or_count = nil) if type_or_count type = type_or_count.upcase if (type_or_count.class == String and (type_or_count.upcase == "BID" or type_or_count.upcase == "ASK")) count = type_or_count.to_s unless type end self.get("exchange/#{currency}/#{commodity}/orders#{ '/type/' + type if type }#{'/' + count if count}") end |
#exchange_order_depth_chart_data(currency, commodity) ⇒ Object
71 72 73 |
# File 'lib/excoin/api.rb', line 71 def exchange_order_depth_chart_data(currency, commodity) self.get("exchange/#{currency}/#{commodity}/chart/orderdepth") end |
#exchange_recent_trades(currency, commodity, limit_type = "count", limit = 100) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/excoin/api.rb', line 51 def exchange_recent_trades(currency, commodity, limit_type = "count", limit = 100) if limit_type == "count" self.get("exchange/#{currency}/#{commodity}/trades/#{limit}") elsif limit_type == "timestamp" self.get("exchange/#{currency}/#{commodity}/trades/timestamp/#{limit}") end end |
#exchange_summary(currency, commodity) ⇒ Object
47 48 49 |
# File 'lib/excoin/api.rb', line 47 def exchange_summary(currency, commodity) self.get("exchange/#{currency}/#{commodity}/summary") end |
#excoin_wallet_reserves(coin) ⇒ Object
151 152 153 |
# File 'lib/excoin/api.rb', line 151 def excoin_wallet_reserves(coin) self.get("wallet/#{coin}/reserves") end |
#excoin_wallets_summary(coin = nil) ⇒ Object
Reserves API
143 144 145 146 147 148 149 |
# File 'lib/excoin/api.rb', line 143 def excoin_wallets_summary(coin = nil) unless coin self.get("wallets/summary") else self.get("wallet/#{coin}") end end |
#multiple_exchange_summary(currency = nil) ⇒ Object
Exchange API
39 40 41 42 43 44 45 |
# File 'lib/excoin/api.rb', line 39 def multiple_exchange_summary(currency = nil) unless currency self.get("summary") else self.get("summary/#{currency}") end end |