This gem is a ruby SDK for the FTX crypto exchange REST API.
API docs can be found on the FTX developer site
Add this line to your application's Gemfile:
gem 'ftx-api'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ftx-api
Initialize a markets session:
markets = FXT::API::Markets.new
Query for all current prices:
markets.list
Fetch a single market price:
markets.get('BTC/USD')
Check for market depth:
markets.orderbook('BTC/USD', depth: 3)
View historic prices:
markets.historic('BTC/USD', resolution: 86400*30)
Check the FTX API docs for additional parameters such as start_time and end_time
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.
Initialize a futures session:
futures = FXT::API::Futures.new
Query for all current prices:
futures.list
Fetch a single market price:
futures.get('BTC-PERP')
Fetch stats for a future:
futures.stats('BTC-PERP')
Fetch all or one funding rates:
futures.funding_rates(future: 'BTC-PERP')
Note: future is optional, start_time and end_time are also accepted per the FTX API docs
Initialize an account session:
account = FXT::API::Account.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Fetch information about account associated with key/secret:
account.get
Query for all current account positions:
account.positions
Initialize a wallet session:
wallet = FXT::API::Wallet.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Query for all available coins:
wallet.coins
Query for all current coin balances in your account:
wallet.balances
Query for all current coin balances split into a hash by subaccount:
wallet.all_balances
Initialize an orders session:
orders = FXT::API::Orders.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Query for all open orders:
orders.open
Query for all historical orders:
orders.history
Fetch a specific order by FTX orderId
:
orders.get(order_id)
Fetch a specific order by clientId
:
orders.get_by_client_id(clientId)
Create a new order:
args = {
market: "XRP-PERP", # coin or futures name
side: "sell", # "buy" or "sell"
price: 0.306525, # Send nil for market orders.
type: "limit", # "limit" or "market"
size: 31431.0,
reduceOnly: false, # optional; default is false
ioc: false, # optional; default is false
postOnly: false, # optional; default is false
clientId: nil # optional; client order id
}
orders.create(args)
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.
Check the FTX API docs for all parameters
Initialize a fills session:
fills = FXT::API::Fills.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Query for all fills:
fills.list
or
fills.list(market: 'BTC/USD')
Note: market is optional
Initialize a funding session:
funding = FXT::API::Funding.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Query for all or one funding payments:
funding.payments(future: 'BTC-PERP')
Query for all or one funding rates:
funding.rates(future: 'BTC-PERP')
Note: future is optional, start_time and end_time are also accepted per the FTX API docs
Initialize an convert session:
convert = FXT::API::Convert.new(key: 'YOUR FTX KEY', secret: 'YOUR FTX SECRET')
Create a new quote:
args = {
size: 0.01, # 0.01 is the smallest increment
fromCoin: "USD",
toCoin: "BTC",
}
convert.new_quote(args)
Response:
{:quoteId=>2*******3}
Fetch a quote:
convert.get_quote('quoteId')
Accept a quote:
convert.accept_quote('quoteId')
After checking out the repo, run bin/setup
to install dependencies.
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.
Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/benrs44/ftx-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Ftx::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.