GithubHelp home page GithubHelp logo

ohenrik / bitfinex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scottjbarr/bitfinex-py

58.0 58.0 32.0 338 KB

A Python client for the Bitfinex API

License: MIT License

Python 99.12% Makefile 0.88%

bitfinex's People

Contributors

avolution avatar dancre avatar dantimofte avatar fatsie avatar fccoelho avatar michielz avatar nhondong avatar ohenrik avatar oskarhandmark avatar sajam avatar sapph1re avatar scottjbarr avatar shanefontaine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitfinex's Issues

unhandled exception in restv1

2018-09-12 17:02:11,545 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 279, in process_update
handler.handle_update(update, self)
File "/usr/local/lib/python3.6/site-packages/telegram/ext/commandhandler.py", line 173, in handle_update
return self.callback(dispatcher.bot, update, **optional_args)
File "bitfinex-telegram/btfxbot.py", line 50, in wrapper
return passed_function(*args, **kwargs)
File "bitfinex-telegram/btfxbot.py", line 312, in cb_new_order
symbol=tradepair
File "/usr/local/lib/python3.6/site-packages/bitfinex/rest/restv1.py", line 142, in place_order
response = self._post("/order/new", payload=payload, verify=True)
File "/usr/local/lib/python3.6/site-packages/bitfinex/rest/restv1.py", line 108, in _post
raise BitfinexException(response.status_code, response.reason, content)
bitfinex.rest.restv1.BitfinexException: (400, 'Bad Request', {'message': 'Cannot evaluate your available balance, please try again'})

authenticated api error

I am trying to make a basic authenticated api and getting error.

from bitfinex import ClientV2 as Client2

BTFXCLIENT = Client2('api656j56ejejKey', 'apiSec56je56jjj56j5ret')
BTFXCLIENT.active_positions()

Always getting Error 10114 nonce Small when trying to get trades_history

Hi Henrik,

I try to use the function trades_history from restv2, but I always got:

Traceback (most recent call last):
File "", line 21, in
File "/home/nhondong/PycharmProjects/venv/lib/python3.6/site-packages/bitfinex/rest/restv2.py", line 330, in trades_history
response = self._post(path, raw_body, verify=True)
File "/home/nhondong/PycharmProjects/venv/lib/python3.6/site-packages/bitfinex/rest/restv2.py", line 89, in _post
raise BitfinexException(response.status_code, response.reason, content)
bitfinex.rest.restv2.BitfinexException: (500, 'Internal Server Error', ['error', 10114, 'nonce: small'])

from bitfinex.rest.restv2 import Client as Client2
key = config.bitfinex_apikey
secret = config.bitfinex_secret
BTFXCLIENT = Client2(key, secret)
TRADES = BTFXCLIENT.trades_history('tIOTUSD', limit=10) 
print(trades)

And an example for setting start and end would be nice.

Kind regards,

Nils

Stop limit orders via websocket v2 not supported

new_order("LIMIT", "tEOSUSD", "5", "4") is OK!, I don't know how to support stop limit for new_order().

update:

I edit client.py

copy new_order_op to new_order_op_stop_limit


def new_order_op_stop_limit(self, order_type, pair, amount, price, stop_limit_price,hidden=0, flags=None):

 #add  'price_aux_limit':stop_limit_price

    flags = flags or []
    client_order_id = wss_utils.UtcNow()
    return {
        'cid': client_order_id,
        'type': order_type,
        'symbol': wss_utils.order_pair(pair),
        'amount': amount,
        'price': price,
        'price_aux_limit':stop_limit_price,  
        'hidden': hidden,
        "flags": sum(flags)
    }

copy new_order to new_order_stop_limit()

def new_order_stop_limit(self, order_type, pair, amount, price, stop_limit_price, hidden=0, flags=list()):

    operation = self.new_order_op_stop_limit(order_type, pair, amount, price, stop_limit_price, 0, flags)
    data = [0,wss_utils.get_notification_code('order new'),None,operation]
    payload = json.dumps(data, ensure_ascii = False).encode('utf8')
    self.factories["auth"].protocol_instance.sendMessage(payload, isBinary=False)
    return operation["cid"]   

if price $5.0

exch_order = self.mywss.new_order_stop_limit("STOP LIMIT", "tEOSUSD", "4", "6","6.2")

