|
| 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. |
0 commit comments