Class: Fisco::Client
- Inherits:
-
Object
- Object
- Fisco::Client
- Defined in:
- lib/fisco.rb
Instance Method Summary collapse
-
#ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue ask order.
-
#bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue bid order.
-
#cancel(order_id) ⇒ Object
Cancel order.
-
#get_active_orders(option = {}) ⇒ Object
Get your active orders.
-
#get_depth(currency_code, counter_currency_code = "jpy") ⇒ Object
Get depth of currency_code / counter_currency_code.
-
#get_info ⇒ Hash
Get user infomation.
-
#get_last_price(currency_code, counter_currency_code = "jpy") ⇒ Object
Get last price of currency_code / counter_currency_code.
-
#get_my_trades(option = {}) ⇒ Object
Get your trade history.
-
#get_ticker(currency_code, counter_currency_code = "jpy") ⇒ Object
Get ticker of currency_code / counter_currency_code.
-
#get_trades(currency_code, counter_currency_code = "jpy") ⇒ Object
Get trades of currency_code / counter_currency_code.
-
#initialize(opt = {}) ⇒ Client
constructor
A new instance of Client.
- #set_api_key(api_key, api_secret) ⇒ Object
-
#trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue trade.
-
#withdraw(currency_code, address, amount, option = {}) ⇒ Object
Withdraw funds.
Constructor Details
#initialize(opt = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 |
# File 'lib/fisco.rb', line 13 def initialize(opt = {}) @cool_down = opt[:cool_down] || true @cool_down_time = opt[:cool_down_time] || 2 @cert_path = opt[:cert_path] || nil @api_key = opt[:api_key] || nil @api_secret = opt[:api_secret] || nil @fisco_public_url = "https://api.fcce.jp/api/1/" @fisco_trade_url = "https://api.fcce.jp/tapi" end |
Instance Method Details
#ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue ask order. Need api key.
120 121 122 |
# File 'lib/fisco.rb', line 120 def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") return trade(currency_code, price, amount, "ask", limit, counter_currency_code) end |
#bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue bid order. Need api key.
114 115 116 |
# File 'lib/fisco.rb', line 114 def bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy") return trade(currency_code, price, amount, "bid", limit, counter_currency_code) end |
#cancel(order_id) ⇒ Object
Cancel order. Need api key.
126 127 128 129 |
# File 'lib/fisco.rb', line 126 def cancel(order_id) json = post_ssl(@fisco_trade_url, "cancel_order", {:order_id => order_id}) return json end |
#get_active_orders(option = {}) ⇒ Object
Get your active orders. Avalible options: currency_pair Need api key.
93 94 95 96 97 98 99 100 101 |
# File 'lib/fisco.rb', line 93 def get_active_orders(option = {}) json = post_ssl(@fisco_trade_url, "active_orders", option) # Convert to datetime json.each do|k, v| v["datetime"] = Time.at(v["timestamp"].to_i) end return json end |
#get_depth(currency_code, counter_currency_code = "jpy") ⇒ Object
Get depth of currency_code / counter_currency_code.
59 60 61 62 |
# File 'lib/fisco.rb', line 59 def get_depth(currency_code, counter_currency_code = "jpy") json = get_ssl(@fisco_public_url + "depth/" + currency_code + "_" + counter_currency_code) return json end |
#get_info ⇒ Hash
Get user infomation. Need api key.
71 72 73 74 |
# File 'lib/fisco.rb', line 71 def get_info json = post_ssl(@fisco_trade_url, "get_info", {}) return json end |
#get_last_price(currency_code, counter_currency_code = "jpy") ⇒ Object
Get last price of currency_code / counter_currency_code.
35 36 37 38 |
# File 'lib/fisco.rb', line 35 def get_last_price(currency_code, counter_currency_code = "jpy") json = get_ssl(@fisco_public_url + "last_price/" + currency_code + "_" + counter_currency_code) return json["last_price"] end |
#get_my_trades(option = {}) ⇒ Object
Get your trade history. Avalible options: from. count, from_id, end_id, order, since, end, currency_pair Need api key.
80 81 82 83 84 85 86 87 88 |
# File 'lib/fisco.rb', line 80 def get_my_trades(option = {}) json = post_ssl(@fisco_trade_url, "trade_history", option) # Convert to datetime json.each do|k, v| v["datetime"] = Time.at(v["timestamp"].to_i) end return json end |
#get_ticker(currency_code, counter_currency_code = "jpy") ⇒ Object
Get ticker of currency_code / counter_currency_code.
43 44 45 46 |
# File 'lib/fisco.rb', line 43 def get_ticker(currency_code, counter_currency_code = "jpy") json = get_ssl(@fisco_public_url + "ticker/" + currency_code + "_" + counter_currency_code) return json end |
#get_trades(currency_code, counter_currency_code = "jpy") ⇒ Object
Get trades of currency_code / counter_currency_code.
51 52 53 54 |
# File 'lib/fisco.rb', line 51 def get_trades(currency_code, counter_currency_code = "jpy") json = get_ssl(@fisco_public_url + "trades/" + currency_code + "_" + counter_currency_code) return json end |
#set_api_key(api_key, api_secret) ⇒ Object
23 24 25 26 |
# File 'lib/fisco.rb', line 23 def set_api_key(api_key, api_secret) @api_key = api_key @api_secret = api_secret end |
#trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy") ⇒ Object
Issue trade. Need api key.
104 105 106 107 108 109 110 |
# File 'lib/fisco.rb', line 104 def trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy") currency_pair = currency_code + "_" + counter_currency_code params = {:currency_pair => currency_pair, :action => action, :price => price, :amount => amount} params.store(:limit, limit) if limit json = post_ssl(@fisco_trade_url, "trade", params) return json end |
#withdraw(currency_code, address, amount, option = {}) ⇒ Object
Withdraw funds. Need api key.
133 134 135 136 137 138 139 |
# File 'lib/fisco.rb', line 133 def withdraw(currency_code, address, amount, option = {}) option["currency"] = currency_code option["address"] = address option["amount"] = amount json = post_ssl(@fisco_trade_url, "withdraw", option) return json end |