Class: Coinfloor::CFcon
- Inherits:
-
Object
- Object
- Coinfloor::CFcon
- Defined in:
- lib/trade_api/trade_api.rb
Instance Attribute Summary collapse
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Instance Method Summary collapse
-
#auth(server_nonce) ⇒ Object
Authenticate using your generated private key, pass in the nonce given by the server on initial authenticate open.
-
#cancelorder(args) ⇒ Object
Cancels users existing order.
-
#estimatemarketorder(args) ⇒ Object
Simulates the execution of a market order and returns the quantity and total that would have been traded.
-
#getbalance(args = {}) ⇒ Object
Return any available balance.
-
#getorders(args = {}) ⇒ Object
Return a list of open orders.
-
#gettradevolume(args) ⇒ Object
Retrieves the 30-day trailing trade volume for the authenticated user.
-
#initialize(uid, password, api_key, pkey = nil) ⇒ CFcon
constructor
coinfloor user trade id, password.
-
#orderbook(args) ⇒ Object
Gets a copy of the orderbook, does not subscribe.
-
#placeorder(args) ⇒ Object
Place an order.
Constructor Details
#initialize(uid, password, api_key, pkey = nil) ⇒ CFcon
coinfloor user trade id, password
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/trade_api/trade_api.rb', line 7 def initialize(uid, password, api_key, pkey = nil) @uid = uid @uid_byte = LibEcp.gen_uid(uid) if pkey @private_key = pkey else @password = password @private_key = LibEcp.private_key(@uid_byte, password) end @public_key = LibEcp.gen_pub(@private_key) @cookie = api_key @password = nil end |
Instance Attribute Details
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
23 24 25 |
# File 'lib/trade_api/trade_api.rb', line 23 def public_key @public_key end |
Instance Method Details
#auth(server_nonce) ⇒ Object
Authenticate using your generated private key, pass in the nonce given by the server on initial authenticate open.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trade_api/trade_api.rb', line 27 def auth(server_nonce) nonce = LibEcp.gen_nonce while nonce.bytes.count == 15 nonce = LibEcp.gen_nonce end sigs = LibEcp.sign(@uid_byte, Base64.decode64(server_nonce), nonce, @private_key) { "method" => "Authenticate", "user_id" => @uid, "cookie" => @cookie, "nonce" => Base64.encode64(nonce).rstrip, "signature" => [Base64.encode64(sigs[0]).rstrip, Base64.encode64(sigs[1]).rstrip] }.to_json.gsub(/\s+/, "") end |
#cancelorder(args) ⇒ Object
Cancels users existing order.
44 45 46 47 48 49 |
# File 'lib/trade_api/trade_api.rb', line 44 def cancelorder(args) { :method => "CancelOrder", :id => args[:id], }.to_json end |
#estimatemarketorder(args) ⇒ Object
Simulates the execution of a market order and returns the quantity and total that would have been traded. This estimation does not take into account trading fees.
92 93 94 95 96 97 98 99 100 |
# File 'lib/trade_api/trade_api.rb', line 92 def estimatemarketorder(args) { :method => "EstimateMarketOrder", :base => args[:base_asset_id], :counter => args[:counter_asset_id], :quantity => args[:quantity], :total => args[:total], }.to_json end |
#getbalance(args = {}) ⇒ Object
Return any available balance.
52 53 54 55 56 |
# File 'lib/trade_api/trade_api.rb', line 52 def getbalance(args = {}) { :method => "GetBalances", }.to_json end |
#getorders(args = {}) ⇒ Object
Return a list of open orders.
59 60 61 62 63 |
# File 'lib/trade_api/trade_api.rb', line 59 def getorders(args = {}) { :method => "GetOrders", }.to_json end |
#gettradevolume(args) ⇒ Object
Retrieves the 30-day trailing trade volume for the authenticated user.
103 104 105 106 107 108 |
# File 'lib/trade_api/trade_api.rb', line 103 def gettradevolume(args) { :method => "GetTradeVolume", :asset => args[:asset_id], }.to_json end |
#orderbook(args) ⇒ Object
Gets a copy of the orderbook, does not subscribe. The subscription connection is not working because we are not doing a continious conection.
80 81 82 83 84 85 86 87 |
# File 'lib/trade_api/trade_api.rb', line 80 def orderbook(args) { :method => "WatchOrders", :base => args[:base_asset_id], :counter => args[:counter_asset_id], :watch => true, }.to_json end |
#placeorder(args) ⇒ Object
Place an order.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/trade_api/trade_api.rb', line 66 def placeorder(args) { :method => "PlaceOrder", :base => args[:base_asset_id], :counter => args[:counter_asset_id], :quantity => args[:quantity], :price => args[:price], :total => args[:total], }.delete_if { |k, v| v.nil? }.to_json end |