exch_order = self.mywss.new_order_stop_limit("STOP LIMIT", "tEOSUSD", "-6", "4","3.9")

That's OK. Sorry, my English is not good

Feature Request: Add books and raw books endpoint of websocket API

Thank you for your effort, please considering add books and raw books endpoint of websocket API. Since request order book with REST api very often will be limit on bitfinex. Use websocket API can get realtime orderbook.
It need to find a way to effieciently organize the order book of different coins, and update them when new websocket data received. I think It also need to implement checksums function to make sure the local order book is correct.
Please considering add this feature, thank you.

reference:
https://docs.bitfinex.com/v2/reference#ws-public-order-books
http://blog.bitfinex.com/api/bitfinex-api-order-books-checksums/

Cannot call authenticate() on unestablished connection

Cannot call authenticate() on unestablished connection
Cannot call subscribe_to_candles() on unestablished connection
Cannot call new_order() on unestablished connection

code


import os
key = os.environ.get("my key")
secret = os.environ.get("my secret")

from bitfinex.websockets import BtfxWss

bm = BtfxWss(key, secret)

bm.authenticate(print)

bm.subscribe_to_candles("EOSUSD", "1m", print)
bm.start()

bm.new_order(order_type="LIMIT", pair="EOSUSD", amount="5", price="4", hidden=0)

Issue with websocket candles response

Not really sure if its an issue or not but I'm trying to gather real-time candle data and save it in a list using the websocket subscribe_to_candles response.

Now while this works for the most part I noticed that occasionally some minutes can get missing or there is no response for those minutes. Does anyone else have this problem or is it a known issue of the Bitfinex API response?

pip3 install bitfinex-v2 returnes file not found - README.md

Command: pip3 install bitfinex-v2 returns:

Collecting bitfinex-v2
Downloading https://files.pythonhosted.org/packages/a8/a0/e10703a05c2ed27d07ce4d5bdaabda3ed60030706bc2f1e6c935fe71cc7e/bitfinex-v2-0.5.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-62awd5et/bitfinex-v2/setup.py", line 15, in
with open("README.md", "r") as fh:
FileNotFoundError: [Errno 2] No such file or directory: 'README.md'

About the 'status' function

When I call the function 'status()', console will display the message(refer picture). Could let the message don't display?

image

Error creating new order

Hi I am getting this error when trying to communicate with Bitfinex using the WSClient:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 3267, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-aa43adbe623c>", line 1, in <module>
    create_order('tBTCUSD',0,4000)
  File "/home/fccoelho/Documentos/Projects_software/Trading/tradeboard/bitfinex_client.py", line 46, in create_order
    price=price,
  File "/usr/local/lib/python3.6/dist-packages/bitfinex/websockets/client.py", line 657, in new_order
    self.factories["auth"].protocol_instance.sendMessage(payload, isBinary=False)
AttributeError: 'NoneType' object has no attribute 'sendMessage'

Max retries exceeded with url

Hello ! I'm trying to load historical data using function of ClientV2() - candles. And i'm getting this annoying error - HttpConnectionPool(host='api-pub.bitfinex.com', port=443): Max retries exceeded with url: /v2/candles/trade:1m:tBTCUSDT/hist?start=1691749001000.0&end=1691809001000.0&limit=10000 (Caused by connectiontimeouterror (< urllib3.connection.HTPPSCONNECTION object at 0x0000277FC687AC0>, 'connection to api-pub.bitfinex.com timed out.)) (connect timeout=5.0'))). What is this exception? What did it caused by? Could you answer me please?

ImportError

Hi,
when I execute the following code, I get the data, but I even get the errormessage:
from bitfinex import ClientV2 as Client
ImportError: cannot import name 'ClientV2'

Code:

from bitfinex import ClientV2 as Client
client = Client(
os.environ.get('BITFINEX_KEY'),
os.environ.get('BITFINEX_SECRET')
)

client.ticker('tBTCUSD')

Any Ideas?

CID invalid for new orders

The cid seems to break placing new orders. However, I can still ping with a cid. Weird...

New order with cid returns the following error:
[0, 'n', [1546953056495, 'on-req', None, None, [None, None, 15469530564677380, 'tXRPUSD', None, None, -38, None, 'STOP', None, None, None, 1024, None, None, None, 0.3689, None, 0, 0, None, None, None, 0, 0, None, None, None, None, None, None, None], None, 'ERROR', 'cid: invalid']]

