Skip to content

Commit 96ce1d6

Browse files
authored
code factor for v3.0.0 (#31)
* code factor for v3.0.0
1 parent 8117997 commit 96ce1d6

File tree

247 files changed

+1913
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+1913
-1815
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
- rc-**
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v1
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements/requirements-test.txt
30+
- name: Run black to review standard code format
31+
run: |
32+
# Checks if need to reformat files
33+
black --check --diff .
34+
- name: Run flake8 to check specific rules not covered by black
35+
run: |
36+
flake8 . --statistics

.github/workflows/release.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release Distributables
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
build-n-upload:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
with:
15+
python-version: "3.10"
16+
- run: pip install wheel
17+
- name: Build new distributables
18+
run: python setup.py sdist bdist_wheel
19+
- name: Upload distributables to PyPI
20+
uses: pypa/gh-action-pypi-publish@release/v1
21+
with:
22+
user: __token__
23+
password: ${{ secrets.PYPI_API_TOKEN }}
24+
- name: Post release cleaning
25+
run: |
26+
python setup.py clean --all
27+
rm dist/*

CHANGELOG.md

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

3-
## Unreleased
3+
## 3.0.0 - 2022-05-26
44

5-
## Released
5+
- Refactor the connector

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) [2020]
3+
Copyright (c) [2022]
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ This is a lightweight library that works as a connector to [Binance Futures publ
1919
pip install binance-futures-connector
2020
```
2121

22-
## Documentation
23-
- USDT-M Futures: https://github.com/Binance-docs/binance-futures-connector-python/wiki/USDT-M-Futures
24-
- COIN-M Futures: https://github.com/Binance-docs/binance-futures-connector-python/wiki/COIN-M-Futures
2522

2623
## RESTful APIs
2724

2825
Usage examples:
2926
```python
30-
from binance.futures import Futures
3127

32-
client = Futures()
33-
print(client.time())
28+
from binance.cm_futures import CMFutures
29+
30+
cm_futures_client = CMFutures()
31+
32+
# get server time
33+
print(cm_futures_client.time())
3434

35-
client = Futures(key='<api_key>', secret='<api_secret>')
35+
cm_futures_client = CMFutures(key='<api_key>', secret='<api_secret>')
3636

3737
# Get account information
38-
print(client.account())
38+
print(cm_futures_client.account())
3939

4040
# Post a new order
4141
params = {
@@ -47,7 +47,7 @@ params = {
4747
'price': 59808
4848
}
4949

50-
response = client.new_order(**params)
50+
response = cm_futures_client.new_order(**params)
5151
print(response)
5252
```
5353
Please find `examples` folder to check for more endpoints.
@@ -78,10 +78,10 @@ It defaults to `5000` (milliseconds) and can be any value lower than `60000`(mil
7878
Anything beyond the limit will result in an error response from Binance server.
7979

8080
```python
81-
from binance.futures import Futures as Client
81+
from binance.cm_futures import CMFutures
8282

83-
client = Client(key, secret)
84-
response = client.query_order('BTCUSDT', orderId=11, recvWindow=10000)
83+
cm_futures_client = CMFutures(key='<api_key>', secret='<api_secret>')
84+
response = cm_futures_client.query_order('BTCUSDT', orderId=11, recvWindow=10000)
8585
```
8686

8787
### Timeout
@@ -91,20 +91,20 @@ Please remember the value as it won't be shown in error message _no bytes have b
9191
By default, `timeout` is None. Hence, requests do not time out.
9292

9393
```python
94-
from binance.futures import Futures as Client
94+
from binance.cm_futures import CMFutures
9595

96-
client= Client(timeout=1)
96+
client= CMFutures(timeout=1)
9797
```
9898

9999
### Proxy
100100
proxy is supported
101101

102102
```python
103-
from binance.futures import Futures as Client
103+
from binance.cm_futures import CMFutures
104104

105105
proxies = { 'https': 'http://1.2.3.4:8080' }
106106

107-
client= Client(proxies=proxies)
107+
client= CMFutures(proxies=proxies)
108108
```
109109

110110
### Response Metadata
@@ -113,15 +113,15 @@ The Binance API server provides weight usages in the headers of each response.
113113
You can display them by initializing the client with `show_limit_usage=True`:
114114

115115
```python
116-
from binance.futures import Futures as Client
116+
from binance.cm_futures import CMFutures
117117

118-
client = Client(show_limit_usage=True)
118+
client = CMFutures(show_limit_usage=True)
119119
print(client.time())
120120
```
121121
returns:
122122

123123
```python
124-
{'data': {'serverTime': 1587990847650}, 'limit_usage': {'x-mbx-used-weight': '31', 'x-mbx-used-weight-1m': '31'}}
124+
{'limit_usage': {'x-mbx-used-weight-1m': '1'}, 'data': {'serverTime': 1653563092778}}
125125
```
126126
You can also display full response metadata to help in debugging:
127127

@@ -158,12 +158,13 @@ There are 2 types of error returned from the library:
158158
## Websocket
159159

160160
```python
161-
from binance.websocket.futures.websocket_client import FuturesWebsocketClient as WebsocketClient
161+
import time
162+
from binance.websocket.cm_futures.websocket_client import CMFuturesWebsocketClient
162163

163164
def message_handler(message):
164165
print(message)
165166

166-
ws_client = WebsocketClient()
167+
ws_client = CMFuturesWebsocketClient()
167168
ws_client.start()
168169

169170
ws_client.mini_ticker(
@@ -178,7 +179,11 @@ ws_client.instant_subscribe(
178179
callback=message_handler,
179180
)
180181

182+
time.sleep(10)
183+
184+
print("closing ws connection")
181185
ws_client.stop()
186+
182187
```
183188
More websocket examples are available in the `examples` folder
184189

@@ -187,3 +192,5 @@ More websocket examples are available in the `examples` folder
187192
Once connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within
188193
a 10 minutes period. This package handles the pong responses automatically.
189194

195+
## License
196+
MIT

binance/__version__.py

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

binance/api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import hmac
42
import json
53
import logging
@@ -145,7 +143,7 @@ def send_request(self, http_method, url_path, payload=None, special=False):
145143
return data
146144

147145
def _prepare_params(self, params, special=False):
148-
return encoded_string(cleanNoneValue(params),special)
146+
return encoded_string(cleanNoneValue(params), special)
149147

150148
def _get_sign(self, data):
151149
m = hmac.new(self.secret.encode("utf-8"), data.encode("utf-8"), hashlib.sha256)

binance/cm_futures/__init__.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from binance.api import API
2+
3+
4+
class CMFutures(API):
5+
def __init__(self, key=None, secret=None, **kwargs):
6+
if "base_url" not in kwargs:
7+
kwargs["base_url"] = "https://dapi.binance.com"
8+
super().__init__(key, secret, **kwargs)
9+
10+
# MARKETS
11+
from binance.cm_futures.market import ping
12+
from binance.cm_futures.market import time
13+
from binance.cm_futures.market import exchange_info
14+
from binance.cm_futures.market import depth
15+
from binance.cm_futures.market import trades
16+
from binance.cm_futures.market import historical_trades
17+
from binance.cm_futures.market import agg_trades
18+
from binance.cm_futures.market import klines
19+
from binance.cm_futures.market import continuous_klines
20+
from binance.cm_futures.market import index_price_klines
21+
from binance.cm_futures.market import mark_price_klines
22+
from binance.cm_futures.market import mark_price
23+
from binance.cm_futures.market import funding_rate
24+
from binance.cm_futures.market import ticker_24hr_price_change
25+
from binance.cm_futures.market import ticker_price
26+
from binance.cm_futures.market import book_ticker
27+
from binance.cm_futures.market import open_interest
28+
from binance.cm_futures.market import open_interest_hist
29+
from binance.cm_futures.market import top_long_short_account_ratio
30+
from binance.cm_futures.market import top_long_short_position_ratio
31+
from binance.cm_futures.market import long_short_account_ratio
32+
from binance.cm_futures.market import taker_long_short_ratio
33+
from binance.cm_futures.market import basis
34+
35+
# ACCOUNT(including orders and trades)
36+
from binance.cm_futures.account import change_position_mode
37+
from binance.cm_futures.account import get_position_mode
38+
from binance.cm_futures.account import new_order
39+
from binance.cm_futures.account import modify_order
40+
from binance.cm_futures.account import new_batch_order
41+
from binance.cm_futures.account import modify_batch_order
42+
from binance.cm_futures.account import order_modify_history
43+
from binance.cm_futures.account import query_order
44+
from binance.cm_futures.account import cancel_order
45+
from binance.cm_futures.account import cancel_open_orders
46+
from binance.cm_futures.account import cancel_batch_order
47+
from binance.cm_futures.account import countdown_cancel_order
48+
from binance.cm_futures.account import get_open_orders
49+
from binance.cm_futures.account import get_orders
50+
from binance.cm_futures.account import get_all_orders
51+
from binance.cm_futures.account import balance
52+
from binance.cm_futures.account import account
53+
from binance.cm_futures.account import change_leverage
54+
from binance.cm_futures.account import change_margin_type
55+
from binance.cm_futures.account import modify_isolated_position_margin
56+
from binance.cm_futures.account import get_position_margin_history
57+
from binance.cm_futures.account import get_position_risk
58+
from binance.cm_futures.account import get_account_trades
59+
from binance.cm_futures.account import get_income_history
60+
from binance.cm_futures.account import leverage_brackets
61+
from binance.cm_futures.account import adl_quantile
62+
from binance.cm_futures.account import force_orders
63+
from binance.cm_futures.account import commission_rate
64+
65+
# STREAMS
66+
from binance.cm_futures.data_stream import new_listen_key
67+
from binance.cm_futures.data_stream import renew_listen_key
68+
from binance.cm_futures.data_stream import close_listen_key

0 commit comments

Comments
 (0)