ftx-api 0.2.4 → 0.2.8
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 +25 -1
- data/Gemfile.lock +2 -2
- data/README.md +94 -8
- data/lib/ftx/api/base.rb +15 -10
- data/lib/ftx/api/convert.rb +23 -0
- data/lib/ftx/api/fills.rb +11 -0
- data/lib/ftx/api/funding.rb +15 -0
- data/lib/ftx/api/futures.rb +8 -0
- data/lib/ftx/api/orders.rb +4 -0
- data/lib/ftx/api/private.rb +5 -3
- data/lib/ftx/api/version.rb +1 -1
- data/lib/ftx/api.rb +4 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034ffdddca45eba8aefa59494ee718e329324b637f50585412eea9500a17011f
|
4
|
+
data.tar.gz: 6a19fc208851effb64df469a145d6ac76a94ea3ad6b2b4c338f07d99b7de57dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e04b01cdc2240f3a69d8f3f7d2751d02f932fca080ee118918444a63b33b498cef423a090eaeeb5537244cb0513107a82e88ab9dc120f0e738df1c6465359d06
|
7
|
+
data.tar.gz: e8edc6cceb16276c0803185f1f025256e5b419d880dffc8487f53a1195e1b715b00cccc391be790229b8ba49d3c403fb1e2e03e1a54a6848654c39a9abb0190d
|
data/CHANGELOG.md
CHANGED
@@ -4,4 +4,28 @@
|
|
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
|
26
|
+
|
27
|
+
## [0.2.7] - 2021-10-06
|
28
|
+
- Implement orders get_by_client_id endpoint
|
29
|
+
|
30
|
+
## [0.2.8] - 2021-10-18
|
31
|
+
- Implement funding endpoints
|
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
|
|
@@ -25,7 +23,7 @@ Or install it yourself as:
|
|
25
23
|
|
26
24
|
## Usage
|
27
25
|
|
28
|
-
### Markets
|
26
|
+
### Markets (public)
|
29
27
|
|
30
28
|
Initialize a markets session:
|
31
29
|
```ruby
|
@@ -53,9 +51,9 @@ markets.historic('BTC/USD', resolution: 86400*30)
|
|
53
51
|
```
|
54
52
|
*Check the [FTX API docs](https://docs.ftx.com/?python#get-historical-prices) for additional parameters such as start_time and end_time*
|
55
53
|
|
56
|
-
Note: resolution is in seconds so 86,400 would be the number of seconds in a day. As a default, the API responds with 12 months of historical prices.
|
54
|
+
> Note: resolution is in seconds so 86,400 would be the number of seconds in a day. As a default, the API responds with 12 months of historical prices.
|
57
55
|
|
58
|
-
### Futures
|
56
|
+
### Futures (public)
|
59
57
|
|
60
58
|
Initialize a futures session:
|
61
59
|
```ruby
|
@@ -72,6 +70,18 @@ Fetch a single market price:
|
|
72
70
|
futures.get('BTC-PERP')
|
73
71
|
```
|
74
72
|
|
73
|
+
Fetch stats for a future:
|
74
|
+
```ruby
|
75
|
+
futures.stats('BTC-PERP')
|
76
|
+
```
|
77
|
+
|
78
|
+
Fetch all or one funding rates:
|
79
|
+
```ruby
|
80
|
+
futures.funding_rates(future: 'BTC-PERP')
|
81
|
+
```
|
82
|
+
|
83
|
+
> Note: future is optional, start_time and end_time are also accepted per the FTX API docs
|
84
|
+
|
75
85
|
### Account
|
76
86
|
|
77
87
|
Initialize an account session:
|
@@ -128,9 +138,14 @@ Query for all historical orders:
|
|
128
138
|
orders.history
|
129
139
|
```
|
130
140
|
|
131
|
-
Fetch a specific order
|
141
|
+
Fetch a specific order by FTX `orderId`:
|
142
|
+
```ruby
|
143
|
+
orders.get(order_id)
|
144
|
+
```
|
145
|
+
|
146
|
+
Fetch a specific order by `clientId`:
|
132
147
|
```ruby
|
133
|
-
orders.
|
148
|
+
orders.get_by_client_id(clientId)
|
134
149
|
```
|
135
150
|
|
136
151
|
Create a new order:
|
@@ -150,10 +165,81 @@ args = {
|
|
150
165
|
orders.create(args)
|
151
166
|
```
|
152
167
|
|
153
|
-
Note: the create order method is not included as a test, because I have not been able to find FTX test keys and it seems a bit ridiculous to execute a live order for testing.
|
168
|
+
> Note: the create order method is not included as a test, because I have not been able to find FTX test keys and it seems a bit ridiculous to execute a live order for testing.
|
154
169
|
|
155
170
|
*Check the [FTX API docs](https://docs.ftx.com/#orders) for all parameters*
|
156
171
|
|
172
|
+
### Fills
|
173
|
+
|
174
|
+
Initialize a fills session:
|
175
|
+
```ruby
|
176
|
+
fills = FXT::API::Fills.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
177
|
+
```
|
178
|
+
|
179
|
+
Query for all fills:
|
180
|
+
```ruby
|
181
|
+
fills.list
|
182
|
+
```
|
183
|
+
or
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
fills.list(market: 'BTC/USD')
|
187
|
+
```
|
188
|
+
|
189
|
+
> Note: market is optional
|
190
|
+
|
191
|
+
### Funding
|
192
|
+
|
193
|
+
Initialize a funding session:
|
194
|
+
```ruby
|
195
|
+
funding = FXT::API::Funding.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
196
|
+
```
|
197
|
+
|
198
|
+
Query for all or one funding payments:
|
199
|
+
```ruby
|
200
|
+
funding.payments(future: 'BTC-PERP')
|
201
|
+
```
|
202
|
+
|
203
|
+
Query for all or one funding rates:
|
204
|
+
```ruby
|
205
|
+
funding.rates(future: 'BTC-PERP')
|
206
|
+
```
|
207
|
+
|
208
|
+
> Note: future is optional, start_time and end_time are also accepted per the FTX API docs
|
209
|
+
|
210
|
+
### Convert Coins
|
211
|
+
|
212
|
+
Initialize an convert session:
|
213
|
+
```ruby
|
214
|
+
convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
|
215
|
+
```
|
216
|
+
|
217
|
+
Create a new quote:
|
218
|
+
```ruby
|
219
|
+
args = {
|
220
|
+
size: 0.01, # 0.01 is the smallest increment
|
221
|
+
fromCoin: "USD",
|
222
|
+
toCoin: "BTC",
|
223
|
+
}
|
224
|
+
|
225
|
+
convert.new_quote(args)
|
226
|
+
```
|
227
|
+
|
228
|
+
Response:
|
229
|
+
```ruby
|
230
|
+
{:quoteId=>2*******3}
|
231
|
+
```
|
232
|
+
|
233
|
+
Fetch a quote:
|
234
|
+
```ruby
|
235
|
+
convert.get_quote('quoteId')
|
236
|
+
```
|
237
|
+
|
238
|
+
Accept a quote:
|
239
|
+
```ruby
|
240
|
+
convert.accept_quote('quoteId')
|
241
|
+
```
|
242
|
+
|
157
243
|
## Development
|
158
244
|
|
159
245
|
After checking out the repo, run `bin/setup` to install dependencies.
|
data/lib/ftx/api/base.rb
CHANGED
@@ -4,15 +4,15 @@ 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
|
-
@key = args.
|
15
|
-
@secret = args.
|
14
|
+
@key = args.fetch(:key, ENV['FTX_KEY'])
|
15
|
+
@secret = args.fetch(:secret, ENV['FTX_SECRET'])
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
@@ -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
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'private'
|
4
|
+
|
5
|
+
class FTX::API::Funding < FTX::API::Private
|
6
|
+
|
7
|
+
def payments(query = {})
|
8
|
+
send_request(:get, '/funding_payments', query)
|
9
|
+
end
|
10
|
+
|
11
|
+
def rates(query = {})
|
12
|
+
send_request(:get, '/funding_rates', query)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/ftx/api/futures.rb
CHANGED
@@ -11,5 +11,13 @@ class FTX::API::Futures < FTX::API::Public
|
|
11
11
|
def get(futures_name)
|
12
12
|
send_request(:get, "/futures/#{futures_name}", {})
|
13
13
|
end
|
14
|
+
|
15
|
+
def stats(futures_name)
|
16
|
+
send_request(:get, "/futures/#{futures_name}/stats", {})
|
17
|
+
end
|
18
|
+
|
19
|
+
def funding_rates(query = {})
|
20
|
+
send_request(:get, '/funding_rates', query)
|
21
|
+
end
|
14
22
|
|
15
23
|
end
|
data/lib/ftx/api/orders.rb
CHANGED
@@ -16,6 +16,10 @@ class FTX::API::Orders < FTX::API::Private
|
|
16
16
|
send_request(:get, "/orders/#{order_id}", {})
|
17
17
|
end
|
18
18
|
|
19
|
+
def get_by_client_id(client_id)
|
20
|
+
send_request(:get, "/orders/by_client_id/#{client_id}", {})
|
21
|
+
end
|
22
|
+
|
19
23
|
def create(query = {})
|
20
24
|
raise ArgumentError.new(
|
21
25
|
"Market, side, price (can be nil), tupe and size params required"
|
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
@@ -3,7 +3,10 @@ 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/funding"
|
12
|
+
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.8
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -63,6 +63,9 @@ 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
|
68
|
+
- lib/ftx/api/funding.rb
|
66
69
|
- lib/ftx/api/futures.rb
|
67
70
|
- lib/ftx/api/markets.rb
|
68
71
|
- lib/ftx/api/orders.rb
|