bitfinexcom / bitfinex-api-rb Goto Github PK
View Code? Open in Web Editor NEWBITFINEX Ruby trading API - Bitcoin, Litecoin, and Ether exchange
Home Page: https://www.bitfinex.com/
License: MIT License
BITFINEX Ruby trading API - Bitcoin, Litecoin, and Ether exchange
Home Page: https://www.bitfinex.com/
License: MIT License
When trying to run api_v2.rb, I get the following error:
from /Users//.gem/ruby/2.3.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/errors.rb:29:in `[]': no implicit conversion of String into Integer (TypeError)
the problem happens at the line
p client.performance
Any idea how to fix this?
I am trying to make exchange similar like bitfinex for a small community (personal use). How can I do that. Do they have any open source code?
'fail' in websocket_connection.rb:209 expects a text message or exception object, but given a faye-websocket event that it doesn't know how to deal with. So, no meaningful exception is produced.
require 'bitfinex-rb'
Bitfinex::Client.configure do |conf|
conf.api_key = 'key' # replace
conf.secret = 'secret' # replace
conf.use_api_v2
end
client = Bitfinex::Client.new
client.trades
Traceback (most recent call last):
11: from /Users/kain/.rvm/rubies/ruby-2.5.0/bin/irb:11:in `<main>'
10: from (irb):14
9: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/v2/trading.rb:65:in `trades'
8: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/connection.rb:8:in `get'
7: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/connection.rb:140:in `get'
6: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
5: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
4: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
3: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
2: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
1: from /Users/kain/.rvm/gems/ruby-2.5.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/errors.rb:27:in `on_complete'
Bitfinex::NotFoundError (Bitfinex::NotFoundError)
Is there any reason for use_all_available
being out of the valid parameters list while placing orders?
When REST request to server ends in error, the only info I get in my application using the library is something like this:
faraday-0.9.2/lib/faraday/response/raise_error.rb:13:in `on_complete': the server responded with status 400 (Faraday::ClientError)
In your program, you can rescue for this exception, but it doesn't give you any clue about what exactly went wrong. You need to enable debug mode on a client, and only then you can see in a console something like:
DEBUG -- response: {"message"=>"Invalid order: maximum size for BTCUSD is 2000.0 units"}
For the program using this lib, analyzing server response messages is often part of business logics. Eyeballing debug console to find what the error message was won't do it. There should be a better way of informing the program using this lib what kind of error message the server returned. This goes both for REST requests and WS error events.
I don't currently have suggestions how to do it exactly, just food for thought.
Hi,
I installed bitfinex-api-rb with bundle successfully, after adding it to Gemsfile. Now I'm trying to load the the bitfinex-api-rb into my application in an initializer but get error when trying to start application:
LoadError: cannot load such file -- bitfinex-api-rb
This is the initializer i'm using:
require 'bitfinex-api-rb'
Bitfinex::Client.configure do |config|
config.key = GLOBAL[:bitfinex_key]
config.secret = GLOBAL[:bitfinex_secret]
config.websocket_api_endpoint = "wss://api.bitfinex.com/ws"
end
Any suggestion why?
Thanks.
Hey guys, do you have any plans to resurrect this library? It's very outdated
Sell Price: 362.52
Selling Amount: 0.2759458
Order type: exchange limit
{:ocoorder=>true, :sell_price_oco=>355.2696}
Bitfinex::ParamsError
/home/samur/.rvm/gems/jruby-9.0.5.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/connection.rb:25:in check_params' /home/samur/.rvm/gems/jruby-9.0.5.0/gems/bitfinex-rb-0.1.0/lib/bitfinex/v1/orders.rb:18:in
new_order'
hightrader_regressionforest.rb:51:in sell' hightrader_regressionforest.rb:177:in
block in trade'
org/jruby/RubyArray.java:1560:in each' hightrader_regressionforest.rb:86:in
trade'
hightrader_regressionforest.rb:210:in `'
Sometimes WS v2
client.listen_account do |update|
puts update
end
client.listen_book("tBTCUSD") do |order|
puts update
end
client.listen!
returns
'auth'
and nothing else, no either account updates nor orderbook deltas. Is it possible to reconnect somehow when this happens? It happens in 50% of cases.
After this update (cbc3508) EM never stops, so you cannot terminate any program that uses WS connection.
Roots of the problem could be the same as in #41
Half of listen_account runs return:
{"event"=>"auth", "status"=>"FAILED", "chanId"=>0, "code"=>10100, "msg"=>"apikey: invalid"}
and half are successful:
{"event"=>"auth", "status"=>"OK", "chanId"=>0, "userId"=>xxx, "auth_id"=>"xxxx", "caps"=>{"orders"=>{"read"=>1, "write"=>1}, "account"=>{"read"=>1, "write"=>0}, "funding"=>{"read"=>1, "write"=>0}, "history"=>{"read"=>1, "write"=>0}, "wallets"=>{"read"=>1, "write"=>0}, "withdraw"=>{"read"=>0, "write"=>0}, "positions"=>{"read"=>1, "write"=>0}}}
Is this an error on the server side or on the client side (I use ws_auth
function provided in this gem). Can it be something with the way signature is generated using sha384?
Iām trying to provide higher numbers (default says 50) but Iām only getting back 25... I need to be able to see more than that.
I'm using WSv2 and the 'ticker' emit return empty object:
#<Bitfinex::Models::FundingTicker:0x00007fe75c6a2cc8 @fields={}, @boolFields=[]>
I'm getting an error on Ruby 2.4.1 that the version of json it uses (2.0.1 I believe) is incompatible with the json 1.8.3 that bitfinex-api-rb requires. Could you please update this to work with the updated json?
I see there is 'bitfinex/websocket.rb', but neither Faye nor Eventmachine are even in the gemspec. Is it just a stub atm?
If I set the price to a value below 0.0001, I get an error for a new order request. Take a look at the example with a price of 0.00009 (four zeros):
2.4.0 :011 > @client.new_order("IOTBTC", 1, "exchange limit", "buy", 0.00009)
Bitfinex::BadRequestError: Key price should be a decimal number, e.g. "123.456"
from /home/trading/.rvm/gems/ruby-2.4.0/gems/bitfinex-rb-0.0.11/lib/bitfinex/errors.rb:20:in `on_complete'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/bitfinex-rb-0.0.11/lib/bitfinex/authenticated_rest.rb:9:in `authenticated_post'
from /home/trading/.rvm/gems/ruby-2.4.0/gems/bitfinex-rb-0.0.11/lib/bitfinex/orders.rb:32:in `new_order'
from (irb):11
from /home/trading/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
But it works quite well with a price of 0.0001 (three zeros)
2.4.0 :012 > @client.new_order("IOTBTC", 1, "exchange limit", "buy", 0.0001)
=> {"id"=>3029486428, "cid"=>56856233060, "cid_date"=>"2017-07-11", "gid"=>nil, "symbol"=>"iotbtc", "exchange"=>"bitfinex", "price"=>"0.0001", "avg_execution_price"=>"0.0", "side"=>"buy", "type"=>"exchange limit", "timestamp"=>"1499788056.336560589", "is_live"=>true, "is_cancelled"=>false, "is_hidden"=>false, "oco_order"=>nil, "was_forced"=>false, "original_amount"=>"1.0", "remaining_amount"=>"1.0", "executed_amount"=>"0.0", "src"=>"api", "order_id"=>3029486428}
Is there any websocket message about adding/deleting pair(s) on bitfinex? It would be useful...
I am using a correct api key and api secret, but it just isn't working. I keep getting the InvalidAuthKeyError message. I am using Ruby 2.4.
I didn't update any code but since 6/24 the restful API doesn't work.
Here are the code and error messages:
client = Bitfinex::RESTv1.new({
:api_key => Rails.application.credentials.bitfinex[:key],
:api_secret => Rails.application.credentials.bitfinex[:secret],
})
fund_records = client.credits
result:
Bitfinex::BadRequestError: Nonce is too small.
When running the order_book_checksums.rb
code in the examples/ws/v2
folder with :checksum_audit => true
, the logger will frequently report checksum mismatch.
Something is not working properly with the internal order book management code.
Run this slightly modified order_book_checksums.rb
code, which will quickly highlight the bug:
require_relative '../../../lib/bitfinex.rb'
client = Bitfinex::WSv2.new({
:url => ENV['WS_URL'],
:manage_order_books => true,
:checksum_audit => true
})
client.on(:order_book) do |sym, msg|
p "recv order book message for symbol #{sym}"
p msg
end
client.on(:open) do
client.subscribe_order_book('fUSD', 'P4', '25')
end
client.on(:checksum) do |sym, msg|
puts
puts "CHECKSUM"
pp msg
puts
end
client.on(:error) do |err|
pp err
exit
end
client.open!
Example output when running the above code:
...
CHECKSUM
[323049, "cs", -1108044634]
E, [2024-01-07T22:08:50.997911 #16770] ERROR -- ws2: OB checksum mismatch, have -961054908 want -1108044634 [fUSD
"OB checksum mismatch, have -961054908 want -1108044634 [fUSD"
I, [2024-01-07T22:08:50.998627 #16770] INFO -- ws2: client closed
Since digest/hmac removed in ruby 2.2.0-preview1 and further versions
authentication will not work. We need to add support for both libraries.
New library docs: http://ruby-doc.org/stdlib-2.1.0/libdoc/openssl/rdoc/OpenSSL/HMAC.html
trace:
2.2.1 :026 > api = Bitfinexrb::AccountInfo.new
=> #<Bitfinexrb::AccountInfo:0x007fc3ec11b1d0 @api_version="v1", @key=nil, @secret=nil>
2.2.1 :027 > api.all
LoadError: library not found for class Digest::HMAC -- digest/hmac
from /Users/andrew/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/digest.rb:15:in `const_missing'
from /Users/andrew/.rvm/gems/ruby-2.2.1/gems/bitfinex-api-rb-0.0.1/lib/bitfinexrb.rb:32:in `headers_for'
from /Users/andrew/.rvm/gems/ruby-2.2.1/gems/bitfinex-api-rb-0.0.1/lib/bitfinexrb/account_info.rb:7:in `all'
from (irb):27
from /Users/andrew/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
As it's seen on the screenshot, I'm placing 2 consequent orders via API v2 websockets.
First step: Buy IOT for BTC
Second step: Sell IOT for ETH
Third step: Sell ETH for BTC (not on the screen since 2nd step failed)
After the first order (IOT buy) goes through, I request IOT wallet update (calc function) to get actual amount available. I receive response:
[0, "wu", ["exchange", "IOT", 60.9, 0, 60.9]]
which tells that 60.9 IOT is available (not null)
I then send order 2 (Sell IOT), but it returns error
"Invalid order: not enough exchange balance for -60.9 IOTETH at 0.00269".
Same order works via UI and REST. If I resend this order again, I immediately get disconnected and reconnected again. I can't figure whats wrong with my order and why im getting reconnected
Hello! I need functionality of the APIv2 but current 1.0.6 version is not synchronized with Rubygems and bundle update
command has no effect. Can you please release Github version to Rubygems to give possibility to get latest changes?
Please, show somewhere, that the actual title of the gem to include is 'bitfinex', not 'bitfinex-api-rb' and neither 'bitfinex-rb' or anything else.
I can figure it out, but I'm just looking for some quickstart-style examples -- just to save some time :-)
Thanks!
Hi , I use like
ans = Bitfinex::Client.new.new_order('BTCUSD' , amounts , 'exchange market' , 'sell')
order_id = ans['id']
info = Bitfinex::Client.new.order_status(order_id)
will get "Bitfinex::NotFoundError" randomly from get "order_status" , not always but often
I think this is not gem's issue , but can your guys help me to fix it?
and I know I won't do that (ans = info) , but ... I think this is issue right? , or someone can answer me I need sleep how much second to get order_status ?
for an account with no margin capabilities, it refuses to put market orders because it wants to make a margin account
how do I order on market price w/out margin (I used the sample code on the bitfinex api site)
https://docs.bitfinex.com/reference#rest-auth-funding-offers
bitfinex-api-rb/lib/rest/v2/margin.rb
Line 8 in 063014b
ERROR -- : https://api.bitfinex.com/v2/auth/r/offers (Bitfinex::NotFoundError)
FOK and EXCHANGE FOK orders are considered invalid by the server when placing via Websockets v2
Hi
When I try to run the ticker.rb example, Ruby returns the following error:
terminate called after throwing an instance of 'std::runtime_error'
what(): Encryption not available on this event-machine
I compiled EventMachine with SSL but still get this error, any clue?
Thanks
I think it's better if we can create a new client with specified secret and api_key like following:
Bitfinex::Client.new(secret, api_key)
derp
Until 17.02 my code did work, but now It does not work anymore without me having done any changes to the code. I have been listening for the ticker events over Websocket like this:
Bitfinex::Client.configure do |conf|
conf.websocket_api_endpoint = "wss://api.bitfinex.com/ws"
end
symbol = "btcusd"
api = Bitfinex::Client.new
api.listen_ticker(symbol) do |tick_json|
puts "#{symbol}: #{tick_json}"
end
api.listen!
No ticker events have logged out starting somewhere from 17.02 (it was working for months previously using the same code). Is there a reason why it should have stopped working? I did not manage to find any announcements nor can I see anything about this in the API documentation for v1 (https://docs.bitfinex.com/v1/docs/ws-general).
I have been using pretty old version of bitfinex-rb
(version 0.1.0) for years. As I understand then bitfinex-rb does not support v1 anymore thus upgrading my code to use a newer version is a bigger change and I don't even know if that would make a difference.
missing functionality
client.ledgers is not implemented
require 'bitfinex'
require 'dotenv'
Dotenv.load()
#p ENV
endpoint = "https://api.bitfinex.com/auth/r/ledgers/hist"
rclient = Bitfinex::RESTv2.new({
:api_key => ENV['BKEY'],
:api_secret => ENV['BSEC'],
:url => endpoint,
})
#p rclient.ticker('tBTCUSD', 'fUSD')
p rclient.ledgers
This is what I'm looking for: https://docs.bitfinex.com/reference#rest-auth-ledgers
Hi, I'm facing the small issue with placing orders with Limit and Market. When I'm placing the orders it shows like. "Bitfinex::BadRequestError: This pair cannot be traded on margin". I have the balance in exchange wallet. But I tried to transfer the balance exchange wallet to margin wallet. But I'm not.
Please refer the below link.
the endpoint clearly needs a key, which is not documented anywhere.
I'm working on the Bitfinex API integration to my application. I have completed integration. But while I'm working with an application, in facing the errors related to Bitfinex API key and Secret Key. Could you please help me with this issue. Please refer the below-attached screencast. (I'm always getting same issues).
https://ibb.co/d62Pye
https://api.bitfinex.com/v1/tickers exists, but this endpoint is not listed in the public documentation?
Is there support planned for the v2 API for this gem at some point? Or does there exist a v2 Ruby implementation somewhere already?
Why the responses are not indexed, like ['order_id' : 999009, etc:etc]. Raw arrays are difficult to understand and can broke easily if the api are updated.
Hi
I am doing
~/.software/bitfinex-api-rb/lib> ruby bitfinex-api-rb.rb
and I get
/home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/specification.rb:2288:in `raise_if_conflicts': Unable to activate bitfinex-rb-0.0.11, because faraday-0.11.0 conflicts with faraday (>= 0.9.2, ~> 0.9.2), json-2.0.2 conflicts with json (>= 1.8.3, ~> 1.8.3) (Gem::ConflictError)
from /home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/specification.rb:1408:in `activate'
from /home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems.rb:220:in `rescue in try_activate'
from /home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems.rb:213:in `try_activate'
from /home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
from /home/zeno/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /home/zeno/.software/bitfinex-api-rb/lib/bitfinex.rb:7:in `<top (required)>'
from bitfinex-api-rb.rb:1:in `require_relative'
from bitfinex-api-rb.rb:1:in `<main>'
Is it possible to set the volume on a buy order to the maximum buying size?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ššš
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ā¤ļø Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.