Skip to content

Commit a441ab1

Browse files
authored
Release v1.16.0 (#164)
1 parent 5c2afe3 commit a441ab1

16 files changed

+305
-22
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## 1.16.0 - 2022-08-11
4+
5+
### Added
6+
- New endpoint for Portfolio Margin:
7+
- `GET /sapi/v1/portfolio/pmLoan` to query Portfolio Margin Bankruptcy Loan Record.
8+
- `POST /sapi/v1/portfolio/repay` to repay Portfolio Margin Bankruptcy Loan.
9+
- `GET /sapi/v1/portfolio/collateralRate` to get Portfolio Margin Collateral Rate.
10+
11+
### Update
12+
- Changes to `POST /api/v3/order` and `POST /api/v3/order/cancelReplace`
13+
- New optional field `strategyId` is a parameter used to identify an order as part of a strategy.
14+
- New optional field `strategyType` is a parameter used to identify what strategy was running. (E.g. If all the orders are part of spot grid strategy, it can be set to strategyType=1000000)
15+
- Note: `strategyType` cannot be less than 1000000.
16+
- Changes to `POST /api/v3/order/oco`
17+
- New optional fields `limitStrategyId`, `limitStrategyType`, `stopStrategyId`, `stopStrategyType`
18+
- These are the strategy metadata parameters for both legs of the OCO orders.
19+
- `limitStrategyType` and `stopStrategyType` both cannot be less than 1000000.
20+
- `asset` is no longer mandatory in `GET /sapi/v1/lending/project/position/list`
21+
322
## 1.15.0 - 2022-07-19
423

524
### Added

binance/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.15.0"
1+
__version__ = "1.16.0"

binance/spot/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,6 @@ def __init__(self, key=None, secret=None, **kwargs):
273273

274274
# Portfolio Margin
275275
from binance.spot.portfolio_margin import portfolio_margin_account
276+
from binance.spot.portfolio_margin import portfolio_margin_collateral_rate
277+
from binance.spot.portfolio_margin import portfolio_margin_bankruptcy_loan_amount
278+
from binance.spot.portfolio_margin import portfolio_margin_bankruptcy_loan_repay

binance/spot/portfolio_margin.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,58 @@ def portfolio_margin_account(self, **kwargs):
1010
"""
1111

1212
return self.sign_request("GET", "/sapi/v1/portfolio/account", {**kwargs})
13+
14+
15+
def portfolio_margin_collateral_rate(self):
16+
"""Portfolio Margin Collateral Rate (MARKET_DATA)
17+
18+
Portfolio Margin Collateral Rate.
19+
20+
Weight(IP): 50
21+
22+
GET /sapi/v1/portfolio/collateralRate
23+
24+
https://binance-docs.github.io/apidocs/spot/en/#portfolio-margin-collateral-rate-market_data
25+
26+
"""
27+
28+
url_path = "/sapi/v1/portfolio/collateralRate"
29+
return self.sign_request("GET", url_path)
30+
31+
32+
def portfolio_margin_bankruptcy_loan_amount(self, **kwargs):
33+
"""Query Portfolio Margin Bankruptcy Loan Amount (USER_DATA)
34+
35+
Query Portfolio Margin Bankruptcy Loan Amount.
36+
37+
Weight(UID): 500
38+
39+
GET /sapi/v1/portfolio/pmLoan
40+
41+
https://binance-docs.github.io/apidocs/spot/en/#query-portfolio-margin-bankruptcy-loan-amount-user_data
42+
43+
Keyword Args:
44+
recvWindow (int, optional): The value cannot be greater than 60000
45+
"""
46+
47+
url_path = "/sapi/v1/portfolio/pmLoan"
48+
return self.sign_request("GET", url_path, {**kwargs})
49+
50+
51+
def portfolio_margin_bankruptcy_loan_repay(self, **kwargs):
52+
"""Portfolio Margin Bankruptcy Loan Repay (USER_DATA)
53+
54+
Repay Portfolio Margin Bankruptcy Loan.
55+
56+
Weight(UID): 3000
57+
58+
POST /sapi/v1/portfolio/repay
59+
60+
https://binance-docs.github.io/apidocs/spot/en/#portfolio-margin-bankruptcy-loan-repay-user_data
61+
62+
Keyword Args:
63+
recvWindow (int, optional): The value cannot be greater than 60000
64+
"""
65+
66+
url_path = "/sapi/v1/portfolio/repay"
67+
return self.sign_request("POST", url_path, {**kwargs})

binance/spot/savings.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,21 @@ def savings_purchase_project(self, projectId: str, lot: int, **kwargs):
163163
)
164164

165165

166-
def savings_project_position(self, asset: str, **kwargs):
166+
def savings_project_position(self, **kwargs):
167167
"""Get Fixed/Activity Project Position (USER_DATA)
168168
169169
GET /sapi/v1/lending/project/position/list
170170
171171
https://binance-docs.github.io/apidocs/spot/en/#get-fixed-activity-project-position-user_data
172172
173-
Args:
174-
asset (str)
175173
Keyword Args:
174+
asset (str, optional)
176175
projectId (str, optional)
177176
status (str, optional): "HOLDING", "REDEEMED"
178177
recvWindow (int, optional): The value cannot be greater than 60000
179178
"""
180179

181-
check_required_parameter(asset, "asset")
182-
payload = {"asset": asset, **kwargs}
183-
return self.sign_request("GET", "/sapi/v1/lending/project/position/list", payload)
180+
return self.sign_request("GET", "/sapi/v1/lending/project/position/list", kwargs)
184181

185182

186183
def savings_account(self, **kwargs):

binance/spot/trade.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def new_order(self, symbol: str, side: str, type: str, **kwargs):
5353
quoteOrderQty (float, optional)
5454
price (float, optional)
5555
newClientOrderId (str, optional): A unique id among open orders. Automatically generated if not sent.
56+
strategyId (int, optional)
57+
strategyType (int, optional): The value cannot be less than 1000000.
5658
stopPrice (float, optional): Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
5759
icebergQty (float, optional): Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
5860
newOrderRespType (str, optional): Set the response JSON. ACK, RESULT, or FULL;
@@ -166,6 +168,8 @@ def cancel_and_replace(
166168
cancelOrigClientOrderId (str, optional): Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
167169
cancelOrderId (int, optional): Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
168170
newClientOrderId (str, optional): Used to identify the new order. Automatically generated by default
171+
strategyId (int, optional)
172+
strategyType (int, optional): The value cannot be less than 1000000.
169173
stopPrice (float, optional): Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
170174
trailingDelta (float, optional): Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
171175
icebergQty (float, optional): Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
@@ -263,8 +267,12 @@ def new_oco_order(
263267
Keyword Args:
264268
listClientOrderId (str, optional): A unique Id for the entire orderList
265269
limitClientOrderId (str, optional)
270+
limitStrategyId (int, optional)
271+
limitStrategyType (int, optional): The value cannot be less than 1000000.
266272
limitIcebergQty (float, optional)
267273
stopClientOrderId (str, optional)
274+
stopStrategyId (int, optional)
275+
stopStrategyType (int, optional): The value cannot be less than 1000000.
268276
stopLimitPrice (float, optional)
269277
stopIcebergQty (float, optional)
270278
stopLimitTimeInForce (str, optional)

docs/source/CHANGELOG.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,60 @@
22
Changelog
33
=========
44

5+
1.16.0 - 2022-08-11
6+
-------------------
7+
8+
Added
9+
^^^^^
10+
11+
* New endpoint for Portfolio Margin:
12+
* `GET /sapi/v1/portfolio/pmLoan` to query Portfolio Margin Bankruptcy Loan Record.
13+
* `POST /sapi/v1/portfolio/repay` to repay Portfolio Margin Bankruptcy Loan.
14+
* `GET /sapi/v1/portfolio/collateralRate` to get Portfolio Margin Collateral Rate.
15+
16+
Update
17+
^^^^^^
18+
19+
* Changes to `POST /api/v3/order` and `POST /api/v3/order/cancelReplace`
20+
* New optional field `strategyId` is a parameter used to identify an order as part of a strategy.
21+
* New optional field `strategyType` is a parameter used to identify what strategy was running. (E.g. If all the orders are part of spot grid strategy, it can be set to strategyType=1000000)
22+
* Note: `strategyType` cannot be less than 1000000.
23+
* Changes to `POST /api/v3/order/oco`
24+
* New optional fields `limitStrategyId`, `limitStrategyType`, `stopStrategyId`, `stopStrategyType`
25+
* These are the strategy metadata parameters for both legs of the OCO orders.
26+
* `limitStrategyType` and `stopStrategyType` both cannot be less than 1000000.
27+
* `asset` is no longer mandatory in `GET /sapi/v1/lending/project/position/list`
28+
29+
1.15.0 - 2022-07-19
30+
-------------------
31+
32+
Added
33+
^^^^^
34+
35+
* New endpoint for Margin:
36+
37+
* `POST /sapi/v3/asset/getUserAsset` to get user assets.
38+
39+
* New endpoint for Wallet:
40+
41+
* `GET /sapi/v1/margin/dribblet` to query the historical information of user's margin account small-value asset conversion BNB.
42+
43+
1.14.0 - 2022-07-04
44+
-------------------
45+
46+
Added
47+
^^^^^
48+
49+
* New endpoint `GET /api/v3/ticker`
50+
* New endpoint `POST /api/v3/order/cancelReplace`
51+
* New websocket stream `<symbol>@ticker_<window_size>`
52+
* New websocket stream `!ticker_<window-size>@arr`
53+
54+
Update
55+
^^^^^^
56+
57+
* #146 `savings_flexible_product_position` `asset` parameter should be optional
58+
559

660
1.13.0 - 2022-05-23
761
-------------------

docs/source/binance.spot.portfolio_margin.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ Portfolio Margin Endpoints
55
Get Portfolio Margin Account Info (USER_DATA)
66
---------------------------------------------
77
.. autofunction:: binance.spot.portfolio_margin.portfolio_margin_account
8+
9+
Query Portfolio Margin Bankruptcy Loan Amount (USER_DATA)
10+
---------------------------------------------------------
11+
.. autofunction:: binance.spot.portfolio_margin.portfolio_margin_bankruptcy_loan_amount
12+
13+
Portfolio Margin Bankruptcy Loan Repay (USER_DATA)
14+
--------------------------------------------------
15+
.. autofunction:: binance.spot.portfolio_margin.portfolio_margin_bankruptcy_loan_repay
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
from binance.error import ClientError
7+
8+
config_logging(logging, logging.DEBUG)
9+
10+
key = ""
11+
secret = ""
12+
13+
client = Client(key, secret)
14+
15+
try:
16+
response = client.portfolio_margin_bankruptcy_loan_amount(recvWindow=5000)
17+
logging.info(response)
18+
except ClientError as error:
19+
logging.error(
20+
"Found error. status: {}, error code: {}, error message: {}".format(
21+
error.status_code, error.error_code, error.error_message
22+
)
23+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
from binance.error import ClientError
7+
8+
config_logging(logging, logging.DEBUG)
9+
10+
key = ""
11+
secret = ""
12+
13+
client = Client(key, secret)
14+
15+
try:
16+
response = client.portfolio_margin_bankruptcy_loan_repay(recvWindow=5000)
17+
logging.info(response)
18+
except ClientError as error:
19+
logging.error(
20+
"Found error. status: {}, error code: {}, error message: {}".format(
21+
error.status_code, error.error_code, error.error_message
22+
)
23+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
from binance.error import ClientError
7+
8+
config_logging(logging, logging.DEBUG)
9+
10+
key = ""
11+
12+
client = Client(key)
13+
14+
try:
15+
response = client.portfolio_margin_collateral_rate()
16+
logging.info(response)
17+
except ClientError as error:
18+
logging.error(
19+
"Found error. status: {}, error code: {}, error message: {}".format(
20+
error.status_code, error.error_code, error.error_message
21+
)
22+
)

examples/spot/savings/savings_project_position.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
secret = ""
1111

1212
client = Client(key, secret)
13-
logging.info(client.savings_project_position(asset="BTC"))
13+
logging.info(client.savings_project_position())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import responses
2+
3+
from binance.spot import Spot as Client
4+
from tests.util import random_str
5+
from urllib.parse import urlencode
6+
from tests.util import mock_http_response
7+
8+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
9+
mock_exception = {"code": -1, "msg": "error message"}
10+
11+
key = random_str()
12+
secret = random_str()
13+
14+
params = {"recvWindow": 5000}
15+
16+
17+
@mock_http_response(
18+
responses.GET,
19+
"/sapi/v1/portfolio/pmLoan\\?" + urlencode(params),
20+
mock_item,
21+
200,
22+
)
23+
def test_portfolio_margin_bankruptcy_loan_amount():
24+
"""Tests the API endpoint to portfolio margin bankruptcy loan amount"""
25+
26+
client = Client(key, secret)
27+
response = client.portfolio_margin_bankruptcy_loan_amount(**params)
28+
response.should.equal(mock_item)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import responses
2+
3+
from binance.spot import Spot as Client
4+
from tests.util import random_str
5+
from urllib.parse import urlencode
6+
from tests.util import mock_http_response
7+
8+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
9+
mock_exception = {"code": -1, "msg": "error message"}
10+
11+
key = random_str()
12+
secret = random_str()
13+
14+
params = {"recvWindow": 5000}
15+
16+
17+
@mock_http_response(
18+
responses.POST,
19+
"/sapi/v1/portfolio/repay\\?" + urlencode(params),
20+
mock_item,
21+
200,
22+
)
23+
def test_portfolio_margin_bankruptcy_loan_repay():
24+
"""Tests the API endpoint to portfolio margin bankruptcy loan repay"""
25+
26+
client = Client(key, secret)
27+
response = client.portfolio_margin_bankruptcy_loan_repay(**params)
28+
response.should.equal(mock_item)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import responses
2+
3+
from binance.spot import Spot as Client
4+
from tests.util import random_str
5+
from tests.util import mock_http_response
6+
7+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
8+
mock_exception = {"code": -1, "msg": "error message"}
9+
10+
key = random_str()
11+
secret = random_str()
12+
13+
14+
@mock_http_response(
15+
responses.GET,
16+
"/sapi/v1/portfolio/collateralRate",
17+
mock_item,
18+
200,
19+
)
20+
def test_portfolio_margin_collateral_rate():
21+
"""Tests the API endpoint to portfolio margin collateral rate"""
22+
23+
client = Client(key, secret)
24+
response = client.portfolio_margin_collateral_rate()
25+
response.should.equal(mock_item)

0 commit comments

Comments
 (0)