Class: Gatecoin::API
- Inherits:
-
Object
- Object
- Gatecoin::API
- Defined in:
- lib/gatecoin/gatecoin.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #balances ⇒ Object
- #cancel_order(id) ⇒ Object
- #create_order(side:, size:, price:, pair:) ⇒ Object
- #deposit_wallets ⇒ Object
-
#initialize(key:, secret:, url: 'https://api.gatecoin.com') ⇒ API
constructor
A new instance of API.
- #order(id) ⇒ Object
- #withdrawal(currency:, address:, amount:, comment: nil, validation: nil) ⇒ Object
Constructor Details
#initialize(key:, secret:, url: 'https://api.gatecoin.com') ⇒ API
Returns a new instance of API.
12 13 14 15 16 |
# File 'lib/gatecoin/gatecoin.rb', line 12 def initialize(key:, secret:, url: 'https://api.gatecoin.com') @key = key @secret = secret @url = url end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/gatecoin/gatecoin.rb', line 8 def key @key end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/gatecoin/gatecoin.rb', line 8 def secret @secret end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/gatecoin/gatecoin.rb', line 8 def url @url end |
Instance Method Details
#balances ⇒ Object
18 19 20 |
# File 'lib/gatecoin/gatecoin.rb', line 18 def balances get('/Balance/Balances')['balances'] end |
#cancel_order(id) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gatecoin/gatecoin.rb', line 53 def cancel_order(id) status = delete("/Trade/Orders/#{id}") if status['responseStatus'] && status['responseStatus']['errorCode'] error = status['responseStatus']['message'] error ||= status['responseStatus'] raise Gatecoin::CancelOrderException.new(error) end status rescue => e raise Gatecoin::CancelOrderException.new(e.) end |
#create_order(side:, size:, price:, pair:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gatecoin/gatecoin.rb', line 26 def create_order(side:, size:, price:, pair:) side = case side when :buy then 'Bid' when :sell then 'Ask' else raise "Unknown side type #{side}. Use :buy or :sell as symbols." end opts = { Code: pair, Way: side, Amount: size.to_f.to_s, Price: price.to_f.to_s, } order = post('/Trade/Orders', opts) if !order['clOrderId'] error = order['responseStatus']['message'] if order['responseStatus'] && order['responseStatus']['message'] error ||= order raise Gatecoin::CreateOrderException.new(error) end order rescue => e raise Gatecoin::CreateOrderException.new(e.) end |
#deposit_wallets ⇒ Object
67 68 69 70 71 72 |
# File 'lib/gatecoin/gatecoin.rb', line 67 def deposit_wallets addresses = get('/ElectronicWallet/DepositWallets') raise addresses['responseStatus']['message'] unless addresses['addresses'] addresses['addresses'] end |
#order(id) ⇒ Object
22 23 24 |
# File 'lib/gatecoin/gatecoin.rb', line 22 def order(id) get("/Trade/Orders/#{id}") end |
#withdrawal(currency:, address:, amount:, comment: nil, validation: nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gatecoin/gatecoin.rb', line 74 def withdrawal(currency:, address:, amount:, comment: nil, validation: nil) opts = { AddressName: address, Amount: amount, } opts[:Comment] = comment if comment opts[:ValidationCode] = validation if validation status = post("/ElectronicWallet/withdrawals/#{currency}", opts) if status['responseStatus'] && status['responseStatus']['errorCode'] error = status['responseStatus']['message'] error ||= status['responseStatus'] raise Gatecoin::WithdrawalException.new(error) end status end |