apexpro


Nameapexpro JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/xxx
SummaryPython3 Apexpro HTTP/WebSocket API Connector
upload_time2024-04-15 03:46:04
maintainerNone
docs_urlNone
authorDexter Dickinson
requires_python>=3.6
licenseMIT License
keywords apexpro api connector
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```

## New Basic Usage V2 
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 V2

You can get no authentication information from public endpoints.  
Please refer to [demo_public_v2](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_public_v2.py)

The V2 version supports both USDT and USDC symbols. Users need to request the configs_v2() interface to obtain the configuration of symbols.
```python
from apexpro.constants import APEX_HTTP_TEST, APEX_HTTP_MAIN
from apexpro.http_public import HttpPublic

client = HttpPublic(APEX_HTTP_MAIN)
print(client.configs_v2())
print(client.history_funding_v2(symbol="BTC-USDT"))
print(client.klines(symbol="ETHUSDT",interval=5,start=1681463600, end=1681563600, limit=5))
print(client.server_time())
print(client.depth(symbol="BTC-USDC"))
print(client.trades(symbol="BTC-USDC"))
print(client.klines(symbol="BTC-USDT",interval="15"))
print(client.ticker(symbol="BTC-USDT"))
print(client.history_funding(symbol="BTC-USDT"))

print(client.depth(symbol="ETH-USDT",limit=50))
print(client.trades(symbol="ETH-USDT",limit=50))
print(client.klines(symbol="ETH-USDT",interval="15"))
print(client.history_funding_v2(symbol="ETH-USDT",limit=100,page=0,beginTimeInclusive=1662348573000,endTimeExclusive=1662434973000))
```

### Register  method V2
If the user wants to trade USDT symbols, needs to call the register_user_v2() interface to register a USDT account, 
and fill in 'USDT' for the token parameter. In the same way, to trade USDC symbols, 
call the register_user_v2() interface to register a USDC account, and fill in 'USDC' as the token parameter. 
If the user has previously registered a USDC account using the v1 interface, there is no need to use the register_user_v2() 
interface to register again.      
You need to call client.configs_v2() after init client.   
You can get stark_key_pair, apiKey,and accountId for private Api , create-order and withdraw  
Please refer to [demo_register_v2](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_register_v2.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_v2()

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_v2(token='USDT', 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 V2
The V2 version supports both USDT and USDC Account. Users need to request the configs_v2() and get_account_v2() interface to obtain the configuration of Account.

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_v2()

accountRes = client.get_account_v2()
print(accountRes)

fillsRes = client.fills_v2(limit=100,page=0,symbol="BTC-USDT",side="BUY",token="USDT")
print(fillsRes)

transfersRes = client.transfers_v2(limit=100,page=0,currencyId="USDT",chainIds="1,5,13,97")
print(transfersRes)

withdrawListRes = client.withdraw_list_v2(limit=100,page=0,beginTimeInclusive=1651406864000,endTimeExclusive=1657105971171)
print(withdrawListRes)

uncommon_withdraw_feeRes = client.uncommon_withdraw_fee_v2(amount="101000.1",token="USDT", chainId=5)
print(uncommon_withdraw_feeRes)

transfer_limitRes = client.transfer_limit_v2(currencyId="USDT")
print(transfer_limitRes)

fillsRes = client.fills_v2(limit=100,page=0,symbol="BTC-USDT",side="BUY",token="USDT")
print(fillsRes)

deleteOrderRes = client.delete_order_v2(id="123456")
print(deleteOrderRes)

deleteOrderRes = client.delete_order_by_client_order_id_v2(id="123456")
print(deleteOrderRes)

openOrdersRes = client.open_orders_v2(token='USDT')
print(openOrdersRes)

deleteOrdersRes = client.delete_open_orders_v2(symbol="BTC-USDC,ETH-USDC", token='USDT')
print(deleteOrdersRes)

historyOrdersRes = client.history_orders_v2(token='USDT')
print(historyOrdersRes)

getOrderRes = client.get_order_v2(id="123456")
print(getOrderRes)

getOrderRes = client.get_order_by_client_order_id_v2(id="123456")
print(getOrderRes)

fundingRes = client.funding_v2(limit=100,page=0,symbol="BTC-USDC",side="BUY",token='USDT')
print(fundingRes)

notifyListRes = client.notify_list(limit=100,page=0,unreadOnly="true",notifyCategory="1")
print(notifyListRes)

markNotifyReadRes = client.mark_notify_read(ids="113123,123123123")
print(markNotifyReadRes)

historicalPnlRes = client.historical_pnl_v2(limit=100,page=0,beginTimeInclusive=1651406864000,endTimeExclusive=1657105971171,symbol="BTC-USDC")
print(historicalPnlRes)

yesterdayPnlRes = client.yesterday_pnl_v2(token='USDT')
print(yesterdayPnlRes)

historyValueRes = client.history_value_v2(token='USDT')
print(historyValueRes)

markAllNotifyReadRes = client.mark_all_notify_read()
print(markAllNotifyReadRes)

setInitialMarginRateRes = client.set_initial_margin_rate_v2(symbol="BTC-USDC",initialMarginRate="0.1",token='USDT')
print(setInitialMarginRateRes)

```