Pong seems to work fine with cid:
{'event': 'pong', 'cid': 15469530562543840, 'ts': 1546953056279}

I have made cid option for new orders for those who don't use it.
#28

Can't normally finish program with few websockets

I created wssclient and subscribed to candles with different symbols.

ws = WssClient()
ws.subscribe_to_candles(...)
ws.start()

After calling ws.close() my program can't finish it work because 'PoolThread-twisted.internet.reactor-0' does not stops.
For proper work i must stop this thread by myself calling

from twisted.internet import reactor
reactor.stop()

Someone else has this issue?

V1 Orders

Ive been trying to get a simple order function working and with a variety of formattings have had no luck.

I went as far as copy pasting the example code for v1 ordering and ensuring I had enough USD to cover the .01 btc and no luck, no orders show up.

Does this just mean that the v1 api is no longer fully operable or am I doing something wrong?

from bitfinex import WssClient, ClientV2, ClientV1

key = 'redacted'
secret = 'redacted'
client = ClientV1(key,secret, nonce_multiplier=999999.15)
symbol = 'ethusd' # Currency pair to trade
amount = '.15' # Amount to buy
price = '175' # Buy price
side = 'sell' # Buy or sell
ord_type = 'exchange market' # Which type
client.place_order(amount, price, side, ord_type, symbol, exchange='bitfinex')

0 values of counter in orderbook

Hi - I'm using the websocket endpoints to get the orderbook and trades.

I have some questions regarding its functioning:

  1. I see that the first return is the whole (filtered by limits) orderbook and then each forward message is an update to that. I understand that those new messages are new orders. In the case of orders that had been executed, do I have to check that with the trades?

  2. I see in the orderbook messages that there are 0 values in the counter. For example: [744498, [9342, 0, 1]]. What does this mean? I recognized that when the counter is 0, the amount is either -1 or 1, but couldn't get its meaning.

  3. In the trades endpoint, the first message is a large one with many trades, why is that? Are these trades from the last x minutes?

Thanks

How to get wallets history?

What parameters input the function wallets_history? For example, the wallet in yesterday, last month or someday.

image

Error in new order

I'm using python 3.7.4 in OSX

Now I'm getting this error:

 File "/Users/andre/git-repos/work/crypto_trader/python/test.py", line 22, in <module>
    trade_client.multi_order(operations=[order_operation])
  File "/usr/local/lib/python3.7/site-packages/bitfinex/websockets/client.py", line 719, in multi_order
    return [order[1].get("cid", None) for order in operations]
  File "/usr/local/lib/python3.7/site-packages/bitfinex/websockets/client.py", line 719, in <listcomp>
    return [order[1].get("cid", None) for order in operations]
KeyError: 1
[0, 'hb']
[0, 'n', [1566490238285, 'ox_multi-req', None, None, None, None, 'ERROR', 'input: invalid']]

My code is the following:

trade_client = WssClient(BFX_KEY, BFX_SECRET)
trade_client.authenticate(callback=handle_account_messages)

trade_client.start()
time.sleep(5)

order_operation = trade_client.new_order_op(
    order_type='FOK',
    symbol='BTCUSD',
    amount=0.004,
    price=1000.0
)

trade_client.multi_order(
    operations=[order_operation]
)```

Full orderbook data

Is there a way to get full orderbook data using the websocket or REST api? I only see ways to get the top 25/100 entires on the orderbook.

Can't create order because of library error

When creating order getting error:
File "...venv\lib\site-packages\bitfinex\websockets\client.py", line 648, in new_order set_cid=set_cid

File "...venv\lib\site-packages\bitfinex\websockets\client.py", line 562, in new_order_op client_order_id = utils.create_cid()

File "...venv\lib\site-packages\bitfinex\utils\__init__.py", line 16, in create_cid return int(float(now.strftime("%s.%f"))*10000)

ValueError: Invalid format string

I did some research, it works fine with upper 'S'.

I am using Python 3.7.0
Library version 1.1.4

Websocket funding Symbols are suppressed

The default helper for trade orders based on raw symbol pairs are causing issues for funding orders etc over websocket requests.

This line forces the funding pair fBTCUSD to become tfBTCUSD:

symbol = 't' + symbol if not symbol.startswith('t') else symbol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.