Skip to content

Commit 870f816

Browse files
committed
pushback
1 parent 08ceb72 commit 870f816

File tree

290 files changed

+66549
-2
lines changed

Some content is hidden

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

290 files changed

+66549
-2
lines changed

README.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# hashkey-python
2+
Python SDK (sync and async) for Hashkey cryptocurrency exchange with Rest and WS capabilities.
3+
4+
- You can check the SDK docs here: [SDK](https://docs.ccxt.com/#/exchanges/hashkey)
5+
- You can check Hashkey's docs here: [Docs](https://www.google.com/search?q=google+hashkey+cryptocurrency+exchange+api+docs)
6+
- Github repo: https://github.com/ccxt/hashkey-python
7+
- Pypi package: https://pypi.org/project/hashkey
8+
9+
10+
## Installation
11+
12+
```
13+
pip install hashkey
14+
```
15+
16+
## Usage
17+
18+
### Sync
19+
20+
```Python
21+
from hashkey import HashkeySync
22+
23+
def main():
24+
instance = HashkeySync({})
25+
ob = instance.fetch_order_book("BTC/USDC")
26+
print(ob)
27+
#
28+
# balance = instance.fetch_balance()
29+
# order = instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)
30+
31+
main()
32+
```
33+
34+
### Async
35+
36+
```Python
37+
import sys
38+
import asyncio
39+
from hashkey import HashkeyAsync
40+
41+
### on Windows, uncomment below:
42+
# if sys.platform == 'win32':
43+
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
44+
45+
async def main():
46+
instance = HashkeyAsync({})
47+
ob = await instance.fetch_order_book("BTC/USDC")
48+
print(ob)
49+
#
50+
# balance = await instance.fetch_balance()
51+
# order = await instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)
52+
53+
# once you are done with the exchange
54+
await instance.close()
55+
56+
asyncio.run(main())
57+
```
58+
59+
60+
61+
### Websockets
62+
63+
```Python
64+
import sys
65+
from hashkey import HashkeyWs
66+
67+
### on Windows, uncomment below:
68+
# if sys.platform == 'win32':
69+
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
70+
71+
async def main():
72+
instance = HashkeyWs({})
73+
while True:
74+
ob = await instance.watch_order_book("BTC/USDC")
75+
print(ob)
76+
# orders = await instance.watch_orders("BTC/USDC")
77+
78+
# once you are done with the exchange
79+
await instance.close()
80+
81+
asyncio.run(main())
82+
```
83+
84+
85+
86+
87+
88+
#### Raw call
89+
90+
You can also construct custom requests to available "implicit" endpoints
91+
92+
```Python
93+
request = {
94+
'type': 'candleSnapshot',
95+
'req': {
96+
'coin': coin,
97+
'interval': tf,
98+
'startTime': since,
99+
'endTime': until,
100+
},
101+
}
102+
response = await instance.public_post_info(request)
103+
```
104+
105+
106+
## Available methods
107+
108+
### REST Unified
109+
110+
- `create_market_buy_order_with_cost(self, symbol: str, cost: float, params={})`
111+
- `create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
112+
- `create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
113+
- `create_orders(self, orders: List[OrderRequest], params={})`
114+
- `create_spot_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
115+
- `create_spot_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
116+
- `create_swap_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
117+
- `create_swap_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})`
118+
- `fetch_accounts(self, params={})`
119+
- `fetch_balance(self, params={})`
120+
- `fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
121+
- `fetch_currencies(self, params={})`
122+
- `fetch_deposit_address(self, code: str, params={})`
123+
- `fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={})`
124+
- `fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
125+
- `fetch_funding_rate(self, symbol: str, params={})`
126+
- `fetch_funding_rates(self, symbols: Strings = None, params={})`
127+
- `fetch_last_prices(self, symbols: Strings = None, params={})`
128+
- `fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={})`
129+
- `fetch_leverage_tiers(self, symbols: Strings = None, params={})`
130+
- `fetch_leverage(self, symbol: str, params={})`
131+
- `fetch_markets(self, params={})`
132+
- `fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
133+
- `fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={})`
134+
- `fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
135+
- `fetch_open_spot_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
136+
- `fetch_open_swap_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
137+
- `fetch_order_book(self, symbol: str, limit: Int = None, params={})`
138+
- `fetch_order(self, id: str, symbol: Str = None, params={})`
139+
- `fetch_positions_for_symbol(self, symbol: str, params={})`
140+
- `fetch_positions(self, symbols: Strings = None, params={})`
141+
- `fetch_status(self, params={})`
142+
- `fetch_ticker(self, symbol: str, params={})`
143+
- `fetch_tickers(self, symbols: Strings = None, params={})`
144+
- `fetch_time(self, params={})`
145+
- `fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})`
146+
- `fetch_trading_fee(self, symbol: str, params={})`
147+
- `fetch_trading_fees(self, params={})`
148+
- `fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={})`
149+
- `cancel_all_orders(self, symbol: Str = None, params={})`
150+
- `cancel_order(self, id: str, symbol: Str = None, params={})`
151+
- `cancel_orders(self, ids: List[str], symbol: Str = None, params={})`
152+
- `check_type_param(self, methodName, params)`
153+
- `custom_urlencode(self, params: dict = {})`
154+
- `describe(self)`
155+
- `encode_account_type(self, type)`
156+
- `encode_flow_type(self, type)`
157+
- `set_leverage(self, leverage: Int, symbol: Str = None, params={})`
158+
- `transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={})`
159+
- `withdraw(self, code: str, amount: float, address: str, tag=None, params={})`
160+
161+
### REST Raw
162+
163+
- `public_get_api_v1_exchangeinfo(request)`
164+
- `public_get_quote_v1_depth(request)`
165+
- `public_get_quote_v1_trades(request)`
166+
- `public_get_quote_v1_klines(request)`
167+
- `public_get_quote_v1_ticker_24hr(request)`
168+
- `public_get_quote_v1_ticker_price(request)`
169+
- `public_get_quote_v1_ticker_bookticker(request)`
170+
- `public_get_quote_v1_depth_merged(request)`
171+
- `public_get_quote_v1_markprice(request)`
172+
- `public_get_quote_v1_index(request)`
173+
- `public_get_api_v1_futures_fundingrate(request)`
174+
- `public_get_api_v1_futures_historyfundingrate(request)`
175+
- `public_get_api_v1_ping(request)`
176+
- `public_get_api_v1_time(request)`
177+
- `private_get_api_v1_spot_order(request)`
178+
- `private_get_api_v1_spot_openorders(request)`
179+
- `private_get_api_v1_spot_tradeorders(request)`
180+
- `private_get_api_v1_futures_leverage(request)`
181+
- `private_get_api_v1_futures_order(request)`
182+
- `private_get_api_v1_futures_openorders(request)`
183+
- `private_get_api_v1_futures_usertrades(request)`
184+
- `private_get_api_v1_futures_positions(request)`
185+
- `private_get_api_v1_futures_historyorders(request)`
186+
- `private_get_api_v1_futures_balance(request)`
187+
- `private_get_api_v1_futures_liquidationassignstatus(request)`
188+
- `private_get_api_v1_futures_risklimit(request)`
189+
- `private_get_api_v1_futures_commissionrate(request)`
190+
- `private_get_api_v1_futures_getbestorder(request)`
191+
- `private_get_api_v1_account_vipinfo(request)`
192+
- `private_get_api_v1_account(request)`
193+
- `private_get_api_v1_account_trades(request)`
194+
- `private_get_api_v1_account_type(request)`
195+
- `private_get_api_v1_account_checkapikey(request)`
196+
- `private_get_api_v1_account_balanceflow(request)`
197+
- `private_get_api_v1_spot_subaccount_openorders(request)`
198+
- `private_get_api_v1_spot_subaccount_tradeorders(request)`
199+
- `private_get_api_v1_subaccount_trades(request)`
200+
- `private_get_api_v1_futures_subaccount_openorders(request)`
201+
- `private_get_api_v1_futures_subaccount_historyorders(request)`
202+
- `private_get_api_v1_futures_subaccount_usertrades(request)`
203+
- `private_get_api_v1_account_deposit_address(request)`
204+
- `private_get_api_v1_account_depositorders(request)`
205+
- `private_get_api_v1_account_withdraworders(request)`
206+
- `private_post_api_v1_userdatastream(request)`
207+
- `private_post_api_v1_spot_ordertest(request)`
208+
- `private_post_api_v1_spot_order(request)`
209+
- `private_post_api_v1_1_spot_order(request)`
210+
- `private_post_api_v1_spot_batchorders(request)`
211+
- `private_post_api_v1_futures_leverage(request)`
212+
- `private_post_api_v1_futures_order(request)`
213+
- `private_post_api_v1_futures_position_trading_stop(request)`
214+
- `private_post_api_v1_futures_batchorders(request)`
215+
- `private_post_api_v1_account_assettransfer(request)`
216+
- `private_post_api_v1_account_authaddress(request)`
217+
- `private_post_api_v1_account_withdraw(request)`
218+
- `private_put_api_v1_userdatastream(request)`
219+
- `private_delete_api_v1_spot_order(request)`
220+
- `private_delete_api_v1_spot_openorders(request)`
221+
- `private_delete_api_v1_spot_cancelorderbyids(request)`
222+
- `private_delete_api_v1_futures_order(request)`
223+
- `private_delete_api_v1_futures_batchorders(request)`
224+
- `private_delete_api_v1_futures_cancelorderbyids(request)`
225+
- `private_delete_api_v1_userdatastream(request)`
226+
227+
### WS Unified
228+
229+
- `describe(self)`
230+
- `wath_public(self, market: Market, topic: str, messageHash: str, params={})`
231+
- `watch_private(self, messageHash)`
232+
- `get_private_url(self, listenKey)`
233+
- `watch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={})`
234+
- `watch_ticker(self, symbol: str, params={})`
235+
- `watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})`
236+
- `watch_order_book(self, symbol: str, limit: Int = None, params={})`
237+
- `watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
238+
- `watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
239+
- `watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={})`
240+
- `watch_balance(self, params={})`
241+
- `set_balance_cache(self, client: Client, type, subscribeHash)`
242+
- `load_balance_snapshot(self, client, messageHash, type)`
243+
- `authenticate(self, params={})`
244+
- `keep_alive_listen_key(self, listenKey, params={})`
245+
246+
## Contribution
247+
- Give us a star :star:
248+
- Fork and Clone! Awesome
249+
- Select existing issues or create a new issue.

build/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"build-single-exchange": "tsx build.ts",
88
"pypi-packager": "tsx pypi-packager.ts",
9-
109
"sample-generate": "cd ../.github/scripts/ && bash generate-exchange-skeleton.sh ../../../tmp_folder kucoin",
1110
"sample-build": "cd ../../tmp_folder/build && npm run build-single-exchange",
1211
"sample-pypi": "cd ../../tmp_folder/build && npm run pypi-packager",
@@ -17,7 +16,8 @@
1716
"dependencies": {
1817
"fs": "*",
1918
"path": "*",
20-
"semver": "^7.7.1"
19+
"semver": "^7.7.1",
20+
"typescript": "^5.8.3"
2121
},
2222
"devDependencies": {
2323
"tsx": "^4.19.3"

examples/async.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import sys
3+
import asyncio
4+
5+
# if CCXT is included locally
6+
# sys.path.append(os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) + '/')
7+
8+
from hashkey import HashkeyAsync
9+
10+
if sys.platform == 'win32':
11+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
12+
13+
async def main():
14+
instance = HashkeyAsync({})
15+
await instance.load_markets()
16+
symbol = "BTC/USDC"
17+
18+
# fetch ticker
19+
ticker = await instance.fetch_ticker(symbol)
20+
print(ticker)
21+
22+
# create order
23+
order = await instance.create_order("BTC/USDC", "limit", "buy", 1, 123456.789)
24+
print(order)
25+
26+
# close after you finish
27+
await instance.close()
28+
29+
asyncio.run(main())
30+

examples/sync.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import sys
3+
4+
root = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
5+
sys.path.append(root + '/')
6+
7+
from hashkey import HashkeySync
8+
9+
10+
def main():
11+
instance = HashkeySync({})
12+
instance.load_markets()
13+
symbol = "BTC/USDC"
14+
15+
# fetch ticker
16+
ticker = instance.fetch_ticker(symbol)
17+
print(ticker)
18+
19+
# create order
20+
order = instance.create_order("BTC/USDC", "limit", "buy", 1, 123456.789)
21+
print(order)
22+
23+
main()
24+

examples/websockets.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import sys
3+
import asyncio
4+
5+
# if CCXT is included locally
6+
# sys.path.append(os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) + '/')
7+
8+
from hashkey import HashkeyWs
9+
10+
if sys.platform == 'win32':
11+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
12+
13+
async def my_watch_ticker(exchange, symbol):
14+
while (True):
15+
result = await exchange.watch_ticker(symbol)
16+
print(result)
17+
18+
19+
async def my_watch_orderbook(exchange, symbol):
20+
while (True):
21+
result = await exchange.watch_order_book(symbol)
22+
print(result)
23+
24+
25+
26+
27+
async def main():
28+
instance = HashkeyWs({})
29+
await instance.load_markets()
30+
symbol = "BTC/USDC"
31+
32+
# fetch ticker
33+
ticker = my_watch_ticker(instance, symbol)
34+
35+
# fetch orderbook
36+
ob = my_watch_orderbook(instance, symbol)
37+
38+
await asyncio.gather(ticker, ob)
39+
40+
# close after you finish
41+
await instance.close()
42+
43+
44+
45+
46+
asyncio.run(main())
47+

hashkey/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
import hashkey.ccxt as ccxt_module
3+
sys.modules['ccxt'] = ccxt_module
4+
5+
from hashkey.ccxt import hashkey as HashkeySync
6+
from hashkey.ccxt.async_support.hashkey import hashkey as HashkeyAsync
7+
from hashkey.ccxt.pro.hashkey import hashkey as HashkeyWs

0 commit comments

Comments
 (0)