cf-trade-client 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/client/client.rb +108 -112
- data/lib/trade_api/trade_api.rb +2 -2
- metadata +7 -6
data/lib/client/client.rb
CHANGED
@@ -15,116 +15,112 @@ limitations under the License.
|
|
15
15
|
=end
|
16
16
|
require 'faye/websocket'
|
17
17
|
module Coinfloor
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@con.public_key
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
18
|
+
class CFClient
|
19
|
+
def initialize(domain,uid,api_key,pass,pkey=nil)
|
20
|
+
|
21
|
+
if domain.include?("ws://")||domain.include?("wss://")
|
22
|
+
@messages=[]
|
23
|
+
if uid==0
|
24
|
+
@con=CFAcon.new(uid,pass)
|
25
|
+
else
|
26
|
+
if pkey
|
27
|
+
@con=CFcon.new(uid,pass,api_key,pkey)
|
28
|
+
else
|
29
|
+
@con=CFcon.new(uid,api_key,pass)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@domain=domain
|
33
|
+
else
|
34
|
+
puts "domain must be a ws:// or wss:// formatted string, if port is not 80 it must be specified"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
def auth(ws,msg)
|
39
|
+
@messages.push(:auth)
|
40
|
+
nonce=msg["nonce"]
|
41
|
+
result=@con.auth(nonce)
|
42
|
+
ws.send(result)
|
43
|
+
end
|
44
|
+
|
45
|
+
def begin_connection(sendata)
|
46
|
+
output=nil
|
47
|
+
EM.run {
|
48
|
+
ws = Faye::WebSocket::Client.new(@domain)
|
49
|
+
ws.on :open do |event|
|
50
|
+
end
|
51
|
+
|
52
|
+
ws.on :message do |event|
|
53
|
+
evtdata=event.data
|
54
|
+
msg=JSON.parse(evtdata)
|
55
|
+
if msg["notice"]&&msg["notice"]=="Welcome"
|
56
|
+
auth(ws,msg)
|
57
|
+
elsif msg["notice"].nil?
|
58
|
+
ret_msg=@messages.delete_at(0)
|
59
|
+
case ret_msg
|
60
|
+
when nil
|
61
|
+
ws.close
|
62
|
+
ws=nil
|
63
|
+
EM.stop
|
64
|
+
when :auth
|
65
|
+
if msg["error_code"]==0
|
66
|
+
@messages.push(:reply)
|
67
|
+
ws.send(sendata)
|
68
|
+
else
|
69
|
+
ws.close
|
70
|
+
ws=nil
|
71
|
+
EM.stop
|
72
|
+
end
|
73
|
+
when :reply
|
74
|
+
if msg["error_code"]==0
|
75
|
+
output=msg
|
76
|
+
ws.close
|
77
|
+
EM.stop
|
78
|
+
else
|
79
|
+
output=msg
|
80
|
+
ws.close
|
81
|
+
EM.stop
|
82
|
+
end
|
83
|
+
else
|
84
|
+
ws.close
|
85
|
+
EM.stop
|
86
|
+
raise "Reply for unknown action"
|
87
|
+
end
|
88
|
+
elsif msg["notice"] && (@messages.count > 0)
|
89
|
+
#we just ignore this until we get a message we want
|
90
|
+
elsif msg["notice"] && (@messages.count == 0)
|
91
|
+
ws.close
|
92
|
+
EM.stop
|
93
|
+
else
|
94
|
+
raise "Somethings gone wrong with the client"
|
95
|
+
end
|
96
|
+
end# end of on message event
|
97
|
+
|
98
|
+
ws.on :error do |event|
|
99
|
+
EM.stop
|
100
|
+
ws = nil
|
101
|
+
end
|
102
|
+
|
103
|
+
ws.on :close do |event|
|
104
|
+
EM.stop
|
105
|
+
ws = nil
|
106
|
+
end
|
107
|
+
}
|
108
|
+
return output
|
109
|
+
end
|
110
|
+
|
111
|
+
def exec(cfcon_method,arguments)
|
112
|
+
|
113
|
+
data=@con.send(cfcon_method.to_s,arguments)
|
114
|
+
|
115
|
+
begin_connection(data)
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_balance
|
119
|
+
self.exec(:getbalance,{})
|
120
|
+
end
|
121
|
+
|
122
|
+
def public_key
|
123
|
+
@con.public_key
|
124
|
+
end
|
125
|
+
end
|
130
126
|
end
|
data/lib/trade_api/trade_api.rb
CHANGED
@@ -22,7 +22,7 @@ module Coinfloor
|
|
22
22
|
# All method calls return json which is to be sent to the API.
|
23
23
|
class CFcon
|
24
24
|
# coinfloor user trade id, password
|
25
|
-
def initialize(uid,password,pkey=nil)
|
25
|
+
def initialize(uid,password,api_key,pkey=nil)
|
26
26
|
@uid=uid
|
27
27
|
@uid_byte=LibEcp.gen_uid(uid)
|
28
28
|
if pkey
|
@@ -33,7 +33,7 @@ module Coinfloor
|
|
33
33
|
|
34
34
|
end
|
35
35
|
@public_key=LibEcp.gen_pub(@private_key)
|
36
|
-
@cookie=
|
36
|
+
@cookie=api_key
|
37
37
|
@password=nil
|
38
38
|
end
|
39
39
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-trade-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faye-websocket
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.1.
|
37
|
+
version: 0.1.2
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.1.
|
45
|
+
version: 0.1.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: json
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +70,7 @@ files:
|
|
70
70
|
- lib/trade_client.rb
|
71
71
|
- lib/client/client.rb
|
72
72
|
- lib/trade_api/trade_api.rb
|
73
|
-
homepage:
|
73
|
+
homepage: http://coinfloor.co.uk
|
74
74
|
licenses:
|
75
75
|
- APACHE 2.0
|
76
76
|
post_install_message:
|
@@ -94,6 +94,7 @@ rubyforge_project:
|
|
94
94
|
rubygems_version: 1.8.25
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
|
-
summary:
|
97
|
+
summary: An example ruby client library to trade on the Coinfloor platform using their
|
98
|
+
API
|
98
99
|
test_files: []
|
99
100
|
has_rdoc:
|