Giter Site home page Giter Site logo

makarworld / pymexc Goto Github PK

View Code? Open in Web Editor NEW
27.0 1.0 10.0 150 KB

Unofficial python library for interacting with the MEXC crypto exchange

Home Page: https://pypi.org/project/pymexc/

License: MIT License

Python 100.00%
api python cryptocurrency cryptoexchange mexc sdk

pymexc's Issues

Timestamp for this request is outside of the recvWindow.

HI.
I want to create new order:

from pymexc import spot

api_key = "apikey"
api_secret = "secretkey"

spot_client = spot.HTTP(api_key = api_key, api_secret = api_secret)
response = spot_client.new_order(symbol='BTCUSDT', side='BUY', order_type='MARKET', quote_order_qty=6)
print(response)

But I get an error:

pymexc.base.MexcAPIError: (code=700003): Timestamp for this request is outside of the recvWindow.

I try to increase the value of recvWindow:

spot_client.recvWindow = 30000

but nothing change :(
The same error is occured when I try initialize WebSocket client (example.py in examples)

Where did I wrong?

Connection is already closed. websocket future ticker subscription.

Exception in thread Thread-2 ():
Traceback (most recent call last):
File "C:\ProgramData\anaconda3\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\ProgramData\anaconda3\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\anaconda3\Lib\site-packages\pymexc\base_websocket.py", line 151, in
self.wsl = threading.Thread(target=lambda: self._ping_loop(
^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\site-packages\pymexc\base_websocket.py", line 101, in _ping_loop
self.ws.send(ping_payload)
File "C:\ProgramData\anaconda3\Lib\site-packages\websocket_app.py", line 253, in send
raise WebSocketConnectionClosedException(
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

Unable to use ws that require paramter

I am trying to use any of the futures ws that require a parameter to be set (kline_stream) and every time I am getting a Connection is already closed error.

ws_futures_client.kline_stream(handle_message, "BTC_USDT", "Min15")

spot_client.ticker_price() doesn't work

Hi,

I'm simply trying the following to get used to this library :

from pymexc import spot

api_key = 'abc'
api_secret = 'def'

spot_client = spot.HTTP(api_key = api_key, api_secret = api_secret)

print(spot_client.account_information())

print(spot_client.ticker_price())

Everything works fine until the last line. I have 2 problems here :

  • I didn't fully understand how to pass the arguments for a specific ticker, for example BTCUSDT

  • biggest problem : even if I try it with no argument, the doc says ":param symbol: (optional) If the symbol is not sent, all symbols will be returned in an array." So I should at least get an array as return, but instead I get the following error which I don't understand :

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/init.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymexc/spot.py", line 290, in ticker_price
return self.call("GET", "/api/v3/ticker/price",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymexc/base.py", line 100, in call
return response.json()
^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

What's wrong ?

futures websocket private channel empty

Tell me how to get balance and pos, order data through a private channel using websocket. I place orders manually in the app, deals appear, but the callbacks are empty.
What am I doing wrong?

from pymexc import futures

def onOrder(message):
    # handle websocket message
    print('onOrder')
    print(message)
def onPosition(message):
    # handle websocket message
    print('onPosition')
    print(message)
def onAsset(message):
    # handle websocket message
    print('onAsset')
    print(message)

SYM = "ETH_USDT"
    futures_client = futures.HTTP(api_key = my_secret_var.mexc_api_key, api_secret = my_secret_var.mexc_api_secret)
    ws_futures_client = futures.WebSocket(api_key = my_secret_var.mexc_api_key, api_secret = my_secret_var.mexc_api_secret, restart_on_error=True, trace_logging=True)
    ws_futures_client.order_stream(onOrder)
    ws_futures_client.asset_stream(onAsset)
    ws_futures_client.position_stream(onPosition)
    while True:
        # lastPrice = getLastPrice(SYM)
        # secho(f"{Now()} {SYM} price:{lastPrice['indexPrice']} time:{lastPrice['timestamp']} check sqltask", fg='magenta')
        sleep(1000)

my API key:
scr1

{'success': False, 'code': 602, 'message': 'Signature verification failed!'}

Hi, dear, problem with signature for futures
query_string = "&".join([f"{k}={v}" for k, v in sorted(kwargs.items())])
query_string = self.api_key + timestamp + query_string
signature = hmac.new(self.api_secret.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()

i tried change:
signature = hmac.new(query_string.encode('utf-8'), self.api_secret.encode('utf-8'), hashlib.sha256).hexdigest()

but same, checked everything is ok i dont know what can be wrong?

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.