question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't place order at btcmarkets (v1.10.503) HTTP 400 Bad Request

See original GitHub issue

I cannot place an order at btcmarkets. I am able to retrieve my position, therefore I assume that my private key is working, and that request signing is working too. Any ideas? Happy to contribute BTC to you if someone can find a fix 😃

Many thanks Nick

  • OS: Fedora (Linux)
  • Programming Language: Python
  • CCXT version: 1.10.503
  • Exchange: btcmarkets
  • Method: create_order
import argparse
import logging
import sys
import ccxt
from ccxt import btcmarkets
from ccmgr.accounts import Accounts

format = '[%(asctime)s] {%(filename)s:%(funcName)s:%(lineno)d} %(levelname)s - %(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=format)
LOG = logging.getLogger(__name__)
parser = argparse.ArgumentParser(description='BTC Markets Test Script')
parser.add_argument('accounts', type=str, help='location of csv account config')    

args = parser.parse_args()

accounts = Accounts(args.accounts)
params = {'apiKey': accounts.data['btcmarkets'][0], 'secret':accounts.data['btcmarkets'][1], 'verbose':True}
exch = btcmarkets(params)

LOG.info('ccxt version {}'.format(ccxt.__version__))

LOG.info("Fetching positions")
bal = exch.fetch_balance()
LOG.info(bal)

LOG.info('Creating order')
raw = exch.create_order('BTC/AUD', 'limit', 'Buy', 0.0001, price=10000.00)
LOG.info(raw)

Note that ccmgr.accounts.Accounts is a custom class that retrieves my keys. You can simply replace accounts.data[‘btcmarkets’][0] with your own key and secret.

Output is:

[2017-12-29 13:55:37,758] {btcmarkets_simple.py:<module>:20} INFO - ccxt version 1.10.503
[2017-12-29 13:55:37,758] {btcmarkets_simple.py:<module>:22} INFO - Fetching positions
GET https://api.btcmarkets.net/account/balance
Request: {'Content-Type': 'application/json', 'apikey': 'xxxxx', 'timestamp': '1514516137758', 'signature': 'T2COAI34hvSsnZd05qT0iZntf5tD8N/oAx+IrOCZ8Svetl74w4Ufu1qBLA4B2Dw4ZloIQDADCi8kyay8HWgOvw==', 'Accept-Encoding': 'gzip, deflate'} None
GET https://api.btcmarkets.net/account/balance
Response: {'Date': 'Fri, 29 Dec 2017 02:55:37 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': '__cfduid=d36128a1b78b73b5835f621ad389ea7e81514516137; expires=Sat, 29-Dec-18 02:55:37 GMT; path=/; domain=.btcmarkets.net; HttpOnly', 'Server': 'cloudflare-nginx', 'CF-RAY': '3d497b46495d1d92-MEL', 'Content-Encoding': 'gzip'} [{"balance":1098835442166,"pendingFunds":800000000000,"currency":"AUD"},{"balance":0,"pendingFunds":0,"currency":"BTC"},{"balance":0,"pendingFunds":0,"currency":"LTC"},{"balance":0,"pendingFunds":0,"currency":"ETH"},{"balance":0,"pendingFunds":0,"currency":"XRP"},{"balance":0,"pendingFunds":0,"currency":"ETC"},{"balance":0,"pendingFunds":0,"currency":"BCH"}]
[2017-12-29 13:55:38,023] {btcmarkets_simple.py:<module>:24} INFO - {'info': [{'balance': 1098835442166, 'pendingFunds': 0, 'currency': 'AUD'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'BTC'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'LTC'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'ETH'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'XRP'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'ETC'}, {'balance': 0, 'pendingFunds': 0, 'currency': 'BCH'}], 'AUD': {'free': 2988.3544216600003, 'used': 0, 'total': 2988.3544216600003}, 'BTC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'LTC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'ETH': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'XRP': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'ETC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'BCH': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'free': {'AUD': 2988.3544216600003, 'BTC': 0.0, 'LTC': 0.0, 'ETH': 0.0, 'XRP': 0.0, 'ETC': 0.0, 'BCH': 0.0}, 'used': {'AUD': 8000.0, 'BTC': 0.0, 'LTC': 0.0, 'ETH': 0.0, 'XRP': 0.0, 'ETC': 0.0, 'BCH': 0.0}, 'total': {'AUD': 2988.3544216600003, 'BTC': 0.0, 'LTC': 0.0, 'ETH': 0.0, 'XRP': 0.0, 'ETC': 0.0, 'BCH': 0.0}}
[2017-12-29 13:55:38,023] {btcmarkets_simple.py:<module>:26} INFO - Creating order
POST https://api.btcmarkets.net/order/create
Request: {'Content-Type': 'application/json', 'apikey': 'xxxxxxx', 'timestamp': '1514516138023', 'signature': 'uM2aziGPvAXD0VZJKSbh9JCqIzyvNfn0dw+fGHJzd0DsfAs+OBUMCfsDUmk6hovxr+2xI35zlGGkJLbwuMgXMQ==', 'Accept-Encoding': 'gzip, deflate'} currency=AUD&instrument=BTC&price=1000000000000.0&volume=10000.0&orderSide=Ask&ordertype=Limit&clientRequestId=1514516138023
Traceback (most recent call last):
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/base/exchange.py", line 345, in fetch_requests
    response.raise_for_status()
  File "/home/nick/anaconda3/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.btcmarkets.net/order/create

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/media/sf_Google_Drive/nick/development/ccmgr/ccmgr/apps/btcmarkets_simple.py", line 27, in <module>
    raw = exch.create_order('BTC/AUD', 'limit', 'Buy', 0.0001, price=10000.00)
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/btcmarkets.py", line 174, in create_order
    response = self.privatePostOrderCreate(self.extend(order, params))
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/btcmarkets.py", line 216, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/base/exchange.py", line 290, in fetch2
    return self.fetch_requests(request['url'], request['method'], request['headers'], request['body'])
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/base/exchange.py", line 358, in fetch_requests
    self.handle_rest_errors(e, response.status_code, self.last_http_response, url, method)
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/base/exchange.py", line 437, in handle_rest_errors
    self.raise_error(error, url, method, exception if exception else http_status_code, response)
  File "/home/nick/GoogleDrive/nick/development/ccxt/python/ccxt/base/exchange.py", line 272, in raise_error
    details,
ccxt.base.errors.ExchangeNotAvailable: btcmarkets POST https://api.btcmarkets.net/order/create 400 Client Error: Bad Request for url: https://api.btcmarkets.net/order/create <html>
<head>
<title>Bad request.</title>
</head>
<body>
Bad request.
</body>
</html>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nickos556commented, Dec 30, 2017

Its now working -thank you very much! Have made a small donation to your BTC wallet… Keep up the good work 😃

1reaction
nickos556commented, Dec 29, 2017

Note I have replaced my apiKey with ‘XXXXXX’ in the info above, thats not my real key 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >
binance eth-btc order 400 bad request - Stack Overflow
The root cause on my side was the precision of quantities and prices in my requests. If anyone is getting 400 Bad Request...
Read more >
ERROR : place a BUY order and return 400 Bad Request and ...
I can obtain AccessToken; however, I can't move forward from here. For Websocket, I can logged in, and it return back o(Open Frame)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found