### Stark key sign method
The V2 version supports both USDT and USDC Account. Users need to request the configs_v2() and get_account_v2() interface to obtain the configuration of Account.

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_v2()
client.get_user()
print(client.get_account_v2())

print(client.get_account_balance_v2())

currentTime = time.time()

#feeRes = client.uncommon_withdraw_fee_v2(amount='2',chainId='5', token='USDT',)
#print(feeRes)
#fastWithdrawRes = client.fast_withdrawal_v2(amount='2',expirationEpochSeconds= currentTime,asset='USDT',fee=feeRes['data']['fee'])

#createWithdrawRes = client.create_withdrawal_v2(amount='1',expirationEpochSeconds= currentTime,asset='USDT')
#print(createWithdrawRes)

historyOrdersRes = client.history_orders_v2(token="USDT")
print(historyOrdersRes)

orderFills = client.order_fills_v2(orderId='498441108374684453')
print(orderFills)

limitFeeRate = '0.0005'

deleteOrdersRes = client.delete_open_orders_v2(token="USDT")
print(deleteOrdersRes)


createOrderRes = client.create_order_v2(symbol="BTC-USDT", side="SELL",
                                        type="LIMIT", size="0.01",expirationEpochSeconds= currentTime,
                                        price="36890", limitFeeRate=limitFeeRate, timeInForce="POST_ONLY")

#print(createOrderRes)

fillsRes = client.fills_v2(limit=100,page=0,symbol="BTC-USDT",token="USDT")
print(fillsRes)


openOrderRes = client.open_orders_v2(token='USDT')
print(openOrderRes)


deleteOrdersRes = client.delete_open_orders_v2(token="USDT")
print(deleteOrdersRes)

historyOrdersRes = client.history_orders_v2(token="USDT")
print(historyOrdersRes)

openOrderRes = client.open_orders_v2(token='USDT')
print(openOrderRes)

feeRes = client.uncommon_withdraw_fee_v2(amount='2',chainId='97', token='USDT')
print(feeRes)
crossWithdrawRes = client.cross_chain_withdraw_v2(amount='2',expirationEpochSeconds= currentTime,asset='USDT',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)

