Last active
November 2, 2017 16:58
-
-
Save TimothyClayton/19486e19dc7a8126c5edbf13dcda9279 to your computer and use it in GitHub Desktop.
Braveno Exchange API Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_KEY='<Your API Key>' | |
API_SECRET='<Your API Secret>' | |
HOST='https://api.sandbox.braveno.com' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'rest-client' | |
class Request | |
class << self | |
##### Usage | |
# e.g., Request.server_time | |
##### Public Requests | |
def server_time | |
public_get '/time' | |
end | |
def products | |
public_get '/products' | |
end | |
def currencies | |
public_get '/currencies' | |
end | |
def trades(product_id) | |
# product_id, e.g., 'BRV-BTC' | |
public_get "/products/#{product_id}/trades" | |
end | |
def ticker(product_id) | |
public_get "/products/#{product_id}/ticker" | |
end | |
def order_book(product_id) | |
public_get "/products/#{product_id}/orders" | |
end | |
##### Private Requests | |
def orders | |
private_get '/users/orders' | |
end | |
def order(product_id, order_id) | |
private_get "/products/#{product_id}/orders/#{order_id}" | |
end | |
def buy_order(params) | |
# params: | |
# { | |
# product_id: 'BRV-BTC', | |
# price: '0.1', | |
# quantity: '1', | |
# wallet_id: '<the account's wallet id>', | |
# account_id: '<some account id>' | |
# } | |
post "/products/#{params[:product_id]}/orders", { side: 'bid' }.merge(params) | |
end | |
def sell_order(params) | |
# params: | |
# { | |
# product_id: 'BRV-BTC', | |
# price: '0.1', | |
# quantity: '1', | |
# wallet_id: '<the account's wallet id>', | |
# account_id: '<some account id>' | |
# } | |
post "/products/#{params[:product_id]}/orders", { side: 'ask' }.merge(params) | |
end | |
def cancel_order(product_id, order_id) | |
post "/products/#{product_id}/orders/#{order_id}" | |
end | |
def cancel_orders(product_id) | |
post "/products/#{product_id}/orders/cancel" | |
end | |
def trades | |
private_get '/users/trades' | |
end | |
def transactions | |
private_get '/users/transactions' | |
end | |
def fills(product_id) | |
post "/products/#{product_id}/fills" | |
end | |
def wallet_balance(account_id, wallet_id) | |
post "/users/balance", { account_id: account_id, wallet_id: wallet_id } | |
end | |
def wallet_transactions | |
post "/wallets/ListExchangeTransactions" | |
end | |
def list_deposit_wallets | |
post '/wallets/GetWallets' | |
end | |
# def create_deposit_wallet(account_id, currency_symbol) | |
# #### WIP #### | |
# # currency_symbol, e.g., 'BVN' | |
# post '/wallets/GetNewAddress', { account_id: account_id, "currencySymbol" => currency_symbol } | |
# end | |
def create_user(params) | |
# params: | |
# { | |
# username: "another-test-acct", | |
# password:"changeme", | |
# email: "noreply@braveno.com" | |
# } | |
post '/users', params | |
end | |
def profile | |
post '/users/profile' | |
end | |
def update_profile(params) | |
# params, e.g., { first_name: "Tom" } | |
post '/users/update-profile', params | |
end | |
def accounts | |
post '/users/accounts' | |
end | |
def api_keys | |
private_get '/users/api-keys' | |
end | |
def create_api_key | |
post '/users/api-key' | |
end | |
# def revoke_api_key(api_key) | |
# #### WIP - endpoint uncertain #### | |
# post '/users/????', { api_key: api_key } | |
# end | |
def public_get(endpoint, params = {}) | |
api_request :get, endpoint, params, false | |
end | |
def private_get(endpoint, params = {}) | |
api_request :get, endpoint, params | |
end | |
def post(endpoint, params = {}) | |
api_request :post, endpoint, params | |
end | |
def authorization | |
{ | |
user: ENV['API_KEY'], | |
password: ENV['API_SECRET'] | |
} | |
end | |
def api_request(method, endpoint, params, auth = true) | |
args = { | |
method: method, | |
url: ENV['HOST'] + endpoint, | |
payload: params.to_json, | |
headers: { content_type: :json } | |
} | |
request = auth ? args.merge(authorization) : args | |
RestClient::Request.execute(request) | |
rescue | |
# handle errors | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment