# apexpro
Official Python3 API connector for Apexpro's HTTP and WebSockets APIs.
You can get Api information from
[OpenApi-SDK](https://api-docs.pro.apex.exchange/#introduction)
## About
Put simply, `apexpro` is the official lightweight one-stop-shop module for the Apex pro HTTP and WebSocket APIs.
## Development
`apexpro` is being actively developed, and new API changes should arrive on `apexpro` very quickly. `apexpro` uses `requests` and `websocket` for its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request and we'll gladly take a look.
## Installation
`apexpro` requires Python 3.6.1 or higher. The module can be installed manually or via [apexpro](https://pypi.org/project/apexpro/) with `pip`:
```
pip install apexpro
```
## Basic Usage
You can create an HTTP session for Inverse on APEX_HTTP_TEST or APEX_HTTP_MAIN:
```python
from apexpro.constants import APEX_HTTP_TEST
from apexpro.http_public import HttpPublic
client = HttpPublic(APEX_HTTP_TEST)
```
### Public endpoints
You can get no authentication information from public endpoints.
Please refer to [demo_public](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_public.py)
```python
from apexpro.constants import APEX_HTTP_TEST
from apexpro.http_public import HttpPublic
client = HttpPublic(APEX_HTTP_TEST)
print(client.server_time())
print(client.configs())
print(client.ticker(symbol="BTC-USDC"))
print(client.history_funding(symbol="BTC-USDC"))
print(client.depth(symbol="ETH-USDC",limit=100))
print(client.trades(symbol="ETH-USDC",limit=100))
print(client.klines(symbol="ETH-USDC",interval="15"))
print(client.history_funding(symbol="ETH-USDC",limit=100,page=0,beginTimeInclusive=1662348573000,endTimeExclusive=1662434973000))
```
### Register method
You can get stark_key_pair, apiKey,and accountId for private Api , create-order and withdraw
Please refer to [demo_register](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_register.py)
```python
from apexpro.http_private import HttpPrivate
from apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST, APEX_HTTP_MAIN, NETWORKID_MAIN
priKey = "your eth private key"
client = HttpPrivate(APEX_HTTP_TEST, network_id=NETWORKID_TEST, eth_private_key=priKey)
configs = client.configs()
stark_key_pair_with_y_coordinate = client.derive_stark_key(client.default_address)
nonceRes = client.generate_nonce(starkKey=stark_key_pair_with_y_coordinate['public_key'],ethAddress=client.default_address,chainId=NETWORKID_TEST)
regRes = client.register_user(nonce=nonceRes['data']['nonce'],starkKey=stark_key_pair_with_y_coordinate['public_key'],stark_public_key_y_coordinate=stark_key_pair_with_y_coordinate['public_key_y_coordinate'],ethereum_address=client.default_address)
key = regRes['data']['apiKey']['key']
secret = regRes['data']['apiKey']['secret']
passphrase = regRes['data']['apiKey']['passphrase']
#back stark_key_pair, apiKey,and accountId for private Api or create-order or withdraw
print(stark_key_pair_with_y_coordinate)
print(regRes['data']['account']['positionId'])
print(regRes['data']['apiKey'])
```
### Private endpoints
some authentication information is required to access private endpoints.
Please refer to [demo_private](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_private.py)
```python
from apexpro.http_private import HttpPrivate
from apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST
# need apiKey={'key': key,'secret': secret, 'passphrase': passphrase} for private api
key = 'your apiKey-key from register'
secret = 'your apiKey-secret from register'
passphrase = 'your apiKey-passphrase from register'
client = HttpPrivate(APEX_HTTP_TEST, network_id=NETWORKID_TEST, api_key_credentials={'key': key,'secret': secret, 'passphrase': passphrase})
configs = client.configs()
userRes = client.get_user()
print(userRes)
modifyUserRes = client.modify_user(username="pythonTest",email="11@aa.com",emailNotifyGeneralEnable="false")
print(modifyUserRes)
accountRes = client.get_account()
print(accountRes)
openOrdersRes = client.open_orders()
print(openOrdersRes)
historyOrdersRes = client.history_orders()
print(historyOrdersRes)
fundingRes = client.funding(limit=100,page=0,symbol="BTC-USDC",side="BUY")
print(fundingRes)
notifyListRes = client.notify_list(limit=100,page=0,unreadOnly="true",notifyCategory="1")
print(notifyListRes)
...
```
### Stark key sign method
Several endpoints require a starkKey signature authentication, namely as following:
- create-order
- withdraw
Please refer to [demo_stark_key_sign](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_stark_key_sign.py)
```python
import time
from apexpro.http_private_stark_key_sign import HttpPrivateStark
from apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST
# need api_key_credentials={'key': key,'secret': secret, 'passphrase': passphrase} for private api
# need starkey for withdraw and createOrder
key = 'your apiKey-key from register'
secret = 'your apiKey-secret from register'
passphrase = 'your apiKey-passphrase from register'
public_key = 'your stark_public_key from register'
public_key_y_coordinate = 'your stark_public_key_y_coordinate from register'
private_key = 'your stark_private_key from register'
client = HttpPrivateStark(APEX_HTTP_TEST, network_id=NETWORKID_TEST,
stark_public_key=public_key,
stark_private_key=private_key,
stark_public_key_y_coordinate=public_key_y_coordinate,
api_key_credentials={'key': key, 'secret': secret, 'passphrase': passphrase})
configs = client.configs()
client.get_user()
client.get_account()
currentTime = time.time()
limitFeeRate = client.account['takerFeeRate']
createOrderRes = client.create_order(symbol="BTC-USDC", side="BUY",
type="LIMIT", size="0.01",
price="1991", limitFeeRate=limitFeeRate,
accountId=client.account['positionId'],
expirationEpochSeconds= currentTime)
print(createOrderRes)
worstPrice = client.get_worst_price(symbol="BTC-USDC", side="SELL", size="0.1")
price = worstPrice['data']['worstPrice']
##market order price must not none
createOrderRes = client.create_order(symbol="BTC-USDC", side="SELL",
type="MARKET", size="1", price=price, limitFee=limitFee,
expirationEpochSeconds= currentTime)
print(createOrderRes)
#createWithdrawRes = client.create_withdrawal(amount='1001',expirationEpochSeconds= currentTime,asset='USDC')
#print(createWithdrawRes)
#feeRes = client.uncommon_withdraw_fee(amount='1002',chainId='5')
#print(feeRes)
#fastWithdrawRes = client.fast_withdrawal(amount='1002',expirationEpochSeconds= currentTime,asset='USDC',fee=feeRes['data']['fee'])
#print(fastWithdrawRes)
deleteOrderRes = client.delete_open_orders(symbol="BTC-USDC")
print(deleteOrderRes)
deleteOrderRes = client.delete_open_orders()
print(deleteOrderRes)
feeRes = client.uncommon_withdraw_fee(amount='1003',chainId='97')
print(feeRes)
crossWithdrawRes = client.cross_chain_withdraw(amount='1003',expirationEpochSeconds= currentTime,asset='USDC',fee=feeRes['data']['fee'],chainId='97')
print(crossWithdrawRes)
```
### WebSocket
To see comprehensive examples of how to subscribe topics from websockets.
Please refer to [demo_ws](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_ws.py)
```python
from time import sleep
from apexpro.constants import APEX_WS_TEST
from apexpro.websocket_api import WebSocket
key = 'your apiKey-key from register'
secret = 'your apiKey-secret from register'
passphrase = 'your apiKey-passphrase from register'
# Connect with authentication!
ws_client = WebSocket(
endpoint=APEX_WS_TEST,
api_key_credentials={'key': key, 'secret': secret, 'passphrase': passphrase},
)
def handle_account(message):
print(message)
contents_data = message["contents"]
print(len(contents_data))
def h1(message):
print(1, message)
def h2(message):
print(2, message)
def h3(message):
print(3, message)
def h4(message):
print(4, message)
#ws_client.depth_stream(h1,'BTCUSDC',25)
#ws_client.ticker_stream(h2,'BTCUSDC')
#ws_client.trade_stream(h3,'BTCUSDC')
#ws_client.klines_stream(h4,'BTCUSDC',1)
ws_client.account_info_stream(handle_account)
while True:
# Run your main trading logic here.
sleep(1)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/xxx",
"name": "apexpro-mod",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "apexpro api connector",
"author": "Dexter Dickinson",
"author_email": "xxx@apexpro.com",
"download_url": "https://files.pythonhosted.org/packages/9d/e6/df485fde9203e391a457acb48b0ab262d8c01598af3d5e463f2d60a72c90/apexpro-mod-1.1.8.tar.gz",
"platform": null,
"description": "# apexpro\n\nOfficial Python3 API connector for Apexpro's HTTP and WebSockets APIs. \nYou can get Api information from \n[OpenApi-SDK](https://api-docs.pro.apex.exchange/#introduction)\n\n## About\nPut simply, `apexpro` is the official lightweight one-stop-shop module for the Apex pro HTTP and WebSocket APIs. \n\n## Development\n`apexpro` is being actively developed, and new API changes should arrive on `apexpro` very quickly. `apexpro` uses `requests` and `websocket` for its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request and we'll gladly take a look.\n\n## Installation\n`apexpro` requires Python 3.6.1 or higher. The module can be installed manually or via [apexpro](https://pypi.org/project/apexpro/) with `pip`:\n```\npip install apexpro\n```\n\n## Basic Usage\nYou can create an HTTP session for Inverse on APEX_HTTP_TEST or APEX_HTTP_MAIN:\n```python\nfrom apexpro.constants import APEX_HTTP_TEST\nfrom apexpro.http_public import HttpPublic\n\nclient = HttpPublic(APEX_HTTP_TEST)\n```\n### Public endpoints\nYou can get no authentication information from public endpoints. \nPlease refer to [demo_public](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_public.py)\n\n```python\nfrom apexpro.constants import APEX_HTTP_TEST\nfrom apexpro.http_public import HttpPublic\n\nclient = HttpPublic(APEX_HTTP_TEST)\nprint(client.server_time())\nprint(client.configs())\nprint(client.ticker(symbol=\"BTC-USDC\"))\nprint(client.history_funding(symbol=\"BTC-USDC\"))\nprint(client.depth(symbol=\"ETH-USDC\",limit=100))\nprint(client.trades(symbol=\"ETH-USDC\",limit=100))\nprint(client.klines(symbol=\"ETH-USDC\",interval=\"15\"))\nprint(client.history_funding(symbol=\"ETH-USDC\",limit=100,page=0,beginTimeInclusive=1662348573000,endTimeExclusive=1662434973000))\n```\n\n### Register method\nYou can get stark_key_pair, apiKey,and accountId for private Api , create-order and withdraw \nPlease refer to [demo_register](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_register.py)\n\n```python\nfrom apexpro.http_private import HttpPrivate\nfrom apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST, APEX_HTTP_MAIN, NETWORKID_MAIN\n\npriKey = \"your eth private key\"\n\nclient = HttpPrivate(APEX_HTTP_TEST, network_id=NETWORKID_TEST, eth_private_key=priKey)\nconfigs = client.configs()\n\nstark_key_pair_with_y_coordinate = client.derive_stark_key(client.default_address)\nnonceRes = client.generate_nonce(starkKey=stark_key_pair_with_y_coordinate['public_key'],ethAddress=client.default_address,chainId=NETWORKID_TEST)\n\nregRes = client.register_user(nonce=nonceRes['data']['nonce'],starkKey=stark_key_pair_with_y_coordinate['public_key'],stark_public_key_y_coordinate=stark_key_pair_with_y_coordinate['public_key_y_coordinate'],ethereum_address=client.default_address)\nkey = regRes['data']['apiKey']['key']\nsecret = regRes['data']['apiKey']['secret']\npassphrase = regRes['data']['apiKey']['passphrase']\n\n#back stark_key_pair, apiKey,and accountId for private Api or create-order or withdraw\nprint(stark_key_pair_with_y_coordinate)\nprint(regRes['data']['account']['positionId'])\nprint(regRes['data']['apiKey'])\n```\n\n### Private endpoints\nsome authentication information is required to access private endpoints. \nPlease refer to [demo_private](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_private.py)\n\n```python\nfrom apexpro.http_private import HttpPrivate\nfrom apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST\n\n# need apiKey={'key': key,'secret': secret, 'passphrase': passphrase} for private api\n\nkey = 'your apiKey-key from register'\nsecret = 'your apiKey-secret from register'\npassphrase = 'your apiKey-passphrase from register'\n\nclient = HttpPrivate(APEX_HTTP_TEST, network_id=NETWORKID_TEST, api_key_credentials={'key': key,'secret': secret, 'passphrase': passphrase})\nconfigs = client.configs()\n\nuserRes = client.get_user()\nprint(userRes)\n\nmodifyUserRes = client.modify_user(username=\"pythonTest\",email=\"11@aa.com\",emailNotifyGeneralEnable=\"false\")\nprint(modifyUserRes)\n\naccountRes = client.get_account()\nprint(accountRes)\n\nopenOrdersRes = client.open_orders()\nprint(openOrdersRes)\n\nhistoryOrdersRes = client.history_orders()\nprint(historyOrdersRes)\n\nfundingRes = client.funding(limit=100,page=0,symbol=\"BTC-USDC\",side=\"BUY\")\nprint(fundingRes)\n\nnotifyListRes = client.notify_list(limit=100,page=0,unreadOnly=\"true\",notifyCategory=\"1\")\nprint(notifyListRes)\n\n...\n```\n\n### Stark key sign method\nSeveral endpoints require a starkKey signature authentication, namely as following:\n- create-order\n- withdraw\n\nPlease refer to [demo_stark_key_sign](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_stark_key_sign.py)\n\n```python\nimport time\nfrom apexpro.http_private_stark_key_sign import HttpPrivateStark\n\nfrom apexpro.constants import APEX_HTTP_TEST, NETWORKID_TEST\n\n# need api_key_credentials={'key': key,'secret': secret, 'passphrase': passphrase} for private api\n# need starkey for withdraw and createOrder\n\nkey = 'your apiKey-key from register'\nsecret = 'your apiKey-secret from register'\npassphrase = 'your apiKey-passphrase from register'\n\npublic_key = 'your stark_public_key from register'\npublic_key_y_coordinate = 'your stark_public_key_y_coordinate from register'\nprivate_key = 'your stark_private_key from register'\n\n\nclient = HttpPrivateStark(APEX_HTTP_TEST, network_id=NETWORKID_TEST,\nstark_public_key=public_key,\nstark_private_key=private_key,\nstark_public_key_y_coordinate=public_key_y_coordinate,\napi_key_credentials={'key': key, 'secret': secret, 'passphrase': passphrase})\nconfigs = client.configs()\nclient.get_user()\nclient.get_account()\n\ncurrentTime = time.time()\n\nlimitFeeRate = client.account['takerFeeRate']\ncreateOrderRes = client.create_order(symbol=\"BTC-USDC\", side=\"BUY\",\ntype=\"LIMIT\", size=\"0.01\",\nprice=\"1991\", limitFeeRate=limitFeeRate,\naccountId=client.account['positionId'],\nexpirationEpochSeconds= currentTime)\nprint(createOrderRes)\n\n\n\nworstPrice = client.get_worst_price(symbol=\"BTC-USDC\", side=\"SELL\", size=\"0.1\")\nprice = worstPrice['data']['worstPrice']\n##market order price must not none\ncreateOrderRes = client.create_order(symbol=\"BTC-USDC\", side=\"SELL\",\ntype=\"MARKET\", size=\"1\", price=price, limitFee=limitFee,\nexpirationEpochSeconds= currentTime)\nprint(createOrderRes)\n\n#createWithdrawRes = client.create_withdrawal(amount='1001',expirationEpochSeconds= currentTime,asset='USDC')\n#print(createWithdrawRes)\n\n#feeRes = client.uncommon_withdraw_fee(amount='1002',chainId='5')\n#print(feeRes)\n#fastWithdrawRes = client.fast_withdrawal(amount='1002',expirationEpochSeconds= currentTime,asset='USDC',fee=feeRes['data']['fee'])\n#print(fastWithdrawRes)\n\ndeleteOrderRes = client.delete_open_orders(symbol=\"BTC-USDC\")\nprint(deleteOrderRes)\n\ndeleteOrderRes = client.delete_open_orders()\nprint(deleteOrderRes)\n\n\nfeeRes = client.uncommon_withdraw_fee(amount='1003',chainId='97')\nprint(feeRes)\ncrossWithdrawRes = client.cross_chain_withdraw(amount='1003',expirationEpochSeconds= currentTime,asset='USDC',fee=feeRes['data']['fee'],chainId='97')\nprint(crossWithdrawRes)\n\n```\n\n### WebSocket\nTo see comprehensive examples of how to subscribe topics from websockets.\nPlease refer to [demo_ws](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_ws.py)\n\n\n```python\nfrom time import sleep\n\nfrom apexpro.constants import APEX_WS_TEST\nfrom apexpro.websocket_api import WebSocket\n\nkey = 'your apiKey-key from register'\nsecret = 'your apiKey-secret from register'\npassphrase = 'your apiKey-passphrase from register'\n\n# Connect with authentication!\nws_client = WebSocket(\n endpoint=APEX_WS_TEST,\n api_key_credentials={'key': key, 'secret': secret, 'passphrase': passphrase},\n)\n\ndef handle_account(message):\n print(message)\n contents_data = message[\"contents\"]\n print(len(contents_data))\n\ndef h1(message):\n print(1, message)\ndef h2(message):\n print(2, message)\ndef h3(message):\n print(3, message)\ndef h4(message):\n print(4, message)\n\n#ws_client.depth_stream(h1,'BTCUSDC',25)\n#ws_client.ticker_stream(h2,'BTCUSDC')\n#ws_client.trade_stream(h3,'BTCUSDC')\n#ws_client.klines_stream(h4,'BTCUSDC',1)\nws_client.account_info_stream(handle_account)\n\n\nwhile True:\n # Run your main trading logic here.\n sleep(1)\n\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Python3 Apexpro HTTP/WebSocket API Connector",
"version": "1.1.8",
"project_urls": {
"Homepage": "https://github.com/xxx"
},
"split_keywords": [
"apexpro",
"api",
"connector"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9de6df485fde9203e391a457acb48b0ab262d8c01598af3d5e463f2d60a72c90",
"md5": "bef535a340ef019ba0460d3a037aa739",
"sha256": "9cad70e7fba95652dbabb2d9c727ac366d6bae0c84f4288a990968e2464d0d15"
},
"downloads": -1,
"filename": "apexpro-mod-1.1.8.tar.gz",
"has_sig": false,
"md5_digest": "bef535a340ef019ba0460d3a037aa739",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 90784,
"upload_time": "2023-11-12T05:08:06",
"upload_time_iso_8601": "2023-11-12T05:08:06.297773Z",
"url": "https://files.pythonhosted.org/packages/9d/e6/df485fde9203e391a457acb48b0ab262d8c01598af3d5e463f2d60a72c90/apexpro-mod-1.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-12 05:08:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "apexpro-mod"
}