ccxt icon indicating copy to clipboard operation
ccxt copied to clipboard

Lykke sell orders are performing buy orders

Open joaotnog opened this issue 6 years ago • 2 comments

  • OS: Windows 10
  • Programming Language version: Python 3.7.1
  • CCXT version: 1.29.10

I can execute buy orders at Lykke for BTC/EUR without issues using

lykke_api.create_market_buy_order('BTC/EUR', 0.01, {'trading_agreement': 'agree'})

When I try to use a sell command,

lykke_api.create_market_sell_order('BTC/EUR', 0.01, {'trading_agreement': 'agree'})

I get

ExchangeNotAvailable: POST https://hft-api.lykke.com/api/Orders/market 400 Bad Request {"Error":{"Code":"Rejected","Field":null,"Message":"The amount should be higher than minimal order size 1 EUR"}}

What seems to be happening is that it is performing a buy order even though the base currency is BTC. When I enter a value higher than 1 it does perform a buy instead of a sell order, deducting my EUR funds for BTC.

I have also tried the create_order function with side argument 'sell' instead of the wrapper and the same thing happens.

joaotnog avatar Jun 02 '20 11:06 joaotnog

@joaotnog hi!

Can you please paste your request+response sequence in verbose mode? (without your keys, of course)

That would help resolve it quicker:

  • https://github.com/ccxt/ccxt/wiki/FAQ#what-is-required-to-get-help

kroitor avatar Jun 02 '20 15:06 kroitor

I think I got the issue, the lykke script should be fixed to default the 'Asset' argument to BTC when selling.

The original failed response in verbose mode is below:

lykke_api.create_market_sell_order('BTC/EUR', .001, {'trading_agreement': 'agree'})

Request: POST https://hft-api.lykke.com/api/Orders/v2/market {'api-key': myapikey, 'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'python-requests/2.23.0', 'Accept-Encoding': 'gzip, deflate'} {"AssetPairId":"BTCEUR","OrderAction":"Sell","Volume":0.001,"Asset":"EUR","trading_agreement":"agree"}

Response: POST https://hft-api.lykke.com/api/Orders/v2/market 400 {'Server': 'nginx', 'Date': 'Fri, 05 Jun 2020 18:57:27 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Request-Context': 'appId=myappid} {"Error":{"Code":"Rejected","Field":null,"Message":"The amount should be higher than minimal order size 1 EUR"}}
Traceback (most recent call last):

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 570, in fetch
    response.raise_for_status()

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\requests\models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)

HTTPError: 400 Client Error: Bad Request for url: https://hft-api.lykke.com/api/Orders/v2/market


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-32-49552a6c10fc>", line 1, in <module>
    lykke_api.create_market_sell_order('BTC/EUR', .001, {'trading_agreement': 'agree'})

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 1783, in create_market_sell_order
    return self.create_order(symbol, 'market', 'sell', amount, None, params)

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\lykke.py", line 266, in create_order
    result = getattr(self, method)(self.extend(query, params))

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 450, in inner
    return entry(_self, **inner_kwargs)

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 477, in request
    return self.fetch2(path, api, method, params, headers, body)

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 473, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 583, in fetch
    self.handle_rest_errors(http_status_code, http_status_text, http_response, url, method)

  File "C:\Users\Joao\AppData\Local\Continuum\anaconda3\envs\arb\lib\site-packages\ccxt\base\exchange.py", line 610, in handle_rest_errors
    raise error(' '.join([method, url, string_code, http_status_text, body]))

ExchangeNotAvailable: POST https://hft-api.lykke.com/api/Orders/v2/market 400 Bad Request {"Error":{"Code":"Rejected","Field":null,"Message":"The amount should be higher than minimal order size 1 EUR"}}

And it works when I place

lykke_api.create_market_sell_order('BTC/EUR', trading_vol, {'trading_agreement': 'agree','Asset':'BTC'})

instead of

lykke_api.create_market_sell_order('BTC/EUR', trading_vol, {'trading_agreement': 'agree'})

So from their documentation (https://hft-api.lykke.com/swagger/ui/#/) the argument 'Asset' is required but it defaults to 'EUR' when a sell order is sent with ccxt even though the base currency is BTC. When 'Asset':'BTC' is sent the execution runs properly, selling BTC in exchange of EUR.

Also from their documentation, /api/Orders/market is deprecated and now it is /api/Orders/v2/market. In ccxt it is defaulting to the deprecated endpoint. In my log it is correct because I fixed the lykke script locally.

joaotnog avatar Jun 05 '20 19:06 joaotnog