Skip to content

Commit

Permalink
Merge pull request #166 from bybit-exchange/update_api
Browse files Browse the repository at this point in the history
Update HTTP API
  • Loading branch information
dextertd authored Sep 28, 2023
2 parents 0253d22 + 9409ae1 commit 852a3f5
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 10 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Improve `close_position` logic

## [5.6.0] - 2023-09-28
### Added
- Add RSA authentication for HTTP and WebSocket (choose "Self-generated API Keys" when [creating](https://testnet.bybit.com/app/user/api-management) an API key)
- To use it, pass `rsa_authentication=True` along with your `api_key` and `api_secret`
- Your `api_key` is given to you after inputting your public key (RSA) into Bybit's API management system
- Your `api_secret` is the private key (RSA) you generate
- Learn more [here](https://www.bybit.com/en-US/help-center/bybitHC_Article?id=000001923&language=en_US)
- See examples files: [HTTP](https://github.com/bybit-exchange/pybit/blob/master/examples/http_example_rsa_authentication.py) and [WebSocket](https://github.com/bybit-exchange/pybit/blob/master/examples/websocket_example_rsa_authentication.py)
- Add the `HTTP` method `get_server_time()`
- Add `HTTP` methods for spot margin trading
- Add `HTTP` method `get_long_short_ratio()`
- Add optional `private_auth_expire` arg for WebSocket (https://github.com/bybit-exchange/pybit/pull/154)

### Deprecated
- The `HTTP` method `enable_universal_transfer_for_sub_uid()`

### Fixed
- Improve `close_position` logic

## [5.5.0] - 2023-07-17
### Added
- `helpers.py` which includes the `Helpers` class and the `close_position` method, which can be imported and employed like so:
Expand All @@ -38,6 +48,7 @@ print(my_helper.close_position(category="linear", symbol="BTCUSDT"))
- `get_affiliate_user_info`
- `get_uid_wallet_type`


## [5.3.0] - 2023-05-19
### Added
- Multiple symbol support for WebSocket topics (pass `symbol` as a list)
Expand Down
2 changes: 1 addition & 1 deletion pybit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "5.5.0"
VERSION = "5.6.0"
1 change: 1 addition & 0 deletions pybit/_v5_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def enable_universal_transfer_for_sub_uid(self, **kwargs):
Additional information:
https://bybit-exchange.github.io/docs/v5/asset/enable-unitransfer-subuid
"""
self.logger.warning("enable_universal_transfer_for_sub_uid() is depreciated. You no longer need to configure transferable sub UIDs. Now, all sub UIDs are automatically enabled for universal transfer.")
return self._submit_request(
method="POST",
path=f"{self.endpoint}{Asset.ENABLE_UT_FOR_SUB_UID}",
Expand Down
31 changes: 31 additions & 0 deletions pybit/_v5_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@


class MarketHTTP(_V5HTTPManager):
def get_server_time(self) -> dict:
"""
Returns:
Request results as dictionary.
Additional information:
https://bybit-exchange.github.io/docs/v5/market/time
"""
return self._submit_request(
method="GET",
path=f"{self.endpoint}{Market.GET_SERVER_TIME}",
)

def get_kline(self, **kwargs) -> dict:
"""Query the kline data. Charts are returned in groups based on the requested interval.
Expand Down Expand Up @@ -266,3 +279,21 @@ def get_option_delivery_price(self, **kwargs):
path=f"{self.endpoint}{Market.GET_OPTION_DELIVERY_PRICE}",
query=kwargs,
)

def get_long_short_ratio(self, **kwargs):
"""
Required args:
category (string): Product type. linear (USDT Perpetual only), inverse
symbol (string): Symbol name
Returns:
Request results as dictionary.
Additional information:
https://bybit-exchange.github.io/docs/v5/market/long-short-ratio
"""
return self._submit_request(
method="GET",
path=f"{self.endpoint}{Market.GET_LONG_SHORT_RATIO}",
query=kwargs,
)
42 changes: 42 additions & 0 deletions pybit/_v5_spot_margin_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@


class SpotMarginTradeHTTP(_V5HTTPManager):
def spot_margin_trade_get_vip_margin_data(self, **kwargs):
"""
Returns:
Request results as dictionary.
Additional information:
https://bybit-exchange.github.io/docs/v5/spot-margin-uta/vip-margin
"""
return self._submit_request(
method="GET",
path=f"{self.endpoint}{SpotMarginTrade.VIP_MARGIN_DATA}",
query=kwargs,
)

def spot_margin_trade_toggle_margin_trade(self, **kwargs):
"""UTA only. Turn spot margin trade on / off.
Expand Down Expand Up @@ -41,6 +55,34 @@ def spot_margin_trade_set_leverage(self, **kwargs):
auth=True,
)

def spot_margin_trade_get_status_and_leverage(self):
"""
Returns:
Request results as dictionary.
Additional information:
https://bybit-exchange.github.io/docs/v5/spot-margin-uta/status
"""
return self._submit_request(
method="GET",
path=f"{self.endpoint}{SpotMarginTrade.STATUS_AND_LEVERAGE}",
auth=True,
)

def spot_margin_trade_normal_get_vip_margin_data(self, **kwargs):
"""
Returns:
Request results as dictionary.
Additional information:
https://bybit-exchange.github.io/docs/v5/spot-margin-normal/vip-margin
"""
return self._submit_request(
method="GET",
path=f"{self.endpoint}{SpotMarginTrade.NORMAL_GET_MARGIN_COIN_INFO}",
query=kwargs,
)

def spot_margin_trade_normal_get_margin_coin_info(self, **kwargs):
"""Normal (non-UTA) account only. Turn on / off spot margin trade
Expand Down
6 changes: 0 additions & 6 deletions pybit/_v5_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def get_api_key_information(self, **kwargs):
def modify_master_api_key(self, **kwargs):
"""Modify the settings of master api key. Use the api key pending to be modified to call the endpoint. Use master user's api key only.
Required args:
permissions (Object): Tick the types of permission. one of below types must be passed, otherwise the error is thrown
Returns:
Request results as dictionary.
Expand All @@ -118,9 +115,6 @@ def modify_master_api_key(self, **kwargs):
def modify_sub_api_key(self, **kwargs):
"""Modify the settings of sub api key. Use the api key pending to be modified to call the endpoint. Use sub user's api key only.
Required args:
permissions (Object): Tick the types of permission. one of below types must be passed, otherwise the error is thrown
Returns:
Request results as dictionary.
Expand Down
2 changes: 2 additions & 0 deletions pybit/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class Market(str, Enum):
GET_SERVER_TIME = "/v5/market/time"
GET_KLINE = "/v5/market/kline"
GET_MARK_PRICE_KLINE = "/v5/market/mark-price-kline"
GET_INDEX_PRICE_KLINE = "/v5/market/index-price-kline"
Expand All @@ -16,6 +17,7 @@ class Market(str, Enum):
GET_INSURANCE = "/v5/market/insurance"
GET_RISK_LIMIT = "/v5/market/risk-limit"
GET_OPTION_DELIVERY_PRICE = "/v5/market/delivery-price"
GET_LONG_SHORT_RATIO = "/v5/market/account-ratio"

def __str__(self) -> str:
return self.value
3 changes: 3 additions & 0 deletions pybit/spot_margin_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class SpotMarginTrade(str, Enum):
# UTA endpoints
TOGGLE_MARGIN_TRADE = "/v5/spot-margin-trade/switch-mode"
SET_LEVERAGE = "/v5/spot-margin-trade/set-leverage"
VIP_MARGIN_DATA = "/v5/spot-margin-trade/data"
STATUS_AND_LEVERAGE = "/v5/spot-margin-trade/state"
# normal mode (non-UTA) endpoints
NORMAL_GET_VIP_MARGIN_DATA = "/v5/spot-cross-margin-trade/data"
NORMAL_GET_MARGIN_COIN_INFO = "/v5/spot-cross-margin-trade/pledge-token"
NORMAL_GET_BORROWABLE_COIN_INFO = "/v5/spot-cross-margin-trade/borrow-token"
NORMAL_GET_INTEREST_QUOTA = "/v5/spot-cross-margin-trade/loan-info"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='pybit',
version='5.5.0',
version='5.6.0',
description='Python3 Bybit HTTP/WebSocket API Connector',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 852a3f5

Please sign in to comment.