```


## Old Basic Usage V1
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",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "apexpro api connector",
    "author": "Dexter Dickinson",
    "author_email": "xxx@apexpro.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/39/adb4d1427f85eb5f2144acf38672590d57a5eef39354bb3d80e4188e608b/apexpro-1.2.0.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## New Basic Usage V2 \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 V2\n\nYou can get no authentication information from public endpoints.  \nPlease refer to [demo_public_v2](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_public_v2.py)\n\nThe V2 version supports both USDT and USDC symbols. Users need to request the configs_v2() interface to obtain the configuration of symbols.\n```python\nfrom apexpro.constants import APEX_HTTP_TEST, APEX_HTTP_MAIN\nfrom apexpro.http_public import HttpPublic\n\nclient = HttpPublic(APEX_HTTP_MAIN)\nprint(client.configs_v2())\nprint(client.history_funding_v2(symbol=\"BTC-USDT\"))\nprint(client.klines(symbol=\"ETHUSDT\",interval=5,start=1681463600, end=1681563600, limit=5))\nprint(client.server_time())\nprint(client.depth(symbol=\"BTC-USDC\"))\nprint(client.trades(symbol=\"BTC-USDC\"))\nprint(client.klines(symbol=\"BTC-USDT\",interval=\"15\"))\nprint(client.ticker(symbol=\"BTC-USDT\"))\nprint(client.history_funding(symbol=\"BTC-USDT\"))\n\nprint(client.depth(symbol=\"ETH-USDT\",limit=50))\nprint(client.trades(symbol=\"ETH-USDT\",limit=50))\nprint(client.klines(symbol=\"ETH-USDT\",interval=\"15\"))\nprint(client.history_funding_v2(symbol=\"ETH-USDT\",limit=100,page=0,beginTimeInclusive=1662348573000,endTimeExclusive=1662434973000))\n```\n\n### Register  method V2\nIf the user wants to trade USDT symbols, needs to call the register_user_v2() interface to register a USDT account, \nand fill in 'USDT' for the token parameter. In the same way, to trade USDC symbols, \ncall the register_user_v2() interface to register a USDC account, and fill in 'USDC' as the token parameter. \nIf the user has previously registered a USDC account using the v1 interface, there is no need to use the register_user_v2() \ninterface to register again.      \nYou need to call client.configs_v2() after init client.   \nYou can get stark_key_pair, apiKey,and accountId for private Api , create-order and withdraw  \nPlease refer to [demo_register_v2](https://github.com/ApeX-Protocol/apexpro-openapi/blob/main/tests/demo_register_v2.py)\n\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_v2()\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_v2(token='USDT', 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 V2\nThe V2 version supports both USDT and USDC Account. Users need to request the configs_v2() and get_account_v2() interface to obtain the configuration of Account.\n\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_v2()\n\naccountRes = client.get_account_v2()\nprint(accountRes)\n\nfillsRes = client.fills_v2(limit=100,page=0,symbol=\"BTC-USDT\",side=\"BUY\",token=\"USDT\")\nprint(fillsRes)\n\ntransfersRes = client.transfers_v2(limit=100,page=0,currencyId=\"USDT\",chainIds=\"1,5,13,97\")\nprint(transfersRes)\n\nwithdrawListRes = client.withdraw_list_v2(limit=100,page=0,beginTimeInclusive=1651406864000,endTimeExclusive=1657105971171)\nprint(withdrawListRes)\n\nuncommon_withdraw_feeRes = client.uncommon_withdraw_fee_v2(amount=\"101000.1\",token=\"USDT\", chainId=5)\nprint(uncommon_withdraw_feeRes)\n\ntransfer_limitRes = client.transfer_limit_v2(currencyId=\"USDT\")\nprint(transfer_limitRes)\n\nfillsRes = client.fills_v2(limit=100,page=0,symbol=\"BTC-USDT\",side=\"BUY\",token=\"USDT\")\nprint(fillsRes)\n\ndeleteOrderRes = client.delete_order_v2(id=\"123456\")\nprint(deleteOrderRes)\n\ndeleteOrderRes = client.delete_order_by_client_order_id_v2(id=\"123456\")\nprint(deleteOrderRes)\n\nopenOrdersRes = client.open_orders_v2(token='USDT')\nprint(openOrdersRes)\n\ndeleteOrdersRes = client.delete_open_orders_v2(symbol=\"BTC-USDC,ETH-USDC\", token='USDT')\nprint(deleteOrdersRes)\n\nhistoryOrdersRes = client.history_orders_v2(token='USDT')\nprint(historyOrdersRes)\n\ngetOrderRes = client.get_order_v2(id=\"123456\")\nprint(getOrderRes)\n\ngetOrderRes = client.get_order_by_client_order_id_v2(id=\"123456\")\nprint(getOrderRes)\n\nfundingRes = client.funding_v2(limit=100,page=0,symbol=\"BTC-USDC\",side=\"BUY\",token='USDT')\nprint(fundingRes)\n\nnotifyListRes = client.notify_list(limit=100,page=0,unreadOnly=\"true\",notifyCategory=\"1\")\nprint(notifyListRes)\n\nmarkNotifyReadRes = client.mark_notify_read(ids=\"113123,123123123\")\nprint(markNotifyReadRes)\n\nhistoricalPnlRes = client.historical_pnl_v2(limit=100,page=0,beginTimeInclusive=1651406864000,endTimeExclusive=1657105971171,symbol=\"BTC-USDC\")\nprint(historicalPnlRes)\n\nyesterdayPnlRes = client.yesterday_pnl_v2(token='USDT')\nprint(yesterdayPnlRes)\n\nhistoryValueRes = client.history_value_v2(token='USDT')\nprint(historyValueRes)\n\nmarkAllNotifyReadRes = client.mark_all_notify_read()\nprint(markAllNotifyReadRes)\n\nsetInitialMarginRateRes = client.set_initial_margin_rate_v2(symbol=\"BTC-USDC\",initialMarginRate=\"0.1\",token='USDT')\nprint(setInitialMarginRateRes)\n\n```\n\n### Stark key sign method\nThe V2 version supports both USDT and USDC Account. Users need to request the configs_v2() and get_account_v2() interface to obtain the configuration of Account.\n\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,\n                          stark_public_key=public_key,\n                          stark_private_key=private_key,\n                          stark_public_key_y_coordinate=public_key_y_coordinate,\n                          api_key_credentials={'key': key, 'secret': secret, 'passphrase': passphrase})\nconfigs = client.configs_v2()\nclient.get_user()\nprint(client.get_account_v2())\n\nprint(client.get_account_balance_v2())\n\ncurrentTime = time.time()\n\n#feeRes = client.uncommon_withdraw_fee_v2(amount='2',chainId='5', token='USDT',)\n#print(feeRes)\n#fastWithdrawRes = client.fast_withdrawal_v2(amount='2',expirationEpochSeconds= currentTime,asset='USDT',fee=feeRes['data']['fee'])\n\n#createWithdrawRes = client.create_withdrawal_v2(amount='1',expirationEpochSeconds= currentTime,asset='USDT')\n#print(createWithdrawRes)\n\nhistoryOrdersRes = client.history_orders_v2(token=\"USDT\")\nprint(historyOrdersRes)\n\norderFills = client.order_fills_v2(orderId='498441108374684453')\nprint(orderFills)\n\nlimitFeeRate = '0.0005'\n\ndeleteOrdersRes = client.delete_open_orders_v2(token=\"USDT\")\nprint(deleteOrdersRes)\n\n\ncreateOrderRes = client.create_order_v2(symbol=\"BTC-USDT\", side=\"SELL\",\n                                        type=\"LIMIT\", size=\"0.01\",expirationEpochSeconds= currentTime,\n                                        price=\"36890\", limitFeeRate=limitFeeRate, timeInForce=\"POST_ONLY\")\n\n#print(createOrderRes)\n\nfillsRes = client.fills_v2(limit=100,page=0,symbol=\"BTC-USDT\",token=\"USDT\")\nprint(fillsRes)\n\n\nopenOrderRes = client.open_orders_v2(token='USDT')\nprint(openOrderRes)\n\n\ndeleteOrdersRes = client.delete_open_orders_v2(token=\"USDT\")\nprint(deleteOrdersRes)\n\nhistoryOrdersRes = client.history_orders_v2(token=\"USDT\")\nprint(historyOrdersRes)\n\nopenOrderRes = client.open_orders_v2(token='USDT')\nprint(openOrderRes)\n\nfeeRes = client.uncommon_withdraw_fee_v2(amount='2',chainId='97', token='USDT')\nprint(feeRes)\ncrossWithdrawRes = client.cross_chain_withdraw_v2(amount='2',expirationEpochSeconds= currentTime,asset='USDT',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\n\n## Old Basic Usage V1\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.2.0",
    "project_urls": {
        "Homepage": "https://github.com/xxx"
    },
    "split_keywords": [
        "apexpro",
        "api",
        "connector"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db0944be6896563cc3600abb4114f4ce25af3e5030c2e9615bda5437d08564b2",
                "md5": "f16b62ebe69b5ec28620177b9c717dd7",
                "sha256": "7ed87f3ff8ccf21029d29329b2ef4c687b5b302449b5fc65473e0c738c8e8d84"
            },
            "downloads": -1,
            "filename": "apexpro-1.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f16b62ebe69b5ec28620177b9c717dd7",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 148424,
            "upload_time": "2024-04-15T03:46:02",
            "upload_time_iso_8601": "2024-04-15T03:46:02.287088Z",
            "url": "https://files.pythonhosted.org/packages/db/09/44be6896563cc3600abb4114f4ce25af3e5030c2e9615bda5437d08564b2/apexpro-1.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c939adb4d1427f85eb5f2144acf38672590d57a5eef39354bb3d80e4188e608b",
                "md5": "c93598e209484bb8b6271c56ea07002b",
                "sha256": "d91ddf64e68416a83cc971bfabd0c2b767c81914d3ab7021a2293120554c692a"
            },
            "downloads": -1,
            "filename": "apexpro-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c93598e209484bb8b6271c56ea07002b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 94867,
            "upload_time": "2024-04-15T03:46:04",
            "upload_time_iso_8601": "2024-04-15T03:46:04.719783Z",
            "url": "https://files.pythonhosted.org/packages/c9/39/adb4d1427f85eb5f2144acf38672590d57a5eef39354bb3d80e4188e608b/apexpro-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-15 03:46:04",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "apexpro"
}
        
Elapsed time: 0.23077s