cf-trade-client 0.1.9 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/client/client.rb +36 -53
- data/lib/trade_api/trade_api.rb +72 -67
- data/lib/trade_client.rb +0 -16
- metadata +43 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e90e17269fa8e89671639959552dff79f388e655
|
4
|
+
data.tar.gz: 87f02f75a2485d8595e8fb6ab862c34179c34b46
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2928593e151240c5d61b8b80769ba326de82cf826304006ddbcf2859fccb0f5e23b5f94d97665070cbad5cd852c6c8aac0b7ecb00dad5df4fb61e0cd84b4326a
|
7
|
+
data.tar.gz: b31e3bbaf441ac1b2fa2c523f4c31c33e4ea8ef261d898d1d3b985122ab23d01e3d44387d04005e22099d59eb1e4d92d7815459df115f560583721c9f6c9cf4c
|
data/lib/client/client.rb
CHANGED
@@ -1,86 +1,71 @@
|
|
1
|
-
|
2
|
-
Copyright 2014 Coinfloor LTD.
|
1
|
+
require "faye/websocket"
|
3
2
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
=end
|
16
|
-
require 'faye/websocket'
|
17
3
|
module Coinfloor
|
18
4
|
class CFClient
|
19
|
-
def initialize(domain,uid,pass,api_key=nil,pkey=nil)
|
20
|
-
if domain.include?("ws://")||domain.include?("wss://")
|
21
|
-
@messages=[]
|
22
|
-
if uid==0
|
23
|
-
@con=CFAcon.new(uid,pass)
|
5
|
+
def initialize(domain, uid, pass, api_key = nil, pkey = nil)
|
6
|
+
if domain.include?("ws://") || domain.include?("wss://")
|
7
|
+
@messages = []
|
8
|
+
if uid == 0
|
9
|
+
@con = CFAcon.new(uid, pass)
|
24
10
|
else
|
25
11
|
if api_key.nil?
|
26
12
|
abort("An API key is required")
|
27
13
|
elsif pkey
|
28
|
-
@con=CFcon.new(uid,pass,api_key,pkey)
|
14
|
+
@con = CFcon.new(uid, pass, api_key, pkey)
|
29
15
|
else
|
30
|
-
@con=CFcon.new(uid,pass,api_key)
|
16
|
+
@con = CFcon.new(uid, pass, api_key)
|
31
17
|
end
|
32
18
|
end
|
33
|
-
@domain=domain
|
19
|
+
@domain = domain
|
34
20
|
else
|
35
21
|
puts "domain must be a ws:// or wss:// formatted string, if port is not 80 it must be specified"
|
36
22
|
end
|
37
|
-
|
38
23
|
end
|
39
|
-
|
24
|
+
|
25
|
+
def auth(ws, msg)
|
40
26
|
@messages.push(:auth)
|
41
|
-
nonce=msg["nonce"]
|
42
|
-
result
|
27
|
+
nonce = msg["nonce"]
|
28
|
+
result = @con.auth(nonce)
|
43
29
|
ws.send(result)
|
44
30
|
end
|
45
|
-
|
31
|
+
|
46
32
|
def begin_connection(sendata)
|
47
33
|
puts "begining connection"
|
48
|
-
output=nil
|
34
|
+
output = nil
|
49
35
|
EM.run {
|
50
36
|
ws = Faye::WebSocket::Client.new(@domain)
|
51
37
|
ws.on :open do |event|
|
52
38
|
end
|
53
|
-
|
39
|
+
|
54
40
|
ws.on :message do |event|
|
55
|
-
|
56
|
-
|
57
|
-
msg=JSON.parse(evtdata)
|
41
|
+
evtdata = event.data
|
42
|
+
msg = JSON.parse(evtdata)
|
58
43
|
puts msg
|
59
|
-
if msg["notice"]&&msg["notice"]=="Welcome"
|
60
|
-
auth(ws,msg)
|
44
|
+
if msg["notice"] && msg["notice"] == "Welcome"
|
45
|
+
auth(ws, msg)
|
61
46
|
elsif msg["notice"].nil?
|
62
|
-
ret_msg
|
47
|
+
ret_msg = @messages.delete_at(0)
|
63
48
|
case ret_msg
|
64
49
|
when nil
|
65
50
|
ws.close
|
66
|
-
ws=nil
|
51
|
+
ws = nil
|
67
52
|
EM.stop
|
68
53
|
when :auth
|
69
|
-
if msg["error_code"]==0
|
54
|
+
if msg["error_code"] == 0
|
70
55
|
@messages.push(:reply)
|
71
56
|
ws.send(sendata)
|
72
57
|
else
|
73
58
|
ws.close
|
74
|
-
ws=nil
|
59
|
+
ws = nil
|
75
60
|
EM.stop
|
76
61
|
end
|
77
62
|
when :reply
|
78
|
-
if msg["error_code"]==0
|
79
|
-
output=msg
|
63
|
+
if msg["error_code"] == 0
|
64
|
+
output = msg
|
80
65
|
ws.close
|
81
66
|
EM.stop
|
82
67
|
else
|
83
|
-
output=msg
|
68
|
+
output = msg
|
84
69
|
ws.close
|
85
70
|
EM.stop
|
86
71
|
end
|
@@ -97,13 +82,13 @@ module Coinfloor
|
|
97
82
|
else
|
98
83
|
raise "Somethings gone wrong with the client"
|
99
84
|
end
|
100
|
-
end
|
101
|
-
|
85
|
+
end
|
86
|
+
|
102
87
|
ws.on :error do |event|
|
103
88
|
EM.stop
|
104
89
|
ws = nil
|
105
90
|
end
|
106
|
-
|
91
|
+
|
107
92
|
ws.on :close do |event|
|
108
93
|
EM.stop
|
109
94
|
ws = nil
|
@@ -111,18 +96,16 @@ module Coinfloor
|
|
111
96
|
}
|
112
97
|
return output
|
113
98
|
end
|
114
|
-
|
115
|
-
def exec(cfcon_method,
|
116
|
-
|
117
|
-
data=@con.send(cfcon_method.to_s,arguments)
|
118
|
-
|
99
|
+
|
100
|
+
def exec(cfcon_method, args)
|
101
|
+
data = @con.send(cfcon_method.to_s, args)
|
119
102
|
begin_connection(data)
|
120
103
|
end
|
121
|
-
|
104
|
+
|
122
105
|
def get_balance
|
123
|
-
self.exec(:getbalance,{})
|
106
|
+
self.exec(:getbalance, {})
|
124
107
|
end
|
125
|
-
|
108
|
+
|
126
109
|
def public_key
|
127
110
|
@con.public_key
|
128
111
|
end
|
data/lib/trade_api/trade_api.rb
CHANGED
@@ -1,106 +1,111 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
=end
|
16
|
-
|
17
|
-
require 'libecp'
|
18
|
-
require 'json'
|
1
|
+
require "json"
|
2
|
+
require "libecp"
|
19
3
|
|
20
4
|
module Coinfloor
|
21
|
-
# The Coinfloor trade API
|
22
|
-
# All method calls return json which is to be sent to the API.
|
23
5
|
class CFcon
|
24
6
|
# coinfloor user trade id, password
|
25
|
-
def initialize(uid,password,api_key,pkey=nil)
|
26
|
-
@uid=uid
|
27
|
-
@uid_byte=LibEcp.gen_uid(uid)
|
7
|
+
def initialize(uid, password, api_key, pkey = nil)
|
8
|
+
@uid = uid
|
9
|
+
@uid_byte = LibEcp.gen_uid(uid)
|
10
|
+
|
28
11
|
if pkey
|
29
|
-
@private_key=pkey
|
12
|
+
@private_key = pkey
|
30
13
|
else
|
31
|
-
@password=password
|
32
|
-
@private_key=LibEcp.private_key(@uid_byte,password)
|
33
|
-
|
14
|
+
@password = password
|
15
|
+
@private_key = LibEcp.private_key(@uid_byte, password)
|
34
16
|
end
|
35
|
-
|
36
|
-
@
|
37
|
-
@
|
17
|
+
|
18
|
+
@public_key = LibEcp.gen_pub(@private_key)
|
19
|
+
@cookie = api_key
|
20
|
+
@password = nil
|
38
21
|
end
|
39
22
|
|
40
|
-
attr_reader
|
23
|
+
attr_reader :public_key
|
41
24
|
|
42
|
-
# Authenticate using your generated private key, pass in the nonce given by
|
25
|
+
# Authenticate using your generated private key, pass in the nonce given by
|
26
|
+
# the server on initial authenticate open.
|
43
27
|
def auth(server_nonce)
|
44
|
-
nonce=LibEcp.gen_nonce
|
45
|
-
while nonce.bytes.count==15
|
46
|
-
nonce=LibEcp.gen_nonce
|
28
|
+
nonce = LibEcp.gen_nonce
|
29
|
+
while nonce.bytes.count == 15
|
30
|
+
nonce = LibEcp.gen_nonce
|
47
31
|
end
|
48
|
-
|
32
|
+
|
33
|
+
sigs = LibEcp.sign(@uid_byte, Base64.decode64(server_nonce), nonce, @private_key)
|
49
34
|
{
|
50
|
-
"method"=>"Authenticate",
|
51
|
-
"user_id"
|
52
|
-
"cookie"
|
53
|
-
"nonce"=>Base64.encode64(nonce).rstrip,
|
54
|
-
"signature"=>[Base64.encode64(sigs[0]).rstrip,Base64.encode64(sigs[1]).rstrip]
|
35
|
+
"method" => "Authenticate",
|
36
|
+
"user_id" => @uid,
|
37
|
+
"cookie" => @cookie,
|
38
|
+
"nonce" => Base64.encode64(nonce).rstrip,
|
39
|
+
"signature" => [Base64.encode64(sigs[0]).rstrip, Base64.encode64(sigs[1]).rstrip]
|
55
40
|
}.to_json.gsub(/\s+/, "")
|
56
41
|
end
|
57
42
|
|
58
|
-
# Cancels users existing order
|
43
|
+
# Cancels users existing order.
|
59
44
|
def cancelorder(args)
|
60
45
|
{
|
61
|
-
:method=>"CancelOrder",
|
62
|
-
:id=>args[:id]
|
46
|
+
:method => "CancelOrder",
|
47
|
+
:id => args[:id],
|
63
48
|
}.to_json
|
64
49
|
end
|
65
50
|
|
66
|
-
#
|
67
|
-
def getbalance(args={})
|
51
|
+
# Return any available balance.
|
52
|
+
def getbalance(args = {})
|
68
53
|
{
|
69
|
-
:method=> "GetBalances"
|
54
|
+
:method => "GetBalances",
|
70
55
|
}.to_json
|
71
56
|
end
|
72
57
|
|
73
|
-
#
|
74
|
-
def getorders(args={})
|
58
|
+
# Return a list of open orders.
|
59
|
+
def getorders(args = {})
|
75
60
|
{
|
76
|
-
:method=> "GetOrders"
|
61
|
+
:method => "GetOrders",
|
77
62
|
}.to_json
|
78
63
|
end
|
79
64
|
|
80
|
-
# Place an order
|
81
|
-
|
82
|
-
|
83
|
-
|
65
|
+
# Place an order.
|
66
|
+
def placeorder(args)
|
67
|
+
{
|
68
|
+
:method => "PlaceOrder",
|
69
|
+
:base => args[:base_asset_id],
|
70
|
+
:counter => args[:counter_asset_id],
|
71
|
+
:quantity => args[:quantity],
|
72
|
+
:price => args[:price],
|
73
|
+
:total => args[:total],
|
74
|
+
}.delete_if { |k, v| v.nil? }.to_json
|
75
|
+
end
|
84
76
|
|
77
|
+
# Gets a copy of the orderbook, does not subscribe.
|
78
|
+
# The subscription connection is not working because we are not doing a
|
79
|
+
# continious conection.
|
80
|
+
def orderbook(args)
|
85
81
|
{
|
86
|
-
:method
|
87
|
-
:base
|
88
|
-
:counter =>
|
89
|
-
:
|
90
|
-
|
91
|
-
}.delete_if { |k, v| v.nil? }.to_json #removes empty values that might not be given as arguments
|
82
|
+
:method => "WatchOrders",
|
83
|
+
:base => args[:base_asset_id],
|
84
|
+
:counter => args[:counter_asset_id],
|
85
|
+
:watch => true,
|
86
|
+
}.to_json
|
92
87
|
end
|
93
88
|
|
94
|
-
#
|
95
|
-
|
89
|
+
# Simulates the execution of a market order and returns the quantity and
|
90
|
+
# total that would have been traded. This estimation does not take into
|
91
|
+
# account trading fees.
|
92
|
+
def estimatemarketorder(args)
|
96
93
|
{
|
97
|
-
:method
|
98
|
-
:base
|
99
|
-
:counter
|
100
|
-
:
|
94
|
+
:method => "EstimateMarketOrder",
|
95
|
+
:base => args[:base_asset_id],
|
96
|
+
:counter => args[:counter_asset_id],
|
97
|
+
:quantity => args[:quantity],
|
98
|
+
:total => args[:total],
|
101
99
|
}.to_json
|
102
100
|
end
|
103
|
-
end
|
104
101
|
|
102
|
+
# Retrieves the 30-day trailing trade volume for the authenticated user.
|
103
|
+
def gettradevolume(args)
|
104
|
+
{
|
105
|
+
:method => "GetTradeVolume",
|
106
|
+
:asset => args[:asset_id],
|
107
|
+
}.to_json
|
108
|
+
end
|
109
|
+
end
|
105
110
|
end
|
106
111
|
|
data/lib/trade_client.rb
CHANGED
@@ -1,18 +1,2 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright 2014 Coinfloor LTD.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
=end
|
16
|
-
|
17
1
|
require 'trade_api/trade_api'
|
18
2
|
require 'client/client'
|
metadata
CHANGED
@@ -1,100 +1,106 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-trade-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
- Coinfloor
|
7
|
+
- Coinfloor LTD
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: cf-ruby-libecp
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
19
|
+
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.4
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.4
|
30
33
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
34
|
+
name: faye-websocket
|
32
35
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
36
|
requirements:
|
35
|
-
- - ~>
|
37
|
+
- - "~>"
|
36
38
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
39
|
+
version: '0.7'
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.7.2
|
38
43
|
type: :runtime
|
39
44
|
prerelease: false
|
40
45
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
46
|
requirements:
|
43
|
-
- - ~>
|
47
|
+
- - "~>"
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
49
|
+
version: '0.7'
|
50
|
+
- - '='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.7.2
|
46
53
|
- !ruby/object:Gem::Dependency
|
47
54
|
name: json
|
48
55
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
56
|
requirements:
|
51
|
-
- - ~>
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.8'
|
60
|
+
- - ">="
|
52
61
|
- !ruby/object:Gem::Version
|
53
62
|
version: 1.8.1
|
54
63
|
type: :runtime
|
55
64
|
prerelease: false
|
56
65
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
66
|
requirements:
|
59
|
-
- - ~>
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.8'
|
70
|
+
- - ">="
|
60
71
|
- !ruby/object:Gem::Version
|
61
72
|
version: 1.8.1
|
62
|
-
description:
|
63
|
-
API, it uses EventMachine and Faye websockets library as well as depending on the
|
64
|
-
coinfloor libecp gem
|
73
|
+
description: Client to trade on the Coinfloor platform using their API.
|
65
74
|
email: development@coinfloor.co.uk
|
66
75
|
executables: []
|
67
76
|
extensions: []
|
68
77
|
extra_rdoc_files: []
|
69
78
|
files:
|
70
|
-
- lib/trade_client.rb
|
71
79
|
- lib/client/client.rb
|
72
80
|
- lib/trade_api/trade_api.rb
|
73
|
-
|
81
|
+
- lib/trade_client.rb
|
82
|
+
homepage: https://github.com/coinfloor/ruby-client
|
74
83
|
licenses:
|
75
|
-
-
|
84
|
+
- Apache License Version 2.0
|
85
|
+
metadata: {}
|
76
86
|
post_install_message:
|
77
87
|
rdoc_options: []
|
78
88
|
require_paths:
|
79
89
|
- lib
|
80
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
91
|
requirements:
|
83
|
-
- -
|
92
|
+
- - ">="
|
84
93
|
- !ruby/object:Gem::Version
|
85
94
|
version: 1.9.3
|
86
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
96
|
requirements:
|
89
|
-
- -
|
97
|
+
- - ">="
|
90
98
|
- !ruby/object:Gem::Version
|
91
99
|
version: '0'
|
92
100
|
requirements: []
|
93
101
|
rubyforge_project:
|
94
|
-
rubygems_version:
|
102
|
+
rubygems_version: 2.4.1
|
95
103
|
signing_key:
|
96
|
-
specification_version:
|
97
|
-
summary:
|
98
|
-
API
|
104
|
+
specification_version: 4
|
105
|
+
summary: Ruby Coinfloor Client
|
99
106
|
test_files: []
|
100
|
-
has_rdoc:
|