Class: Etwings::API

Inherits:
Object
  • Object
show all
Defined in:
lib/etwings.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ API


14
15
16
17
18
19
20
21
22
# File 'lib/etwings.rb', line 14

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
    @etwings_public_url = "https://exchange.etwings.com/api/1/"
    @etwings_trade_url = "https://exchange.etwings.com/tapi"
end

Instance Method Details

#ask(currency_code, price, amount, counter_currency_code = "jpy") ⇒ Object

Issue ask order. Need api key.


109
110
111
# File 'lib/etwings.rb', line 109

def ask(currency_code, price, amount, counter_currency_code = "jpy")
    return trade(currency_code, price, amount, "ask", counter_currency_code)
end

#bid(currency_code, price, amount, counter_currency_code = "jpy") ⇒ Object

Issue bid order. Need api key.


103
104
105
# File 'lib/etwings.rb', line 103

def bid(currency_code, price, amount, counter_currency_code = "jpy")
    return trade(currency_code, price, amount, "bid", counter_currency_code)
end

#cancel(order_id) ⇒ Object

Cancel order. Need api key.


115
116
117
118
# File 'lib/etwings.rb', line 115

def cancel(order_id)
    json = post_ssl(@etwings_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.


84
85
86
87
88
89
90
91
92
# File 'lib/etwings.rb', line 84

def get_active_orders(option = {})
    json = post_ssl(@etwings_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.


52
53
54
55
# File 'lib/etwings.rb', line 52

def get_depth(currency_code, counter_currency_code = "jpy")
    json = get_ssl(@etwings_public_url + "depth/" + currency_code + "_" + counter_currency_code)
    return json
end

#get_infoObject

Get user infomation. Need api key.


63
64
65
66
# File 'lib/etwings.rb', line 63

def get_info
    json = post_ssl(@etwings_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.


34
35
36
37
# File 'lib/etwings.rb', line 34

def get_last_price(currency_code, counter_currency_code = "jpy")
    json = get_ssl(@etwings_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.


71
72
73
74
75
76
77
78
79
# File 'lib/etwings.rb', line 71

def get_my_trades(option = {})
    json = post_ssl(@etwings_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.


40
41
42
43
# File 'lib/etwings.rb', line 40

def get_ticker(currency_code, counter_currency_code = "jpy")
    json = get_ssl(@etwings_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.


46
47
48
49
# File 'lib/etwings.rb', line 46

def get_trades(currency_code, counter_currency_code = "jpy")
    json = get_ssl(@etwings_public_url + "trades/" + currency_code + "_" + counter_currency_code)
    return json
end

#set_api_key(api_key, api_secret) ⇒ Object


24
25
26
27
# File 'lib/etwings.rb', line 24

def set_api_key(api_key, api_secret)
    @api_key = api_key
    @api_secret = api_secret
end

#trade(currency_code, price, amount, action, counter_currency_code = "jpy") ⇒ Object

Issue trade. Need api key.


95
96
97
98
99
# File 'lib/etwings.rb', line 95

def trade(currency_code, price, amount, action, counter_currency_code = "jpy")
    currency_pair = currency_code + "_" + counter_currency_code
    json = post_ssl(@etwings_trade_url, "trade", {:currency_pair => currency_pair, :action => action, :price => price, :amount => amount})
    return json
end

#withdraw(currency_code, address, amount, option = {}) ⇒ Object

Withdraw funds. Need api key.


122
123
124
125
126
127
128
# File 'lib/etwings.rb', line 122

def withdraw(currency_code, address, amount, option = {})
    option["currency"] = currency_code
    option["address"] = address
    option["amount"] = amount
    json = post_ssl(@etwings_trade_url, "withdraw", option)
    return json
end