-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
339 additions
and
166 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in bitfinexrb.gemspec | ||
gemspec | ||
|
||
group :test do | ||
gem 'rspec' | ||
gem 'simplecov' | ||
gem 'webmock', '~> 1.22.6' | ||
gem 'pry' | ||
end | ||
|
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'faraday' | ||
require 'bitfinex/configurable' | ||
require 'bitfinex/base_resource' | ||
require 'bitfinex/connection_errors' | ||
require 'bitfinex/connection' | ||
require 'bitfinex/ticker' | ||
require 'bitfinex/client' | ||
|
5 changes: 2 additions & 3 deletions
5
lib/bitfinexrb/account_info.rb → lib/bitfinex/account_info.rb
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class Balances < Authenticated | ||
def all | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Bitfinex | ||
class BaseResource | ||
class << self | ||
def set_properties *props | ||
@properties = props | ||
props.each do |val| | ||
class_eval %{ | ||
def #{val}=(v);@#{val}=v;end | ||
def #{val};@#{val};end | ||
} | ||
end | ||
end | ||
|
||
def properties | ||
@properties | ||
end | ||
end | ||
|
||
def initialize(obj) | ||
obj.each do |k,v| | ||
if self.class.properties.include?(k.to_sym) | ||
send((k+'=').to_sym,v) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Bitfinex | ||
class Client | ||
include Bitfinex::RestConnection | ||
include Bitfinex::TickerClient | ||
include Bitfinex::Configurable | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Bitfinex | ||
module Configurable | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
def config | ||
self.class.config | ||
end | ||
|
||
module ClassMethods | ||
def configure | ||
yield config | ||
end | ||
|
||
def config | ||
@configuration ||= Configuration.new | ||
end | ||
end | ||
end | ||
|
||
class Configuration | ||
attr_accessor :api_endpoint | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Bitfinex | ||
# Network Layer for API Rest client | ||
module RestConnection | ||
|
||
# Make an HTTP GET request | ||
def get(url, options={}) | ||
rest.get url, parse_params(options) | ||
end | ||
|
||
private | ||
def rest | ||
@conn ||= new_rest_connection | ||
end | ||
|
||
def new_rest_connection | ||
Faraday.new(url: config.api_endpoint) do |builder| | ||
builder.use Bitfinex::CheckResponse | ||
end | ||
end | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Bitfinex | ||
|
||
class Error | ||
def self.check_response(response) | ||
case response.status.to_i | ||
when 400 then BitFinex::BadRequest | ||
end | ||
end | ||
end | ||
|
||
# Check Faraday Response and raise the appropriate exception | ||
# in case of failure | ||
class CheckResponse < Faraday::Response::Middleware | ||
private | ||
def on_complete(response) | ||
if error = Bitfinex::Error.check_response(response) | ||
raise error | ||
end | ||
end | ||
end | ||
|
||
class ClientError < Error; end | ||
class BadRequest < ClientError; end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class Credits < Authenticated | ||
def all | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class Lend | ||
attr_accessor :rate, :amount, :timestamp | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class MarginInfo < Authenticated | ||
def all | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
class Orderbook < Base | ||
|
||
attr_accessor :bids, :asks | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
# | ||
class Orders < Authenticated | ||
def all | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
# | ||
class Pairs < Base | ||
def all | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class Positions < Authenticated | ||
|
||
def all | ||
uri = "/#{@api_version}/positions" | ||
self.class.post(uri, headers: headers_for(uri)).parsed_response | ||
end | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
module Bitfinexrb | ||
module Bitfinex | ||
|
||
class TakenFunds < Authenticated | ||
def all | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Bitfinex | ||
module TickerClient | ||
def ticker(symbol='btcusd') | ||
resp = rest.get("/pubticker/#{symbol}") | ||
if resp.success? | ||
Ticker.new(JSON.parse(resp.body)) | ||
end | ||
end | ||
end | ||
|
||
class Ticker < BaseResource | ||
set_properties :mid, :bid, :ask, :last_price, :low, :volume, :timestamp | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Bitfinex | ||
|
||
module TradeClient | ||
TRADE_PARAMS = %w{timestamp limit_trades} | ||
|
||
def trades symbol, params={} | ||
resp = rest.get("/trades/#{symbol}", check_params(params, TRADE_PARAMS)) | ||
|
||
if resp.success? | ||
Trade.new(JSON.parse(resp.body)) | ||
end | ||
end | ||
end | ||
|
||
class Trade | ||
values :tid, :timestamp, :price, :amount, :exchange, :type | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Bitfinexrb | ||
module Bitfinex | ||
VERSION = "0.0.1" | ||
end |
Oops, something went wrong.