gemini-rb 0.0.1
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 +7 -0
- data/lib/gemini/api_versions.rb +7 -0
- data/lib/gemini/authenticated_rest.rb +58 -0
- data/lib/gemini/client.rb +38 -0
- data/lib/gemini/configurable.rb +48 -0
- data/lib/gemini/connection.rb +52 -0
- data/lib/gemini/errors.rb +35 -0
- data/lib/gemini/v1/account_info.rb +38 -0
- data/lib/gemini/v1/deposit.rb +23 -0
- data/lib/gemini/v1/funding_book.rb +18 -0
- data/lib/gemini/v1/historical_data.rb +53 -0
- data/lib/gemini/v1/lends.rb +18 -0
- data/lib/gemini/v1/margin_funding.rb +103 -0
- data/lib/gemini/v1/orderbook.rb +36 -0
- data/lib/gemini/v1/orders.rb +121 -0
- data/lib/gemini/v1/positions.rb +27 -0
- data/lib/gemini/v1/stats.rb +15 -0
- data/lib/gemini/v1/symbols.rb +22 -0
- data/lib/gemini/v1/ticker.rb +27 -0
- data/lib/gemini/v1/trades.rb +31 -0
- data/lib/gemini/v1/wallet.rb +98 -0
- data/lib/gemini/v2/margin.rb +34 -0
- data/lib/gemini/v2/personal.rb +94 -0
- data/lib/gemini/v2/stats.rb +27 -0
- data/lib/gemini/v2/ticker.rb +58 -0
- data/lib/gemini/v2/trading.rb +146 -0
- data/lib/gemini/v2/utils.rb +27 -0
- data/lib/gemini/version.rb +3 -0
- data/lib/gemini/websocket_connection.rb +231 -0
- data/lib/gemini-api-rb.rb +1 -0
- data/lib/gemini.rb +38 -0
- metadata +188 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::PositionsClient
|
3
|
+
|
4
|
+
# View your active positions.
|
5
|
+
#
|
6
|
+
# @return [Array]
|
7
|
+
# @example:
|
8
|
+
# client.positions
|
9
|
+
def positions
|
10
|
+
authenticated_post("positions").body
|
11
|
+
end
|
12
|
+
|
13
|
+
# A position can be claimed if:
|
14
|
+
#
|
15
|
+
# It is a long position: The amount in the last unit of the position pair that you have in your trading wallet AND/OR the realized profit of the position is greater or equal to the purchase amount of the position (base price * position amount) and the funds which need to be returned. For example, for a long BTCUSD position, you can claim the position if the amount of USD you have in the trading wallet is greater than the base price * the position amount and the funds used.
|
16
|
+
#
|
17
|
+
# It is a short position: The amount in the first unit of the position pair that you have in your trading wallet is greater or equal to the amount of the position and the margin funding used.
|
18
|
+
# @param position_id [int] The position ID given by `/positions`
|
19
|
+
# @param amount [decimal] The partial amount you wish to claim
|
20
|
+
# @return [Hash]
|
21
|
+
# @example:
|
22
|
+
# client.claim_position(100,10)
|
23
|
+
def claim_position(position_id, amount)
|
24
|
+
authenticated_post("position/claim", params: {position_id: position_id, amount: amount}).body
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::StatsClient
|
3
|
+
|
4
|
+
# Various statistics about the requested pair.
|
5
|
+
#
|
6
|
+
# @param symbol [string] Symbol of the pair you want info about. Default 'btcusd'
|
7
|
+
# @return [Array]
|
8
|
+
# @example:
|
9
|
+
# client.stats('btcusd')
|
10
|
+
def stats(symbol = "btcusd")
|
11
|
+
get("stats/#{symbol}").body
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::SymbolsClient
|
3
|
+
|
4
|
+
# Get a list of valid symbol IDs.
|
5
|
+
#
|
6
|
+
# @return [Array]
|
7
|
+
# @example:
|
8
|
+
# client.symbols
|
9
|
+
def symbols
|
10
|
+
get("symbols").body
|
11
|
+
end
|
12
|
+
|
13
|
+
# Get detailed list of symbols
|
14
|
+
#
|
15
|
+
# @return [Array]
|
16
|
+
# @example:
|
17
|
+
# client.symbols_details
|
18
|
+
def symbols_details
|
19
|
+
get("symbols_details").body
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::TickerClient
|
3
|
+
|
4
|
+
# Gives innermost bid and asks and information on the most recent trade, as well as high, low and volume of the last 24 hours.
|
5
|
+
#
|
6
|
+
# @param symbol [string] The name of hthe symbol
|
7
|
+
# @return [Hash]
|
8
|
+
# @example:
|
9
|
+
# client.ticker
|
10
|
+
def ticker(symbol = "btcusd")
|
11
|
+
get("pubticker/#{symbol}").body
|
12
|
+
end
|
13
|
+
|
14
|
+
# Call the specified block passing tickers, it uses websocket
|
15
|
+
#
|
16
|
+
# @param pair [string]
|
17
|
+
# @param block [Block] The code to be executed when a new ticker is sent by the server
|
18
|
+
# @example:
|
19
|
+
# client.listen_ticker do |tick|
|
20
|
+
# puts tick.inspect
|
21
|
+
# end
|
22
|
+
def listen_ticker(pair="BTCUSD", &block)
|
23
|
+
raise BlockMissingError unless block_given?
|
24
|
+
register_channel pair: pair, channel: "ticker", &block
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::TradesClient
|
3
|
+
|
4
|
+
# Get a list of the most recent trades for the given symbol.
|
5
|
+
#
|
6
|
+
# @param symbol [string] the name of the symbol
|
7
|
+
# @param params :timestamp [time] Only show trades at or after this timestamp.
|
8
|
+
# @param params :limit_trades [int] Limit the number of trades returned. Must be >= 1.
|
9
|
+
# @return [Array]
|
10
|
+
# @example:
|
11
|
+
# client.trades
|
12
|
+
def trades(symbol="btcusd", params={})
|
13
|
+
check_params(params, %i{timestamp limit_trades})
|
14
|
+
get("trades/#{symbol}", params).body
|
15
|
+
end
|
16
|
+
|
17
|
+
# Listen to the trades using websocket.
|
18
|
+
#
|
19
|
+
# @param pair [string]
|
20
|
+
# @param block [Block] The code to be executed when a new trade is executed
|
21
|
+
# @example:
|
22
|
+
# client.listen_trades do |trade|
|
23
|
+
# puts trade.inspect
|
24
|
+
# end
|
25
|
+
def listen_trades(pair="BTCUSD", &block)
|
26
|
+
raise BlockMissingError unless block_given?
|
27
|
+
register_channel pair:pair, channel: 'trades', &block
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V1::WalletClient
|
3
|
+
|
4
|
+
# See your balances.
|
5
|
+
#
|
6
|
+
# @param params :type [string] “trading”, “deposit” or “exchange”.
|
7
|
+
# @param params :currency [string] currency
|
8
|
+
# @param params :amount [decimal] How much balance of this currency in this wallet
|
9
|
+
# @param params :available [decimal] How much X there is in this wallet that is available to trade
|
10
|
+
# @return [Array]
|
11
|
+
# @example:
|
12
|
+
# client.balances
|
13
|
+
def balances(params = {})
|
14
|
+
check_params(params, %i{type currency amount available})
|
15
|
+
authenticated_post("balances", params: params).body
|
16
|
+
end
|
17
|
+
|
18
|
+
# See your trading wallet information for margin trading.
|
19
|
+
#
|
20
|
+
# @return [Array]
|
21
|
+
# @example:
|
22
|
+
# client.margin_infos
|
23
|
+
def margin_infos
|
24
|
+
authenticated_post("margin_infos").body
|
25
|
+
end
|
26
|
+
|
27
|
+
# See a symmary of your trade volume, funding profits etc.
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
# @example:
|
31
|
+
# client.summary
|
32
|
+
def summary
|
33
|
+
authenticated_post("summary").body
|
34
|
+
end
|
35
|
+
|
36
|
+
# Allow you to move available balances between your wallets.
|
37
|
+
#
|
38
|
+
# @param amount [decimal] Amount to transfer
|
39
|
+
# @param currency [string] Currency of funds to transfer
|
40
|
+
# @param wallet_from [string] Wallet to transfer from
|
41
|
+
# @param wallet_to [string] Wallet to transfer to
|
42
|
+
# @return [Array]
|
43
|
+
# @example:
|
44
|
+
# client.transfer(10, 'btc', "exchange", "deposit")
|
45
|
+
def transfer(amount, currency, wallet_from, wallet_to)
|
46
|
+
params = {
|
47
|
+
amount: amount.to_s,
|
48
|
+
currency: currency.upcase,
|
49
|
+
walletfrom: wallet_from.downcase,
|
50
|
+
walletto: wallet_to.downcase
|
51
|
+
}
|
52
|
+
authenticated_post("transfer", params: params).body
|
53
|
+
end
|
54
|
+
|
55
|
+
# Allow you to request a withdrawal from one of your wallet.
|
56
|
+
#
|
57
|
+
# @param withdraw_type [string] can be “bitcoin”, “litecoin” or “darkcoin” or “tether” or “wire”
|
58
|
+
# @param walletselected [string] The wallet to withdraw from, can be “trading”, “exchange”, or “deposit”.
|
59
|
+
# @param amount [decimal] Amount to withdraw
|
60
|
+
# For Cryptocurrencies (including tether):
|
61
|
+
# @param params :address [string] Destination address for withdrawal
|
62
|
+
# For wire withdrawals
|
63
|
+
# @param params :account_name [string] account name
|
64
|
+
# @param params :account_number [string] account number
|
65
|
+
# @param params :bank_name [string] bank name
|
66
|
+
# @param params :bank_address [string] bank address
|
67
|
+
# @param params :bank_city [string] bank city
|
68
|
+
# @param params :bank_country [string] bank country
|
69
|
+
# @param params :detail_payment [string] (optional) message to beneficiary
|
70
|
+
# @param params :intermediary_bank_name [string] (optional) intermediary bank name
|
71
|
+
# @param params :intermediary_bank_address [string] (optional) intermediary bank address
|
72
|
+
# @param params :intermediary_bank_city [string] (optional) intermediary bank city
|
73
|
+
# @param params :intermediary_bank_country [string] (optional) intermediary bank country
|
74
|
+
# @param params :intermediary_bank_account [string] (optional) intermediary bank account
|
75
|
+
# @param params :intermediary_bank_swift [string] (optional) intemediary bank swift
|
76
|
+
# @param params :expressWire [int] (optional). “1” to submit an express wire withdrawal, “0” or omit for a normal withdrawal
|
77
|
+
# @return [Array]
|
78
|
+
# @example:
|
79
|
+
# client.withdraw("bitcoin","deposit",1000, address: "1DKwqRhDmVyHJDL4FUYpDmQMYA3Rsxtvur")
|
80
|
+
def withdraw(withdraw_type, walletselected, amount, params={})
|
81
|
+
params.merge!({
|
82
|
+
withdraw_type: withdraw_type,
|
83
|
+
walletselected: walletselected.downcase,
|
84
|
+
amount: amount.to_s})
|
85
|
+
|
86
|
+
authenticated_post("withdraw", params: params).body
|
87
|
+
end
|
88
|
+
|
89
|
+
# Check the permissions of the key being used to generate this request
|
90
|
+
#
|
91
|
+
# @return [Hash]
|
92
|
+
# @example:
|
93
|
+
# client.key_info
|
94
|
+
def key_info
|
95
|
+
authenticated_post("key_info").body
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V2::MarginClient
|
3
|
+
|
4
|
+
# Get active offers
|
5
|
+
#
|
6
|
+
# @example:
|
7
|
+
# client.offers
|
8
|
+
def offers
|
9
|
+
authenticated_post("auth/r/offers").body
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get account margin info
|
13
|
+
# - if symbol is not specified return everything
|
14
|
+
#
|
15
|
+
# @param symbol [string] (optional)
|
16
|
+
#
|
17
|
+
# @example:
|
18
|
+
# client.margin_info("tBTCUSD")
|
19
|
+
def margin_info(symbol = "base")
|
20
|
+
authenticated_post("auth/r/margin/#{symbol}").body
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Get account funding info
|
25
|
+
#
|
26
|
+
# @param symbol [string] default fUSD
|
27
|
+
#
|
28
|
+
# @example:
|
29
|
+
# client.funding_info
|
30
|
+
def funding_info(symbol = "fUSD")
|
31
|
+
authenticated_post("auth/r/funding/#{symbol}").body
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V2::PersonalClient
|
3
|
+
|
4
|
+
# Get account wallets
|
5
|
+
#
|
6
|
+
# @example:
|
7
|
+
# client.wallets
|
8
|
+
def wallets
|
9
|
+
authenticated_post("auth/r/wallets").body
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get account historical daily performance
|
13
|
+
#
|
14
|
+
# @example:
|
15
|
+
# client.performance
|
16
|
+
def performance
|
17
|
+
authenticated_post("auth/r/stats/perf:1D/hist")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the list of alerts
|
21
|
+
#
|
22
|
+
# @example:
|
23
|
+
# client.alerts
|
24
|
+
def alerts(type = 'price')
|
25
|
+
authenticated_post("auth/r/alerts", params: {type: type}).body
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set a new alert
|
29
|
+
#
|
30
|
+
# @param price
|
31
|
+
# @param symbol
|
32
|
+
# @param type
|
33
|
+
#
|
34
|
+
# @example:
|
35
|
+
# client.alert(3000, "tBTCUSD")
|
36
|
+
def alert(price, symbol = "tBTCUSD", type = "price")
|
37
|
+
params = {
|
38
|
+
type: type,
|
39
|
+
price: price,
|
40
|
+
symbol: symbol
|
41
|
+
}
|
42
|
+
authenticated_post("auth/w/alert/set", params: params).body
|
43
|
+
end
|
44
|
+
|
45
|
+
# Delete an existing alert
|
46
|
+
#
|
47
|
+
# @param price
|
48
|
+
# @param symbol
|
49
|
+
#
|
50
|
+
# @example:
|
51
|
+
# client.delete_alert(3000, "tBTCUSD")
|
52
|
+
def delete_alert(price, symbol = "tBTCUSD")
|
53
|
+
authenticated_post("auth/w/alert/price:#{symbol}:#{price}/del").body
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Calculate available balance for order/offer
|
58
|
+
#
|
59
|
+
# @param rate [int] Rate of the order/offer
|
60
|
+
# @param dir [int] direction of the order/offer
|
61
|
+
# (orders: > 0 buy, < 0 sell | offers:
|
62
|
+
# > 0 sell, < 0 buy)
|
63
|
+
# @param type [string] Type of the order/offer
|
64
|
+
# EXCHANGE or MARGIN
|
65
|
+
# @param symbol [string]
|
66
|
+
|
67
|
+
# @example:
|
68
|
+
# client.available_balance(800, 1, 'EXCHANGE', 'tBTCUSD')
|
69
|
+
def available_balance(rate, dir, type, symbol)
|
70
|
+
params = {
|
71
|
+
symbol: symbol,
|
72
|
+
dir: dir,
|
73
|
+
type: type,
|
74
|
+
rate: rate
|
75
|
+
}
|
76
|
+
authenticated_post("auth/calc/order/avail", params: params).body
|
77
|
+
end
|
78
|
+
|
79
|
+
# Listen to authenticated channel
|
80
|
+
#
|
81
|
+
# Documentation:
|
82
|
+
# https://docs.gemini.com/v2/reference#account-info
|
83
|
+
#
|
84
|
+
# example:
|
85
|
+
# client.listen_account do |account|
|
86
|
+
# puts account
|
87
|
+
# end
|
88
|
+
def listen_account(&block)
|
89
|
+
raise BlockMissingError unless block_given?
|
90
|
+
ws_auth(&block)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Gemini
|
4
|
+
module V2::StatsClient
|
5
|
+
|
6
|
+
# Various statistics about the requested pair.
|
7
|
+
#
|
8
|
+
# @param symbol [string] The symbol you want information about.
|
9
|
+
# @param key [string] Allowed values: "funding.size",
|
10
|
+
# "credits.size", "credits.size.sym", "pos.size"
|
11
|
+
# @param side [string] Available values: "long", "short"
|
12
|
+
# @param section [string] Available values: "last", "hist"
|
13
|
+
# @param size [string] Available values: '1m'
|
14
|
+
# @param params :sort [int32] if = 1 it sorts results
|
15
|
+
# returned with old > new
|
16
|
+
#
|
17
|
+
# @return [Array]
|
18
|
+
#
|
19
|
+
# @example:
|
20
|
+
# client.stats('fUSD', 'pos.size')
|
21
|
+
def stats(symbol = 'fUSD', key = 'funding.size', side = "long", section = "last", size = '1m', params = {})
|
22
|
+
check_params(params, %i{sort})
|
23
|
+
get("stats1/#{key}:#{size}:#{symbol}:#{side}/#{section}").body
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Gemini
|
4
|
+
module V2::TickerClient
|
5
|
+
|
6
|
+
# Gives innermost bid and asks and information on
|
7
|
+
# the most recent trade, as well as high, low and
|
8
|
+
# volume of the last 24 hours.
|
9
|
+
#
|
10
|
+
# @param symbols a list of symbols
|
11
|
+
# @return [Hash]
|
12
|
+
# @example:
|
13
|
+
# client.ticker("tBTCUSD","tLTCUSD","fUSD")
|
14
|
+
def ticker(*symbols)
|
15
|
+
if symbols.size == 1
|
16
|
+
get("ticker/#{symbols.first}").body
|
17
|
+
else
|
18
|
+
get("tickers", symbols: "#{symbols.flatten.join(",")}").body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Call the specified block passing tickers, it uses websocket
|
23
|
+
#
|
24
|
+
# @param pair [string]
|
25
|
+
# @param block [Block] The code to be executed when a new ticker is sent by the server
|
26
|
+
#
|
27
|
+
# Documentation:
|
28
|
+
# https://docs.gemini.com/v2/reference#ws-public-ticker
|
29
|
+
#
|
30
|
+
# @example:
|
31
|
+
# client.listen_ticker do |tick|
|
32
|
+
# puts tick.inspect
|
33
|
+
# end
|
34
|
+
def listen_ticker(pair="tBTCUSD", &block)
|
35
|
+
raise BlockMissingError unless block_given?
|
36
|
+
register_channel pair: pair, channel: "ticker", &block
|
37
|
+
end
|
38
|
+
|
39
|
+
# Provides a way to access charting candle info
|
40
|
+
#
|
41
|
+
# @param symbol [string]
|
42
|
+
# @param time_frame [string] default '1m' - see doc for list of options
|
43
|
+
#
|
44
|
+
# Documentation:
|
45
|
+
# https://docs.gemini.com/v2/reference#ws-public-candle
|
46
|
+
#
|
47
|
+
# @example:
|
48
|
+
# client.listen_candles("tBTCUSD","1m") do |candle|
|
49
|
+
# puts "high #{candle[1][8]} | low #{candle[1][9]}"
|
50
|
+
# end
|
51
|
+
def listen_candles(symbol="tBTCUSD", time_frame="1m", &block)
|
52
|
+
raise BlockMissingError unless block_given?
|
53
|
+
key = "trade:#{time_frame}:#{symbol}"
|
54
|
+
register_channel key: key, channel: 'candles', &block
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Gemini
|
2
|
+
module V2::TradingClient
|
3
|
+
|
4
|
+
# Provides a way to access charting candle info
|
5
|
+
#
|
6
|
+
# @param symbol [string] The symbol you want information about.
|
7
|
+
# @param timeframe [string] Available values: '1m', '5m', '15m',
|
8
|
+
# '30m', '1h', '3h', '6h', '12h', '1D', '7D', '14D', '1M'
|
9
|
+
# @param section [string] Available values: "last", "hist"
|
10
|
+
# @param params :limit [int32] Number of candles requested
|
11
|
+
# @param params :start [int32] Filter start (ms)
|
12
|
+
# @param params :end [int32] Filter end (ms)
|
13
|
+
# @param params :sort [int32] if = 1 it sorts
|
14
|
+
# results returned with old > new
|
15
|
+
#
|
16
|
+
# @return [Array]
|
17
|
+
#
|
18
|
+
# @example:
|
19
|
+
# client.candles('tBTCUSD')
|
20
|
+
def candles(symbol = 'tBTCUSD', timeframe = '1m', section = "last", params = {})
|
21
|
+
check_params(params, %i{limit start end sort})
|
22
|
+
get("candles/trade:#{timeframe}:#{symbol}/#{section}", params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
# The Order Books channel allow you to keep track
|
26
|
+
# of the state of the Gemini order book.
|
27
|
+
# It is provided on a price aggregated basis,
|
28
|
+
# with customizable precision.
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# @param symbol [string] The symbol you want
|
32
|
+
# information about. You can find the list of
|
33
|
+
# valid symbols by calling the /symbols
|
34
|
+
# endpoint.
|
35
|
+
# @param precision [string] Level of price
|
36
|
+
# aggregation (P0, P1, P2, P3, R0)
|
37
|
+
# @param params :len [int32] Number of price
|
38
|
+
# points ("25", "100")
|
39
|
+
#
|
40
|
+
# @return [Hash] :bids [Array], :asks [Array]
|
41
|
+
#
|
42
|
+
# @example:
|
43
|
+
# client.orderbook("btcusd")
|
44
|
+
def books(symbol="btcusd", precision="P0", params = {})
|
45
|
+
check_params(params, %i{len})
|
46
|
+
get("book/#{symbol}/#{precision}", params: params).body
|
47
|
+
end
|
48
|
+
|
49
|
+
# Trades endpoint includes all the pertinent details
|
50
|
+
# of the trade, such as price, size and time.
|
51
|
+
#
|
52
|
+
# @param symbol [string] the name of the symbol
|
53
|
+
# @param params :limit [int32] Number of records
|
54
|
+
# @param params :start [int32] Millisecond start time
|
55
|
+
# @param params :end [int32] Millisecond end time
|
56
|
+
# @param params :sort [int32] if = 1 it sorts
|
57
|
+
# results returned with old > new
|
58
|
+
#
|
59
|
+
# @return [Array]
|
60
|
+
#
|
61
|
+
# @example:
|
62
|
+
# client.trades("tETHUSD")
|
63
|
+
def trades(symbol="tBTCUSD", params={})
|
64
|
+
check_params(params, %i{limit start end sort})
|
65
|
+
get("trades/#{symbol}", params).body
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get active orders
|
69
|
+
#
|
70
|
+
# example:
|
71
|
+
# client.orders
|
72
|
+
def orders
|
73
|
+
authenticated_post("auth/r/orders").body
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get Trades generated by an Order
|
77
|
+
#
|
78
|
+
# @param order_id [int32] Id of the order
|
79
|
+
# @param symbol [string] symbol used for the order
|
80
|
+
#
|
81
|
+
# @return [Array]
|
82
|
+
#
|
83
|
+
# @example:
|
84
|
+
# client.order_trades 10010, "tBTCUSD"
|
85
|
+
#
|
86
|
+
def order_trades(order_id, symbol="tBTCUSD")
|
87
|
+
authenticated_post("auth/r/order/#{symbol}:#{order_id}/trades").body
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# Get active positions
|
92
|
+
#
|
93
|
+
# return [Array]
|
94
|
+
#
|
95
|
+
# @example:
|
96
|
+
# client.active_positions
|
97
|
+
def active_positions
|
98
|
+
authenticated_post("auth/positions").body
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# This channel sends a trade message whenever a trade occurs at Gemini.
|
103
|
+
# It includes all the pertinent details of the trade, such as price, size and time.
|
104
|
+
#
|
105
|
+
# @param symbol [string]
|
106
|
+
# @param block [Block] The code to be executed when a new ticker is sent by the server
|
107
|
+
#
|
108
|
+
# Documentation:
|
109
|
+
# https://docs.gemini.com/v2/reference#ws-public-trades
|
110
|
+
#
|
111
|
+
# @example:
|
112
|
+
# client.listen_trades("tBTCUSD") do |trade|
|
113
|
+
# puts "traded #{trade[2][2]} BTC for #{trade[2][3]} USD"
|
114
|
+
# end
|
115
|
+
def listen_trades(symbol="tBTCUSD", &block)
|
116
|
+
raise BlockMissingError unless block_given?
|
117
|
+
register_channel symbol: symbol, channel: "trades", &block
|
118
|
+
end
|
119
|
+
|
120
|
+
# The Order Books channel allow you to keep track of the state of the Gemini order book.
|
121
|
+
# It is provided on a price aggregated basis, with customizable precision.
|
122
|
+
# After receiving the response, you will receive a snapshot of the book,
|
123
|
+
# followed by updates upon any changes to the book.
|
124
|
+
#
|
125
|
+
# @param symbol [string]
|
126
|
+
# @param precision [string] Level of price aggregation (P0, P1, P2, P3, R0).
|
127
|
+
# (default P0) R0 is raw books - These are the most granular books.
|
128
|
+
# @param frequency [string] Frequency of updates (F0, F1, F2, F3).
|
129
|
+
# F0=realtime / F1=2sec / F2=5sec / F3=10sec (default F0)
|
130
|
+
# @param length [int] Number of price points ("25", "100") [default="25"]
|
131
|
+
#
|
132
|
+
# Documentation:
|
133
|
+
# https://docs.gemini.com/v2/reference#ws-public-order-books
|
134
|
+
# https://docs.gemini.com/v2/reference#ws-public-raw-order-books
|
135
|
+
#
|
136
|
+
# @example:
|
137
|
+
# client.listen_book("tBTCUSD") do |trade|
|
138
|
+
# puts "traded #{trade[2][2]} BTC for #{trade[2][3]} USD"
|
139
|
+
# end
|
140
|
+
def listen_book(symbol="tBTCUSD", frequency="F0", length=25, precision="P0", &block)
|
141
|
+
raise BlockMissingError unless block_given?
|
142
|
+
register_channel symbol: symbol, channel: "book", prec: precision, freq: frequency, len: length, &block
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Gemini
|
4
|
+
module V2::UtilsClient
|
5
|
+
|
6
|
+
# Calculate the average execution rate for Trading or Margin funding.
|
7
|
+
#
|
8
|
+
# @param symbol [string] The symbol you want information about.
|
9
|
+
# @param amount [string] Amount. Positive for buy, negative for sell (ex. "1.123")
|
10
|
+
# @param period [string] (optional) Maximum period for Margin Funding
|
11
|
+
# @param rate_limit [string] Limit rate/price (ex. "1000.5")
|
12
|
+
#
|
13
|
+
# @return [Array]
|
14
|
+
#
|
15
|
+
# @example:
|
16
|
+
# client.calc_avg_price('tBTCUSD', 1000, 1000)
|
17
|
+
def calc_avg_price(symbol = 'tBTCUSD', amount = 0, period = 0, rate_limit = nil)
|
18
|
+
params = {
|
19
|
+
symbol: symbol,
|
20
|
+
amount: amount.to_s,
|
21
|
+
period: period.to_s
|
22
|
+
}
|
23
|
+
params[:rateLimit] = rate_limit.to_s unless rate_limit.nil?
|
24
|
+
get("calc/trade/avg",params)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|