sammchardy / python-idex Goto Github PK
View Code? Open in Web Editor NEWIDEX v3 Exchange REST API python implementation
Home Page: https://python-idex.readthedocs.io/en/latest/
License: MIT License
IDEX v3 Exchange REST API python implementation
Home Page: https://python-idex.readthedocs.io/en/latest/
License: MIT License
Hey, when I'm trying to install your library on Windows, it crashes with error code 1. I googled the error reason and it was a incompatibility in pyethash library. Hm, is it possible to delete it from dependencies, maybe try to replace sha-3 hash implementation from another sources?
UPD: I found the possible solution, but it isn't convenient.
So, the problem is in the ethash lib. First, clone its repo from https://github.com/ethereum/ethash
Now, follow the instrcutions I found:
Installing ethash on Windows:
Open \src\libethash\mmap_win32.c for editing
Add the following after the last #include statement
#pragma comment(lib, "Shell32.lib")
Open \src\python\core.c
Replace:
#include <alloca.h>
with:
#if defined(_WIN32) || defined(WIN32)
#include <malloc.h>
#else
#include <alloca.h>
#endif
Run the following in the source code main folder
setup.py install
Now, when ethash is installed, you are able to install python-idex, run:
pip install python-idex. As ethash is already installed, it won't try to install it and all be OK.
**Util/_raw_api.py", line 208
except OSError, exp:
^
SyntaxError: invalid syntax
**
I am looking for where it can come from
this code from Contract function
client = Client(api_key, address, private_key)
tx_options = TransactionOptions(gas=150000, gas_price=20000000000)
client.deposit_funds(
asset="USD",
quantity=1123,
tx_options=tx_options,
)
error
File "/Users/PycharmProjects/pythonProject/pythonProject2/test_del_deposits.py", line 20, in
client.deposit_funds(
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 1219, in deposit_funds
return self._deposit_funds(
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 310, in _deposit_funds
res = self.execute_idex_contract_function(
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 242, in execute_idex_contract_function
"abi": self.exchange_abi(),
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 219, in exchange_abi
with open(Path(file).parent / "contracts" / "Exchange.abi.json") as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/opt/homebrew/lib/python3.9/site-packages/idex/contracts/Exchange.abi.json'
Using version 0.3.2:
Traceback:
ImportError: dlopen(/Users/{venv}/lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: /Users/{venv}/lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so
Reason: image not found
When trying to use websockets.py for subscribing to idex data, ia have an error:
"
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/IDEXbot.py", line 141, in
loop.run_until_complete(main())
File "C:\Users\Administrator\miniconda3\lib\asyncio\base_events.py", line 583, in run_until_complete
return future.result()
File "C:/Users/Administrator/PycharmProjects/untitled/IDEXbot.py", line 97, in main
await ism.subscribe(SubscribeCategory.markets,subscribe_list,['market_cancels', 'market_orders', 'market_trades'])
File "C:\Users\Administrator\PycharmProjects\untitled\idex\asyncio\websockets.py", line 246, in subscribe
await self._conn.send_message(category, req_msg)
File "C:\Users\Administrator\PycharmProjects\untitled\idex\asyncio\websockets.py", line 144, in send_message
await self._socket.send(socket_msg)
AttributeError: 'NoneType' object has no attribute 'send'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000000E14FE061C8>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000000E14FDF4358>, 355.937)]']
connector: <aiohttp.connector.TCPConnector object at 0x000000E14FE06208>
"
How should i fix that?
Hi, it appears that on all calls such as to get_tickers
, there is a small chance that the client hangs forever. Maybe a timeout should be added?
I just try to connect and the file send me that. Can anyone can help me ? thanks :)
Traceback (most recent call last): File "test.py", line 1, in <module> from idex.client import Client File "/usr/local/lib/python3.6/site-packages/idex/client.py", line 13, in <module> from .utils import sha3, ecsign, encode_int32 File "/usr/local/lib/python3.6/site-packages/idex/utils.py", line 9, in <module> import coincurve File "/usr/local/lib/python3.6/site-packages/coincurve/__init__.py", line 1, in <module> from coincurve.context import GLOBAL_CONTEXT, Context File "/usr/local/lib/python3.6/site-packages/coincurve/context.py", line 4, in <module> from coincurve.flags import CONTEXT_ALL, CONTEXT_FLAGS File "/usr/local/lib/python3.6/site-packages/coincurve/flags.py", line 1, in <module> from ._libsecp256k1 import lib ImportError: dlopen(/usr/local/lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib Referenced from: /usr/local/lib/python3.6/site-packages/coincurve/_libsecp256k1.cpython-36m-darwin.so Reason: image not found
Hello the problem with get_order_book is that they show only one order in ask and one in bid. I think the problem come to the new API update of Idex. You have to put 'count' which show between 1 and 100 orders as you wish.
Thanks
Some other API's (e.g. python-binance) allow to place order at market price.
Is there any plan adding this for python-idex? Idex itself supports this feature.
Has anyone conducted a security audit of this repository?
to debug I used this dockerfile. it worked with requirements.txt changing rlp to: rlp==1.0.1
FROM python:3
RUN mkdir /app
ADD python-idex /app/idex
WORKDIR /app/idex
RUN python3 setup.py install
Traceback (most recent call last):
File "/home/k/PycharmProjects/idex/test.py", line 1, in
from idex.client import Client
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/idex/client.py", line 11, in
from ethereum.utils import sha3, ecsign, encode_int32
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/ethereum/init.py", line 11, in
from . import slogging # noqa
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/ethereum/slogging.py", line 6, in
from ethereum.utils import bcolors, is_numeric
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/ethereum/utils.py", line 11, in
import rlp
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/rlp/init.py", line 1, in
from . import sedes # noqa: F401
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/rlp/sedes/init.py", line 4, in
from .big_endian_int import BigEndianInt, big_endian_int # noqa: F401
File "/home/k/environments/testbed_env/lib/python3.6/site-packages/rlp/sedes/big_endian_int.py", line 1, in
from eth_utils import (
ImportError: cannot import name 'int_to_big_endian'
in set_wallet_address()
there's this check to see if the private key is valid
if private_key:
if re.match(r"^0x[0-9a-zA-Z]{64}$", private_key) is None:
raise(IdexException("Private key in invalid format must satisfy 0x[0-9a-zA-Z]{64}"))
Why would the private key start with 0x
? I thought only public addresses started with the 0x prefix? Is there some conversion step I'm missing to convert my private key to a form that starts with 0x? As the code stands now I get this "Private key in invalid format error" every time. Did you mean for this to validate the private key or was this intended to validate public address
instead like this?
if address:
if re.match(r"^0x[0-9a-zA-Z]{64}$", address) is None:
raise(IdexException("Address in invalid format must satisfy 0x[0-9a-zA-Z]{64}"))
self._wallet_address = address.lower()
Can you add market order type? Seems like limit order doesn't work well now, because get_order_books() returns empty now.
Bug: create_trade is not working for coins like LTO, WMB, EPY that have less than 18 decimals.
from idex.client import Client
client = Client("redacted", "redacted")
depth = client.get_order_book(market, 1)
orderHash = depth["asks"][0]["orderHash"]
amount = depth["asks"][0]["amount"]
order = client.create_trade(orderHash, "WMB", amount)
print(order)
If u try to make an order to sell some bug quantities of token, like hundreds of millions, then function BaseClient._convert_to_currency_quantity() has such bug: in the last line return str(res)
if res is quite big, str() returns such format like 1.1337420e+25
and this causes some errors and exceptions further if u try to place new order. The solution is to replace this line to return '{:d}'.format(int(res))
then it will return ok numbers like 113374200000000000000000
Hello, I beg for an example (ideally for chain_gas_price) of IdexSocketManager.subscribe().
Also, in order to run without an error, line 14 of test_websocket_connect.py had to be changed to
ism = await IdexSocketManager(loop, None)
balances = client.get_my_balances("0xD234221C38Ea33B5D785c02B2185CbBAFB0F7b18")
print(balances)
returns
{}
Am I doing something wrong?
Also I can not create orders..
order = client.create_order('ETH', 'TUSD', 145, 0.15)
results in
idex.exceptions.IdexAPIException: IdexAPIException: You have insufficient funds to place this order.
Thanks!!
Private Api not working for me, create order, like in the example, or cancel order doesnt work.
python 3.6.6 windows 10/windows server2012
result = client.create_order(symbols[1], symbols[0], price, amount)
File "C:\Users\Administrator\venv\lib\site-packages\idex\decorators.py", line 8, in check_address
return f(self, *args, **kwargs)
File "C:\Users\Administrator\venv\lib\site-packages\idex\client.py", line 1260, in create_order
return self.create_order_wei(token_buy, token_sell, amount_buy, amount_sell)
File "C:\Users\Administrator\venv\lib\site-packages\idex\decorators.py", line 8, in check_address
return f(self, *args, **kwargs)
File "C:\Users\Administrator\venv\lib\site-packages\idex\decorators.py", line 16, in check_private_key
return f(self, *args, **kwargs)
File "C:\Users\Administrator\venv\lib\site-packages\idex\client.py", line 1328, in create_order_wei
return self._post('order', True, hash_data=hash_data)
File "C:\Users\Administrator\venv\lib\site-packages\idex\client.py", line 250, in _post
return self._request('post', path, signed, **kwargs)
File "C:\Users\Administrator\venv\lib\site-packages\idex\client.py", line 229, in _request
return self._handle_response(response)
File "C:\Users\Administrator\venv\lib\site-packages\idex\client.py", line 237, in _handle_response
raise IdexAPIException(response, response.status_code, response.text)
idex.exceptions.IdexAPIException: IdexAPIException: Cannot read property 'message' of undefined
Hey! Awesome library! I work with IDEX and just wanted to get in touch if possible about the upcoming changes to our realtime API and work with you to make sure this library is ready for the change!
I am "+B" in our Discord if you wanted to get in touch, there is a "#developers" chat there, we also released the first draft of the Typescript library offering it: https://github.com/AuroraDAO/datastream-client-js
Let me know! Thanks!
i making deposit matic from example here, but taking error
File "/Users/PycharmProjects/pythonProject/pythonProject2/svalka/test_del_deposits.py", line 16, in
client.associate_wallet(wallet_address=wallet_address)
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 840, in associate_wallet
return self._post("wallets", sign_type=SignType.TRADE, data={"wallet": wallet_address})
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 397, in _post
return self._request("post", path, sign_type, **kwargs)
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 378, in _request
return self._handle_response(response)
File "/opt/homebrew/lib/python3.9/site-packages/idex/client.py", line 387, in _handle_response
raise IdexAPIException(response, response.status_code, response.text)
idex.exceptions.IdexAPIException: IdexAPIException: INVALID_HMAC_SIGNATURE - The HMAC signature is invalid
Hello!
When I try to init client like
self.__client = Client(address, pk)
I got an error from idex:
{'result': 'error', 'errors': ['[LAMBDA-RUNNER]\n FAILED TO INITIALIZE LAMBDA! \n \n Our initialization function expects either one or two arguments, however, \n you provided 3 parameters.', "Cannot set property 'agent' of undefined"]}
It is a result of get_next_nonce(address) function.
What could be wrong?
Thanks!
Hello,
Is there any time-frame on when deposit / withdrawal will be implemented? I really like your API wrappers and hope to use them on a couple of projects but this functionality is essential for that.
Thanks,
Joseph.
Hi, I have this error:
Traceback (most recent call last):
File "***.py", line 1, in <module>
from idex.client import Client
File "/usr/lib/python2.7/site-packages/idex/client.py", line 10, in <module>
from ethereum.utils import sha3, ecsign, encode_int32
File "/usr/lib/python2.7/site-packages/ethereum-2.3.1-py2.7.egg/ethereum/__init__.py", line 11, in <module>
from . import slogging # noqa
File "/usr/lib/python2.7/site-packages/ethereum-2.3.1-py2.7.egg/ethereum/slogging.py", line 6, in <module>
from ethereum.utils import bcolors, is_numeric
File "/usr/lib/python2.7/site-packages/ethereum-2.3.1-py2.7.egg/ethereum/utils.py", line 11, in <module>
import rlp
File "/usr/lib/python2.7/site-packages/rlp/__init__.py", line 1, in <module>
from . import sedes # noqa: F401
File "/usr/lib/python2.7/site-packages/rlp/sedes/__init__.py", line 1, in <module>
from . import raw # noqa: F401
File "/usr/lib/python2.7/site-packages/rlp/sedes/raw.py", line 9, in <module>
from rlp.atomic import Atomic
File "/usr/lib/python2.7/site-packages/rlp/atomic.py", line 4
class Atomic(metaclass=abc.ABCMeta):
^
SyntaxError: invalid syntax
My source:
from idex.client import Client
client = Client(***, ***)
currencies = client.get_currencies()
log("Currencies: " % currencies)
exit(0)
Running setup.py bdist_wheel for ethereum ... error
Complete output from command /home/el/.virtualenv/exchange/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-u6ddgle2/ethereum/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmpdqs7mi_opip-wheel- --python-tag cp36:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'bdist_wheel'
Failed building wheel for ethereum
And it just starts cascading from there... final output:
Command "/home/el/.virtualenv/exchange/bin/python3 -u -c "import setuptools,
tokenize;file='/tmp/pip-build-04jb3ffi/pyethash/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-17on7ecr-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/el/.virtualenv/exchange/include/site/python3.6/pyethash" failed with error code 1 in /tmp/pip-build-04jb3ffi/pyethash/
Hello, first of all, thank you for free your code. I just installed the package and tried the basic script that you post but it throws an error when trying to open an order, I'm able to get my balances so it isn't a problem with the address and private key.
It throws the error in this line:
order = client.create_order('EOS', 'ETH', '0.00110120', '154')
The exception:
Traceback (most recent call last): File "/home/rfenzo/Desktop/idextrader.py", line 17, in <module> order = client.create_order('EOS', 'ETH', '0.00110120', '154') File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 1228, in create_order return self.create_order_wei(token_buy, token_sell, amount_buy, amount_sell) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 1300, in create_order_wei return self._post('order', True, hash_data=hash_data) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 144, in _post return self._request('post', path, signed, **kwargs) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 123, in _request return self._handle_response(response) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 135, in _handle_response raise IdexAPIException(response) idex.exceptions.IdexAPIException: IdexAPIException: Order signature invalid
I've been able to make new orders, but when I try to cancel them, i'm getting this signature error. Any ideas?
Traceback (most recent call last): File "/home/rfenzo/CryptoWallet/code/idextrader.py", line 33, in <module> client.cancel_order(last_buy_order) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 1397, in cancel_order return self._post('cancel', True, hash_data=hash_data, json=json_data) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 144, in _post return self._request('post', path, signed, **kwargs) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 123, in _request return self._handle_response(response) File "/home/rfenzo/.local/lib/python3.5/site-packages/idex/client.py", line 135, in _handle_response raise IdexAPIException(response) idex.exceptions.IdexAPIException: IdexAPIException: Cancel signature invalid. Please try again.
where the order is placed like this:
order = client.create_order(...)
last_buy_order = order["orderHash"]
I couldn't spot any error on your returnOpenOrders
call but it's returning "error": "Cannot read property 'toLowerCase' of undefined"
So I just started playing around with idex's API today so I'm not sure if this is an issue on idex's API or there is a real issue with your wrapper.
to make the client setup work I had to change requirements.txt changing rlp from rlp==0.4.7 to rlp==1.0.1
https://github.com/AuroraDAO/idex-api-docs#order shows more variables that client.create_order is not sending.
All signatures must be in the { v, r, s } form where v is a Number type between 27 and 28, and r and s are both hex strings with the standard 0x prefix.
https://github.com/sammchardy/python-idex/blob/master/idex/client.py#L1307 does not send this information.
Please fix?
Hi.
I'm trying to use the api as follows:
client = Client("public_key", "private_key")
r = client.create_order(
token_buy = "EOS", # The name or address of the token you will receive as a result of the trade
token_sell = "ETH", # The name or address of the token you will lose as a result of the trade
price = eth_price, # The price in token_sell you want to purchase the new token for
quantity = amount # The amount of token_buy you will receive when the order is fully filled
)
which receives an error from idex-API:
IdexAPIException: IdexAPIException: ER_WARN_DATA_OUT_OF_RANGE: Out of range value for column 'nonce' at row 1
Looking in to the python-idex source-code, it seems _get_nonce
is used to create the nonce for create_order
def _get_nonce(self):
"""Get a unique nonce for request
"""
return int(time.time() * 1000)
which seems to contradict
https://github.com/AuroraDAO/idex-api-docs
All hashes which are to be signed require a nonce parameter to derive, which must be a numeric value
that increases by 1 with every message that requires a nonce.
...
A nonce must increase by 1 for every API call that requires one,
i.e. you cannot use the same nonce for an order and then a withdrawal.
I saw get_my_next_nonce
exists, but create_order
doesnt seems to use that one.
Am I using the API in a wrong way?
Any help would be much appreciated :)
Pycrypto (from here https://www.dlitz.net/software/pycrypto/) does not contain any keccak... so i have an error "cannot import name 'keccak' from 'Crypto.Hash' (C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\pycrypto-2.6.1-py3.7-win-amd64.egg\Crypto\Hash_init_.py)"
when I try the get_order_books() method I get the following error:
idex.exceptions.IdexAPIException: IdexAPIException: Parameter address or market is required
But it does not takes any args..
Traceback (most recent call last):
File "idexV2.py", line 6, in
client = Client(address, private_key)
File "/usr/local/lib/python3.6/dist-packages/idex/client.py", line 53, in init
self.set_wallet_address(address, private_key)
File "/usr/local/lib/python3.6/dist-packages/idex/client.py", line 170, in set_wallet_address
self._start_nonce = nonce_res['nonce']
KeyError: 'nonce'
Hello
The documentation says that you can add custom parameters to the POST requests like so: "client.get_ticker('ETH_SAN', requests_params={'timeout': 5})" but this results in the TypeError "got an unexpected keyword argument 'requests_params'"
Thanks
I always get this error when trying get_order_book(ETH_ICX)
idex.exceptions.IdexAPIException: IdexAPIException: Market ETH_ICX not found
**not only ICX, I tried every possible token, all returning same error.
**edit
I found they use another URL and path to get orderbook, here's my simple python script to get orderbook:
url = 'https://ns5qa7zsuj.execute-api.ca-central-1.amazonaws.com/prod/returnOrderBookForMarket'
payload = {"selectedMarket":"ETH","tradeForMarket":"AION"}
r = requests.post(url, data=json.dumps(payload))
js = json.loads(r.content.decode('utf-8'))
Hi I've Been Trying To Withdraw funds from the "withdraw_funds" method and I've defined my api_key, api_secret, private_key in my idex client but I'm getting the error below? has anyone successfully withdrawn funds from IDEX Using This SDK
I setup and run the code as specified in the docs. However, this error message shows up.
Traceback (most recent call last):
File "idexV2.py", line 1, in
from idex.client import Client
File "/usr/local/lib/python3.5/dist-packages/idex/client.py", line 10, in
from ethereum.utils import sha3, ecsign, encode_int32
File "/usr/local/lib/python3.5/dist-packages/ethereum/init.py", line 11, in
from . import slogging # noqa
File "/usr/local/lib/python3.5/dist-packages/ethereum/slogging.py", line 6, in
from ethereum.utils import bcolors, is_numeric
File "/usr/local/lib/python3.5/dist-packages/ethereum/utils.py", line 13, in
from rlp.utils import decode_hex, encode_hex, ascii_chr, str_to_bytes
ImportError: cannot import name 'decode_hex'
how to create a sell order by using api ?
Hello,
It will be cool if we can have all open orders in all markets from one address.
I saw that we can do that in Idex API if you put an empty string for the market variable.
Thanks a lot for your lib, you are genius :)
"On Monday, Oct 8 at 12pm noon Pacific time breaking changes will be introduced to the IDEX API which must be accounted for within your integrations."
I'm particularly interested in returnOpenOrders, returnTradeHistory and returnOrderBook being updated with the count parameter as the default is unusable for me.
Thanks
The old version had this format: Client(address, privKey)
but the new version has this format Client(apiKey, address, privKey)
If you leave the api key out and use it like the old format (address, privatekey) it sends the private key as the address to idex servers. So people who update the code but don't add the api key get their private key sent to IDEX servers and it returns Invalid address
Maybe do a sanity check for required 3rd parameter on Client instantiation
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.