ftx-api 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +33 -0
- data/lib/ftx/api/base.rb +13 -8
- data/lib/ftx/api/convert.rb +23 -0
- data/lib/ftx/api/private.rb +5 -3
- data/lib/ftx/api/version.rb +1 -1
- data/lib/ftx/api.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c15096ba4fb95095c38eb810ce23e70066ae3e462cd96d25b4793be3ed0457
|
4
|
+
data.tar.gz: 44f47071c91cb4d76a3bf075ae3c4b9e3ad656833936ad7b4cb8e3671908bb33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 687383de76c7e9b00e8cc385cc73a32537d45392253881a56b00d70336021e356cd87a6a3804357a18a1933c6be2a9b69fed2969f6817558a7acf0adbffdede3
|
7
|
+
data.tar.gz: 25a2ea5c354a87a36074759790b3b28af98aae58f3c9109e7bf7489acaebaa969d3e26c4a49005e18788dc246175340a4b532b8666b1e6b12a761c7106810d87
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -154,6 +154,39 @@ Note: the create order method is not included as a test, because I have not been
|
|
154
154
|
|
155
155
|
*Check the [FTX API docs](https://docs.ftx.com/#orders) for all parameters*
|
156
156
|
|
157
|
+
### Convert Coins
|
158
|
+
|
159
|
+
Initialize an convert session:
|
160
|
+
```ruby
|
161
|
+
convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
162
|
+
```
|
163
|
+
|
164
|
+
Create a new quote:
|
165
|
+
```ruby
|
166
|
+
args = {
|
167
|
+
size: 0.01, # 0.01 is the smallest increment
|
168
|
+
fromCoin: "USD",
|
169
|
+
toCoin: "BTC",
|
170
|
+
}
|
171
|
+
|
172
|
+
convert.new_quote(args)
|
173
|
+
```
|
174
|
+
|
175
|
+
Response:
|
176
|
+
```ruby
|
177
|
+
{:quoteId=>2*******3}
|
178
|
+
```
|
179
|
+
|
180
|
+
Fetch a quote:
|
181
|
+
```ruby
|
182
|
+
convert.get_quote('quoteId')
|
183
|
+
```
|
184
|
+
|
185
|
+
Accept a quote:
|
186
|
+
```ruby
|
187
|
+
convert.accept_quote('quoteId')
|
188
|
+
```
|
189
|
+
|
157
190
|
## Development
|
158
191
|
|
159
192
|
After checking out the repo, run `bin/setup` to install dependencies.
|
data/lib/ftx/api/base.rb
CHANGED
@@ -4,11 +4,11 @@ require 'httparty'
|
|
4
4
|
|
5
5
|
class FTX::API::Base
|
6
6
|
|
7
|
+
attr_reader :config, :key, :secret
|
8
|
+
|
7
9
|
include HTTParty
|
8
10
|
base_uri 'https://ftx.com/api'
|
9
11
|
|
10
|
-
attr_reader :config, :key, :secret
|
11
|
-
|
12
12
|
def initialize(args = {})
|
13
13
|
@config = FTX::API::Config.new(args.dig(:config))
|
14
14
|
@key = args.dig(:key)
|
@@ -21,16 +21,21 @@ class FTX::API::Base
|
|
21
21
|
uuid = SecureRandom.uuid
|
22
22
|
print_log(:info, "[API] #{uuid} #{method.upcase} '#{path}' query = #{query}")
|
23
23
|
|
24
|
-
|
24
|
+
if method == :get
|
25
|
+
body_or_query = :query
|
26
|
+
else
|
27
|
+
body_or_query = :body
|
28
|
+
query = query.to_json
|
29
|
+
end
|
25
30
|
|
26
31
|
begin
|
27
32
|
response = self.class.send(
|
28
|
-
method,
|
29
|
-
path,
|
33
|
+
method,
|
34
|
+
path,
|
30
35
|
headers: headers,
|
31
36
|
timeout: @config.timeout,
|
32
|
-
body_or_query => query
|
33
|
-
)
|
37
|
+
body_or_query.to_sym => query
|
38
|
+
)
|
34
39
|
|
35
40
|
print_log(:info, "[API] #{uuid} response #{response}")
|
36
41
|
return parse_response(response)
|
@@ -43,6 +48,7 @@ class FTX::API::Base
|
|
43
48
|
private
|
44
49
|
|
45
50
|
def parse_response(response)
|
51
|
+
response = response.parsed_response
|
46
52
|
if response.dig("success")
|
47
53
|
response.dig("result").symbolize_keys
|
48
54
|
else
|
@@ -54,7 +60,6 @@ class FTX::API::Base
|
|
54
60
|
logger = @config.logger
|
55
61
|
if logger
|
56
62
|
puts "#{method}: #{message}"
|
57
|
-
# logger[method] = message
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'private'
|
4
|
+
|
5
|
+
class FTX::API::Convert < FTX::API::Private
|
6
|
+
|
7
|
+
def new_quote(query = {})
|
8
|
+
raise ArgumentError.new(
|
9
|
+
"Size, fromCoin, toCoin params required"
|
10
|
+
) unless [:fromCoin, :toCoin, :size].all? { |i| query.include? i }
|
11
|
+
|
12
|
+
send_request(:post, "/otc/quotes", query)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_quote(quote_id)
|
16
|
+
send_request(:get, "/otc/quotes/#{quote_id}", {})
|
17
|
+
end
|
18
|
+
|
19
|
+
def accept_quote(quote_id)
|
20
|
+
send_request(:post, "/otc/quotes/#{quote_id}/accept", {})
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/ftx/api/private.rb
CHANGED
@@ -15,6 +15,8 @@ class FTX::API::Private < FTX::API::Base
|
|
15
15
|
'FTX-KEY' => key,
|
16
16
|
'FTX-SIGN' => signature(*args),
|
17
17
|
'FTX-TS' => ts.to_s,
|
18
|
+
'Content-Type' => 'application/json',
|
19
|
+
'Accepts' => 'application/json',
|
18
20
|
}
|
19
21
|
end
|
20
22
|
|
@@ -26,12 +28,12 @@ class FTX::API::Private < FTX::API::Base
|
|
26
28
|
payload = [ts, method.to_s.upcase, "/api", path].compact_empty
|
27
29
|
|
28
30
|
if method==:post
|
29
|
-
payload
|
31
|
+
payload << query.to_json
|
30
32
|
elsif method==:get
|
31
|
-
payload
|
33
|
+
payload << ("?" + URI.encode_www_form(query))
|
32
34
|
end unless query.empty?
|
33
35
|
|
34
|
-
|
36
|
+
payload.join.encode("UTF-8")
|
35
37
|
end
|
36
38
|
|
37
39
|
def ts
|
data/lib/ftx/api/version.rb
CHANGED
data/lib/ftx/api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ftx-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benrs44
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/ftx/api/account.rb
|
64
64
|
- lib/ftx/api/base.rb
|
65
65
|
- lib/ftx/api/config.rb
|
66
|
+
- lib/ftx/api/convert.rb
|
66
67
|
- lib/ftx/api/futures.rb
|
67
68
|
- lib/ftx/api/markets.rb
|
68
69
|
- lib/ftx/api/orders.rb
|