Access the Gate API with Ruby.
Add this line to your application's Gemfile:
gem 'gate.rb'And then execute:
$ bundle install
Or install it yourself as:
$ gem install gate.rb
client = Gate::Client.new(
api_key: 'your_api_key',
api_secret: 'your_api_secret',
)Everything a client uses is given to it: api_key:, api_secret:, debug: and logger:. Each has a
setter of its own, and the client is yielded while it is being built, so these are the same:
client = Gate::Client.new do |c|
c.api_key = 'your_api_key'
c.api_secret = 'your_api_secret'
end
client = Gate::Client.new
client.api_key = 'your_api_key'
client.api_secret = 'your_api_secret'The client keeps nothing in common with any other, and reads nothing from the environment or from a file: where the settings come from is the program's business. Credentials not given raise at the first request, before anything is sent, naming each of them:
Gate::Client.new(api_key: 'your_api_key').spot_time
# => ArgumentError: api_secret is missing.Before 0.3.0 the settings could be declared once with Gate.configure, and every client
fell back upon them, or be given as a Gate::Configuration under configuration:. Pass them
to each client as keywords instead.
A client logs when it has somewhere to log to, and not at all when it does not. Hand it any
object answering to #info and #error; the standard library's Logger will do.
A request is logged with its headers, the key being written as [FILTERED].
require 'logger'
client = Gate::Client.new(
api_key: 'your_api_key',
api_secret: 'your_api_secret',
logger: Logger.new($stdout)
)# Get all currencies
client.spot_currencies
# Get specific currency
client.spot_currencies('BTC')
# Get all symbol/currency pairs
client.spot_currency_pairs
# Get one symbol/currency pair
client.spot_currency_pairs('BTC_USDT')
# Get all ticker
client.spot_tickers
# Get ticker for one symbol/currency pair
client.spot_tickers(currency_pair: 'BTC_USDT')
# Get order book for a symbol/currency pair
client.spot_order_book(currency_pair: 'BTC_USDT')
# Get trades for a symbol/currency pair
client.spot_trades(currency_pair: 'BTC_USDT')
# Get OHLC for a symbol/currency pair
client.spot_candlesticks(currency_pair: 'BTC_USDT')
# Get OHLC for a symbol for specific period
client.spot_candlesticks(currency_pair: 'BTC_USDT', interval: '1d', from: 1648995780, to: 1649082180)
# Get server time
client.spot_time# Get the authenticated user's balance
client.wallet_total_balance(currency: 'USDT')
# Place an order for a symbol/currency pair
client.spot_orders(currency_pair: 'BTC_USDT', side: 'buy', amount: '0.0001', price: '100000')
# Get the authenticated user's trades for a symbol/currency pair
client.spot_my_trades(currency_pair: 'BTC_USDT')- Fork it (https://github.com/thoran/gate/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new pull request
The gem is available as open source under the terms of the Ruby License.