-
|
Hi all, I wanted to share what I found out about the error in the selling code in the last class. I change the code in amount, now it works for me always : params = {
"amount": int(round(market_price/10,0)*10),
"instrument_name": "BTC-PERPETUAL",
"type": "market"
} |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 9 replies
-
|
The solution works for me in the first task but as the the second task asks for only 60%/50% of the price I seem to run into the same issue as before. |
Beta Was this translation helpful? Give feedback.
-
|
I have the same issue: here is my version: response_json = response.json() #Send the GET request #Check if the request was successful |
Beta Was this translation helpful? Give feedback.
-
|
I can share with you what I did: Function Stop_limit_order () inside a class MarketHandler: def Stop_limit_order(self,amount,instrument_name, time_in_force,price, trigger_price):
url = "https://test.deribit.com/api/v2/private/sell"
params = {
"amount": amount,
"instrument_name": instrument_name,
"type": "stop_limit",
"trigger_price": trigger_price,
"price": price,
"time_in_force": time_in_force,
"trigger":"mark_price"
}
response = requests.get(url, params=params, auth=(self.ClientID, self.ClientSecret))
if response.status_code == 200:
response = response.json()
order_id=response["result"]["order"]["order_id"]
print(f"The order was carried out satisfactorily. Order ID: {order_id}")
else:
print(f"Failed to retrieve data: {response.status_code}")For use the function I have: instrument_name="BTC-PERPETUAL"
price=int(round(Seller.GetMarketPrice(instrument_name=instrument_name)*0.6/10)*10)
trigger_price=int(round(Seller.GetMarketPrice(instrument_name=instrument_name)*0.5/10)*10)
amount=int(price/10)*10
time_in_force="good_til_day"
instrument_name="BTC-PERPETUAL"
Seller.Stop_limit_order(amount=amount,instrument_name=instrument_name,price=price,trigger_price=trigger_price,time_in_force=time_in_force) |
Beta Was this translation helpful? Give feedback.
-
|
Adding to @Di3goCH suggestion, one can also use Of cause, if you then calculate some percentage of the price, first calculate the percentage and then round to the closest ten (as otherwise the stop_price would be for example 26530*0.5=13265, which is not a multiple of ten). Instead use: |
Beta Was this translation helpful? Give feedback.
Adding to @Di3goCH suggestion, one can also use
int(market_price.round(-1))to round the current market price to the neares ten.Of cause, if you then calculate some percentage of the price, first calculate the percentage and then round to the closest ten (as otherwise the stop_price would be for example 26530*0.5=13265, which is not a multiple of ten). Instead use:
int((market_price*0.5).round(-1))