ftx-api 0.2.2 → 0.2.6
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 +4 -4
- data/CHANGELOG.md +19 -1
- data/Gemfile.lock +1 -1
- data/README.md +57 -3
- data/ftx-api.gemspec +1 -1
- data/lib/ext/array.rb +1 -1
- data/lib/ftx/api/base.rb +13 -8
- data/lib/ftx/api/convert.rb +23 -0
- data/lib/ftx/api/fills.rb +11 -0
- data/lib/ftx/api/private.rb +6 -4
- data/lib/ftx/api/version.rb +1 -1
- data/lib/ftx/api.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7845a00bf3bf2a3ad58c8ee65a131008f2bf456683674dd2a664db57f6be89e4
|
4
|
+
data.tar.gz: 0fe0ccbe9faab912eee3250e6610abb499944716a52727e1dbec00d2c2f8a6a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 533647fc948c9b1d9f5c0f331b6c58954c566d6a00bd5d1f6e181eecefcef868e444afc0ba223b3131eb87ae428927642e34a68c2f03dbc700f93f2ecaf301c3
|
7
|
+
data.tar.gz: 18c12550f422a555b90bfecf648a75883e777cc0c033653bbc77ca8543d02cc16188381d937b7d967773c9bd5b503ab39b6cfbc1a5ce1c8e31e560a4d3a24392
|
data/CHANGELOG.md
CHANGED
@@ -4,4 +4,22 @@
|
|
4
4
|
- Initial release
|
5
5
|
|
6
6
|
## [0.2.0] - 2021-09-23
|
7
|
-
- Implement public API covering Markets and Futures only
|
7
|
+
- Implement public API covering Markets and Futures only
|
8
|
+
|
9
|
+
## [0.2.1] - 2021-09-23
|
10
|
+
- Empty
|
11
|
+
|
12
|
+
## [0.2.2] - 2021-10-05
|
13
|
+
- Include private API endpoints with tests
|
14
|
+
|
15
|
+
## [0.2.3] - 2021-10-05
|
16
|
+
- Include private API endpoints with tests - further updates
|
17
|
+
|
18
|
+
## [0.2.4] - 2021-10-05
|
19
|
+
- Fix error compact_blank creates for rails db:migrate
|
20
|
+
|
21
|
+
## [0.2.5] - 2021-10-06
|
22
|
+
- Fix issues with post methods and add Convert endpoint
|
23
|
+
|
24
|
+
## [0.2.6] - 2021-10-06
|
25
|
+
- Implement Fills endpoint including tests
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ This gem is a ruby SDK for the FTX crypto exchange REST API.
|
|
4
4
|
|
5
5
|
API docs can be found on the [FTX developer site](https://docs.ftx.com/)
|
6
6
|
|
7
|
-
It is still under development and currently only covers the markets and futures endpoints.
|
8
|
-
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -154,9 +152,65 @@ Note: the create order method is not included as a test, because I have not been
|
|
154
152
|
|
155
153
|
*Check the [FTX API docs](https://docs.ftx.com/#orders) for all parameters*
|
156
154
|
|
155
|
+
### Fills
|
156
|
+
|
157
|
+
Initialize an fills session:
|
158
|
+
```ruby
|
159
|
+
fills = FXT::API::Orders.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
160
|
+
```
|
161
|
+
|
162
|
+
Query for all fills:
|
163
|
+
```ruby
|
164
|
+
fills.list
|
165
|
+
```
|
166
|
+
or
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
fills.list(market: 'BTC/USD')
|
170
|
+
```
|
171
|
+
|
172
|
+
Note: market is optional
|
173
|
+
|
174
|
+
### Convert Coins
|
175
|
+
|
176
|
+
Initialize an convert session:
|
177
|
+
```ruby
|
178
|
+
convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
179
|
+
```
|
180
|
+
|
181
|
+
Create a new quote:
|
182
|
+
```ruby
|
183
|
+
args = {
|
184
|
+
size: 0.01, # 0.01 is the smallest increment
|
185
|
+
fromCoin: "USD",
|
186
|
+
toCoin: "BTC",
|
187
|
+
}
|
188
|
+
|
189
|
+
convert.new_quote(args)
|
190
|
+
```
|
191
|
+
|
192
|
+
Response:
|
193
|
+
```ruby
|
194
|
+
{:quoteId=>2*******3}
|
195
|
+
```
|
196
|
+
|
197
|
+
Fetch a quote:
|
198
|
+
```ruby
|
199
|
+
convert.get_quote('quoteId')
|
200
|
+
```
|
201
|
+
|
202
|
+
Accept a quote:
|
203
|
+
```ruby
|
204
|
+
convert.accept_quote('quoteId')
|
205
|
+
```
|
206
|
+
|
157
207
|
## Development
|
158
208
|
|
159
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
209
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
210
|
+
|
211
|
+
You'll then need to add environment variables `ENV['FTX_KEY']` and `ENV['FTX_SECRET']`. API keys can be created in your [FTX settings page](https://ftx.com/profile).
|
212
|
+
|
213
|
+
Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
160
214
|
|
161
215
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
162
216
|
|
data/ftx-api.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "Ruby gem for the FTX Exchange API"
|
13
13
|
spec.homepage = "https://github.com/benrs44/ftx-api"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 3.0.
|
15
|
+
spec.required_ruby_version = ">= 3.0.1"
|
16
16
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
18
|
|
data/lib/ext/array.rb
CHANGED
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
|
|
@@ -23,15 +25,15 @@ class FTX::API::Private < FTX::API::Base
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def signature_payload(method, path, query)
|
26
|
-
payload = [ts, method.to_s.upcase, "/api", path].
|
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
@@ -3,7 +3,9 @@ require_relative "../ext/base"
|
|
3
3
|
require_relative "api/version"
|
4
4
|
require_relative "api/config"
|
5
5
|
require_relative "api/markets"
|
6
|
+
require_relative "api/futures"
|
6
7
|
require_relative "api/account"
|
7
8
|
require_relative "api/wallet"
|
8
9
|
require_relative "api/orders"
|
9
|
-
require_relative "api/
|
10
|
+
require_relative "api/fills"
|
11
|
+
require_relative "api/convert"
|
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.6
|
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,8 @@ 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
|
67
|
+
- lib/ftx/api/fills.rb
|
66
68
|
- lib/ftx/api/futures.rb
|
67
69
|
- lib/ftx/api/markets.rb
|
68
70
|
- lib/ftx/api/orders.rb
|
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
87
|
requirements:
|
86
88
|
- - ">="
|
87
89
|
- !ruby/object:Gem::Version
|
88
|
-
version: 3.0.
|
90
|
+
version: 3.0.1
|
89
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
92
|
requirements:
|
91
93
|
- - ">="
|