How can I post an order request via API?

1 回表示 (過去 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 件のコメント
Brendan Hamm
Brendan Hamm 2018 年 4 月 6 日
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 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')

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by