Closed Workingsolutions1 closed 2 years ago
Same things like for c#, for python it doesn't work as well, next code:
`# !/usr/bin/env python
import logging import random from decimal import Decimal as D, ROUND_UP, getcontext
from gate_api import ApiClient, Configuration, Loan, MarginApi, Order, RepayRequest, SpotApi, Transfer, WalletApi from gate_api.exceptions import GateApiException
from config import RunConfig
logger = logging.getLogger(name)
def margin_demo():
currency_pair = "AGLD_USDT" currency = "USDT" host_used = "https://api.gateio.ws/api/v4" api_key = "key1" api_secret = "key2" # Initialize API client # Setting host is optional. It defaults to https://api.gateio.ws/api/v4 config = Configuration(key=api_key, secret=api_secret, host=host_used) spot_api = SpotApi(ApiClient(config)) margin_api = MarginApi(ApiClient(config)) wallet_api = WalletApi(ApiClient(config)) # retrieve currency pair last price tickers = spot_api.list_tickers(currency_pair=currency_pair) assert len(tickers) == 1 last_price = tickers[0].last print("currency pair %s last price %s", currency_pair, last_price) # Print margin_acc value margin_acc = margin_api.list_margin_accounts() print(margin_acc) # create margin order order = Order(account='margin', currency_pair=currency_pair, price=last_price, amount="65", side='buy', auto_borrow=True) try: created_order = spot_api.create_order(order) logger.info("margin order created with id %s, status %s", created_order.id, created_order.status) except GateApiException as ex: logger.error("failed to create margin order: %s", ex)
margin_demo()`
That's result:
currency pair %s last price %s AGLD_USDT 3.6506 [{'base': {'available': '0.014110300371', 'borrowed': '0', 'currency': 'AGLD', 'interest': '0', 'locked': '0'}, 'currency_pair': 'AGLD_USDT', 'locked': False, 'quote': {'available': '158.677108476601', 'borrowed': '0', 'currency': 'USDT', 'interest': '0', 'locked': '0'}, 'risk': '9999.99'}, {'base': {'available': '0.000099', 'borrowed': '0', 'currency': 'BTC', 'interest': '0', 'locked': '0'}, 'currency_pair': 'BTC_USDT', 'locked': False, 'quote': {'available': '5', 'borrowed': '0', 'currency': 'USDT', 'interest': '0', 'locked': '0'}, 'risk': '9999.99'}] failed to create margin order: (400) Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Date': 'Sun, 10 Oct 2021 14:25:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '86', 'Connection': 'keep-alive', 'Server': 'openresty', 'X-Request-Id': '[532fecb0-2374045718]'}) HTTP response body: {"label":"AUTO_BORROW_TOO_MUCH","message":"auto borrow amount exceeds max borrowable"}
What to do with it ? Looks like there is no normal option to set leveraged order on isolated margin for some reason
The answer has been replied in the corresponding csharp issue gateio/gateapi-csharp#12 . This one will be closed
Same things like for c#, for python it doesn't work as well, next code:
`# !/usr/bin/env python
coding: utf-8
import logging import random from decimal import Decimal as D, ROUND_UP, getcontext
from gate_api import ApiClient, Configuration, Loan, MarginApi, Order, RepayRequest, SpotApi, Transfer, WalletApi from gate_api.exceptions import GateApiException
from config import RunConfig
logger = logging.getLogger(name)
def margin_demo():
margin_demo()`
That's result:
currency pair %s last price %s AGLD_USDT 3.6506 [{'base': {'available': '0.014110300371', 'borrowed': '0', 'currency': 'AGLD', 'interest': '0', 'locked': '0'}, 'currency_pair': 'AGLD_USDT', 'locked': False, 'quote': {'available': '158.677108476601', 'borrowed': '0', 'currency': 'USDT', 'interest': '0', 'locked': '0'}, 'risk': '9999.99'}, {'base': {'available': '0.000099', 'borrowed': '0', 'currency': 'BTC', 'interest': '0', 'locked': '0'}, 'currency_pair': 'BTC_USDT', 'locked': False, 'quote': {'available': '5', 'borrowed': '0', 'currency': 'USDT', 'interest': '0', 'locked': '0'}, 'risk': '9999.99'}] failed to create margin order: (400) Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Date': 'Sun, 10 Oct 2021 14:25:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '86', 'Connection': 'keep-alive', 'Server': 'openresty', 'X-Request-Id': '[532fecb0-2374045718]'}) HTTP response body: {"label":"AUTO_BORROW_TOO_MUCH","message":"auto borrow amount exceeds max borrowable"}
What to do with it ? Looks like there is no normal option to set leveraged order on isolated margin for some reason