How can I post an order request via API?

조회 수: 12(최근 30일)
Fabio Barbosa
Fabio Barbosa 2018년 4월 6일
답변: Brendan Hamm 2018년 4월 16일
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
Fabio Barbosa
Fabio Barbosa 2018년 4월 6일
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.

댓글을 달려면 로그인하십시오.

답변(1개)

Brendan Hamm
Brendan Hamm 2018년 4월 16일

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')

태그

Community Treasure Hunt

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

Start Hunting!

Translated by