How can I post an order request via API?

1 visualización (últimos 30 días)
Fabio Barbosa
Fabio Barbosa el 6 de Abr. de 2018
Respondida: Brendan Hamm el 16 de Abr. de 2018
I'm having this issue with posting order requests to an exchange API.
In python the request would be:
import requests
orderData = {'symbol':'ethbtc', 'side': 'sell', 'quantity': '0.063', 'type': 'market', 'timeInForce': 'GTC'}
r = requests.post('https://api.hitbtc.com/api/2/order', data = orderData, auth=('ff20f250a7b3a414781d1abe11cd8cee', 'fb453577d11294359058a9ae13c94713'))
print(r.json())
And in cURL:
curl -X POST "https://api.hitbtc.com/api/2/order" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "symbol=ethbtc&side=sell&type=market&timeInForce=GTC&quantity=0.063"
I've already figured out the authentication process, but I can't seem to specify the request body. In python it is the orderData dictionary, but what about MatLab?
Thanks in advance!
  2 comentarios
Brendan Hamm
Brendan Hamm el 6 de Abr. de 2018
Before anyone answers this, I just want to point out that it appears in your r = requests.post(...) you are providing your keys.
I just want to make sure you do NOT have your private key listed here!
Fabio Barbosa
Fabio Barbosa el 6 de Abr. de 2018
Sorry not to make it clear before but those are NOT my keys. They're generic keys from the code provided by the exchange's API git.

Iniciar sesión para comentar.

Respuestas (1)

Brendan Hamm
Brendan Hamm el 16 de Abr. de 2018

Hi Fabio,

Without a pair of keys myself I cannot duplicate the auth portion of this. I suspect this woudl be done with the username and password inputs of weboption For the remainder, all of the API is just using GET and POST methods. These can be accomplished with the webread function. As an example consider the API interface for returning the candles info (GET method):

r = webread('https://api.hitbtc.com/api/2/public/orderbook/ETHBTC','limit',200,'period','M1')

The above returns a structure with the 1 minute interval high, low, open, close, etc. for the ETHBTC pair. As you can see each of the fields is a different input to the webread command. The webread command defaults to GET method, whereas the webwrite function uses POST method, although there are option sin the weboptions as well. Again, without the keys I cannot exactly produce the desired resutls, but you should have something similar to:

r = webwrite('https://api.hitbtc.com/api/2/order',...
     'symbol','ethbtc',...
     'side','sell',...
     'quantity', 0.063,...
     'type','market',...
     'timeInForce','GTC')

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by