Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<div align="center">

# BingX API Connector Python
# BingX API Connector Python2
[![PYPI version][pypi-shield]][pypi-url]
[![Python version][python-shield]][python-url]
[![License: GPLv3][license-shield]][license-url]

</div>

## 📌 Please note:

This package is a minor update to [bingX-connector](https://pypi.org/project/bingX-connector/).
I have opened a pull request as [Ming119](https://github.com/Ming119) instructed in their repoistory. After opening the pull request and mailing them directly and asking them to merge, I got no answer. Therefore, I am publishing this new update with the similar name. This package may be deprecated after they merge.

Keep in mind that for Perpetual v1, no changes were made, so you cannot work demo with that.

Link to [My Pull Request](https://github.com/Ming119/bingX-connector-python/pull/21)
Link to [Git Repository](https://github.com/demonarch/bingX-connector-python)
Link to my [GitHub](https://github.com/demonarch)


The rest of README.md file provided by Ming119:



## 📌 About The Project

This is a Python package for bingX API, aims to provide a simple and easy-to-use interface for developers to access bingX API.
Expand All @@ -22,43 +38,54 @@ pip install -U bingX-connector # upgrade the package to the latest version

## 📌 Features

- [x] Standard Contract
- [x] Standard Contract (Demo)
- [x] Standard Contract (Real)
- [ ] Standard Contract Web Socket
- [x] Spot
- [x] Spot (Demo)
- [x] Spot (Real)
- [ ] Spot Web Socket
- [x] Perpetual v1
- [ ] Perpetual v1 Web Socket
- [x] Perpetual v2
- [x] Perpetual v2 (Demo)
- [x] Perpetual v2 (Real)
- [ ] Perpetual v2 Web Socket

## 📌 Usage

### Standard Contract
```python
from bingX.standard import Standard

# by defaul, you're using demo
client = Standard(api_key, api_secret)
# or
client = Standard(api_key, api_secret, mode='demo')
```

### Spot
```python
from bingX.spot import Spot

# by defaul, you're using demo
client = Spot(api_key, api_secret)
# or
client = Spot(api_key, api_secret, mode='demo')
# use mode='real' to interact with your real account
```

### Perpetual v1
```python
from bingX.perpetual.v1 import Perpetual

client = Perpetual(api_key, api_secret)
```

### Perpetual v2
```python
from bingX.perpetual.v2 import Perpetual

# by defaul, you're using demo
client = Perpetual(api_key, api_secret)
#or
client = Perpetual(api_key, api_secret, mode='demo')
# use mode='real' to interact with your real account
```
> Note that you can not import `Perpetual v1` and `Perpetual v2` at the same time

Expand Down Expand Up @@ -134,9 +161,12 @@ client = Perpetual(api_key, api_secret)

> **IMPORTANT**: By submitting a patch, you agree to allow us to license your work under the same license as that used by `bingX-connector-python`

[pypi-shield]: https://img.shields.io/pypi/v/bingX-connector
[pypi-url]: https://pypi.org/project/bingX-connector/
[python-shield]: https://img.shields.io/pypi/pyversions/bingX-connector
[original-github-repo]: https://github.com/Ming119/bingX-connector-python/
[original-pypi-package]: https://pypi.org/project/bingX-connector/
[pull-request-url]: https://github.com/Ming119/bingX-connector-python/pull/21
[pypi-shield]: https://img.shields.io/pypi/v/bingX-connector2
[pypi-url]: https://pypi.org/project/bingX-connector2/
[python-shield]: https://img.shields.io/pypi/pyversions/bingX-connector2
[python-url]: https://www.python.org/downloads/
[license-shield]: https://img.shields.io/github/license/Ming119/bingX-connector-python
[license-shield]: https://img.shields.io/github/license/demonarch/bingX-connector-python
[license-url]: https://www.gnu.org/licenses/gpl-3.0.en.html
11 changes: 10 additions & 1 deletion bingX/perpetual/v2/Perpetual.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ class Perpetual(API):
def __init__(self,
api_key: str,
api_secret: str,
mode: str = 'demo' # Default mode is 'demo'
) -> object:
if mode == "real":
url = "https://open-api.bingx.com"
elif mode == "demo":
url = "https://open-api-vst.bingx.com"
else:
raise ValueError("Invalid mode. Mode must be 'real' or 'demo'.")

super().__init__(
api_key = api_key,
api_secret = api_secret,
base_url = "https://open-api.bingx.com",
base_url = url,
)


def server_time(self) -> dict:
''' Get Server Time
https://bingx-api.github.io/docs/swapV2/base-info.html#get-server-time
Expand Down
6 changes: 6 additions & 0 deletions bingX/perpetual/v2/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def trade_order(self,
quantity: float = None,
stopPrice: float = None,
recvWindow: int = None,

takeProfit: float = None,
stopLoss: float = None,
) -> dict:
''' Place a New Order
POST /openApi/swap/v2/trade/order
Expand All @@ -29,6 +32,9 @@ def trade_order(self,
"quantity": quantity,
"stopPrice": stopPrice,
"recvWindow": recvWindow,

"takeProfit": "{\"type\": \"TAKE_PROFIT_MARKET\", \"stopPrice\": %TAKE_PROFIT%,\"price\": %TAKE_PROFIT%,\"workingType\":\"MARK_PRICE\", \"stopGuaranteed\": \"true\"}".replace("%TAKE_PROFIT%", str(takeProfit)) if takeProfit else None,
"stopLoss": "{\"type\": \"STOP_MARKET\", \"stopPrice\": %STOP_LOSS%,\"price\": %STOP_LOSS%,\"workingType\":\"MARK_PRICE\", \"stopGuaranteed\": \"true\"}".replace("%STOP_LOSS%", str(stopLoss)) if stopLoss else None,
})

if 'code' in res and res['code']:
Expand Down
10 changes: 9 additions & 1 deletion bingX/spot/Spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ class Spot(API):
def __init__(self,
api_key: str,
api_secret: str,
mode: str = 'demo' # Default mode is 'demo'
) -> object:
if mode == "real":
url = "https://open-api.bingx.com"
elif mode == "demo":
url = "https://open-api-vst.bingx.com"
else:
raise ValueError("Invalid mode. Mode must be 'real' or 'demo'.")

super().__init__(
api_key = api_key,
api_secret = api_secret,
base_url = 'https://open-api.bingx.com',
base_url = url,
)

# ========== TRADE INTERFACE ==========
Expand Down
11 changes: 10 additions & 1 deletion bingX/standard/Standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ class Standard(API):
def __init__(self,
api_key: str,
api_secret: str,
mode: str = 'demo' # Default mode is 'demo'
) -> object:
if mode == "real":
url = "https://open-api.bingx.com"
elif mode == "demo":
url = "https://open-api-vst.bingx.com"
else:
raise ValueError("Invalid mode. Mode must be 'real' or 'demo'.")

super().__init__(
api_key = api_key,
api_secret = api_secret,
base_url = "https://open-api.bingx.com",
base_url = url,
)


# ========== STANDARD CONTRACT INTERFACE ==========
from bingX.standard.trade import (
position,
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
with open("README.md", "r") as fh:
long_description = fh.read()

NAME = "bingX-connector"
VERSION = "0.0.5"
NAME = "bingX-connector2"
VERSION = "0.0.8"
AUTHOR = "Ming119"
URL = "https://github.com/Ming119/bingX-connector-python"
URL = "https://github.com/demonarch/bingX-connector-python"

setuptools.setup(
name=NAME,
Expand Down