tanx-connector


Nametanx-connector JSON
Version 2.1.0 PyPI version JSON
download
home_pageNone
SummaryThe official Python connector for Tanx's API
upload_time2024-06-28 11:11:28
maintainerNone
docs_urlNone
authortanX
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Tanx Fi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords tanx connector finance api wrapper python
VCS
bugtrack_url
requirements requests web3 ecdsa websockets sympy typing-extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">tanX Connector Python</h1>

<p align="center">
  The official Python connector for <a href="https://docs.tanx.fi/tech/api-documentation">tanX's API</a> 🚀
</p>

<!-- <div align="center">

  [![npm version](https://img.shields.io/npm/v/@tanx-fi/tanx-connector)](https://www.npmjs.org/package/@tanx-fi/tanx-connector)
  [![Build status](https://img.shields.io/github/actions/workflow/status/tanx-Libs/tanx-connector-nodejs/main.yml)](https://github.com/tanX-Finance-Libs/tanX-connector-nodejs/actions/workflows/main.yml)
  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@tanx-fi/tanx-connector)](https://bundlephobia.com/package/@tanx-fi/tanx-connector@latest)

</div> -->


## Features

- Complete endpoints including REST and WebSockets
- Methods return parsed JSON.
- High level abstraction for ease of use.
- Easy authentication
- Automatically sets JWT token internally
- Auto refresh tokens when access token expires

Tanx-connector-python includes utility/connector functions which can be used to interact with the Tanx API. It uses requests internally to handle all requests.

## Table of Contents

- [Features](#features)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [Getting Started](#getting-started)
  - [Workflow](#workflow)
  - [L2 Key Pair](#l2-key-pair)
  - [Rest Client](#rest-client)
  - [General Endpoints](#general-endpoints)
    - [Test Connectivity](#test-connectivity)
    - [24hr Price](#24hr-price)
    - [Kline/Candlestick Data](#klinecandlestick-data)
    - [Order Book](#order-book)
    - [Recent trades](#recent-trades)
    - [Login](#login)
    - [Refresh Token](#refersh-token)
    - [Logout](#logout)
    - [Profile Information (Private 🔒)](#profile-information-private-)
    - [Balance details (Private 🔒)](#balance-details-private-)
    - [Profit and Loss Details (Private 🔒)](#profit-and-loss-details-private-)
    - [Create order (Private 🔒)](#create-order-private-)
    - [Get Order (Private 🔒)](#get-order-private-)
    - [List Orders (Private 🔒)](#list-orders-)
    - [Cancel Order (Private 🔒)](#cancel-order-private-)
    - [Bulk Cancel (Private 🔒)](#bulk-cancel-private-)
    - [List Trades (Private 🔒)](#list-trades-private-)
  - [WebSocket Client](#websocket-client)
    - [Connect](#connect)
    - [Subscribe](#subscribe)
    - [Unsubscribe](#unsubscribe)
    - [Disconnect](#disconnect)
    - [Usage](#usage)
  - [Error Handling](#error-handling)
  - [Deposit](#deposit)
    - [Ethereum Network Deposit](#ethereum-network-deposit)
    - [Polygon Network Deposit](#polygon-network-deposit)
    - [Cross Network Deposit](#cross-network-deposit)
    - [List Deposits](#list-deposits)
  - [Withdrawal](#withdrawal)
    - [Normal Withdrawal](#normal-withdrawal-only-for-ethereum-network)
    - [Fast Withdrawal](#fast-withdrawal)
  - [Internal Transfer](#internal-transfer)
    - [Available Methods](#available-methods)

## Installation

First go to the [tanX Website](https://www.tanx.fi/) and create an account with your wallet.

Install the package using pip.

```python
pip install tanx-connector
```

## Quickstart

Make sure that tanxconnector is [installed](#installation) and up-to-date.
Also make sure you have an account on the [mainnet](https://trade.tanx.fi/) or [testnet](https://testnet.tanx.fi/) website.

To get quickly started, try running the simple example for creating and fetching the order once logged in.
For the `stark_private_key`, kindly see the [L2 Key Pair](#l2-key-pair) section of the documentation.

```python
from tanxconnector import Client

ETH_ADDRESS = "(your eth wallet address)"
ETH_WALLET_PRIVATE_KEY = "(your wallet's private key)"
STARK_PRIVATE_KEY = "(stark private key from the L2 Key Pair)"

client = Client()

# login to the network
login = client.complete_login(ETH_ADDRESS, PRIVATE_KEY)

# create an order nonce
nonce: CreateOrderNonceBody = {'market': 'ethusdc', 'ord_type':'market', 'price': 29580.51, 'side': 'sell', 'volume': 0.0005}

# create the order
order = client.create_complete_order(nonce, STARK_PRIVATE_KEY)
print(order)

# fetch the details of the order just created
order_id = order['payload']['id']
fetch_order = client.get_order(order_id)
print(fetch_order)
```

## Getting Started

The default base url for mainnet is https://api.tanx.fi and testnet is https://api-testnet.tanx.fi. You can choose between mainnet and testnet by providing it through the constructor. The default is mainnet. All REST apis, WebSockets are handled by Client, WsClient classes respectively.

### Workflow

Check out the [example files](./example) to see an example workflow.

### L2 Key Pair

L2 Key Pair generation isn't currently available in the TanX Python SDK. 

To get the L2 Key Pair, follow any of the two steps:

1. Get the Key Pair from the [TanX official website](https://trade.tanx.fi/)'s Account Settings Tab once wallet is connected. Refer to the image below for more reference. Click on `Settings -> tanX key -> Show Keys` and Sign the request to get the keys. Copy these keys and store it securely.
<img src="https://raw.githubusercontent.com/tanx-libs/tanx-connector-python/main/images/tanx-key.png">

2. Generate the L2 key pair using the [TanX Nodejs SDK](https://github.com/tanx-libs/tanx-connector-nodejs). For generation using the Node SDK, refer to [this section](https://github.com/tanx-libs/tanx-connector-nodejs#create-l2-key-pair) in the documentation of the Nodejs SDK.

### Rest Client

Import the REST Client

```py
from tanxconnector import Client
```

Create a new instance

```python
client = Client()
# or
client = Client('testnet')
# default is mainnet, can pass explicitly as well
```

### General Endpoints

#### Test connectivity

`GET /sapi/v1/health/`

```python
client.test_connection()
```

#### 24hr Price

`GET /sapi/v1/market/tickers/`

```python
client.get_24h_price('btcusdt')
```

#### Kline/Candlestick Data

`GET /sapi/v1/market/kline/`

```python
client.get_candlestick('btcusdt')
```

#### Order Book

`GET /sapi/v1/market/orderbook/`

```python
client.get_orderbook('btcusdt')
```

#### Recent trades

`GET /sapi/v1/market/trades/`

```python
client.get_recent_trades('btcusdt')
```

#### Login

Both login() and complete_Login() sets tokens internally. Optionally, set_access_token() and set_refresh_token() can be used to set tokens directly.

getNonce: `POST /sapi/v1/auth/nonce/`  
login: `POST /sapi/v1/auth/login/`

```python
from tanxconnector import sign_msg, Client

client = Client()

client.complete_login(ETH_ADDRESS, PRIVATE_KEY)  
# calls below functions internally, use this for ease

# or

nonce = client.get_nonce(ETH_ADDRESS)
user_signature = sign_msg(nonce['payload'], PRIVATE_KEY)
login = client.login(ETH_ADDRESS, user_signature)

# or

client.set_access_token(access_token)
client.set_refresh_token(refresh_token)
# these functions are called internally when you use login or complete_login
```

#### Refresh Token

`POST /sapi/v1/auth/token/refresh/`

If refresh token is set (manually or by using login functions), the refresh endpoint is called automatically when access token expires. Optionally, you can call `refresh_tokens` manually by passing in refresh_token (passing it is optional, it'll work if has been set before).

```python
res = client.refresh_tokens(refresh_token)
```

#### Logout

Sets tokens to null

```python
client.logout()
```

#### Profile Information (Private 🔒)

`GET /sapi/v1/user/profile/`

```python
client.get_profile_info()
```

#### Balance details (Private 🔒)

`GET /sapi/v1/user/balance/`

```python
client.get_balance()
```

#### Profit and Loss Details (Private 🔒)

`GET /sapi/v1/user/pnl/`

```python
client.get_profit_and_loss()
```

#### Create order (Private 🔒)

Order is created in 2 steps:

1. Create the order nonce body
2. Process the order nonce body with the stark private key to create the order

Create Nonce Body

```py
from tanxconnector.typings import CreateOrderNonceBody
nonce: CreateOrderNonceBody = {'market': 'btcusdt', 'ord_type': 'market',
                               'price': 29580.51, 'side': 'buy', 'volume': 0.0001}
```

Stop Limit Order

```py
from tanxconnector.typings import CreateOrderNonceBody
nonce: CreateOrderNonceBody = {'market': 'btcusdt', 'ord_type': 'stop_limit',
                               'stop_price':29800,'price': 29580.51, 'side': 'buy', 'volume': 0.0001}
```

Create Order

create_order_nonce: `POST /sapi/v1/orders/nonce/`  
create_new_order: `POST /sapi/v1/orders/create/`

For getting the L2 Key Pairs (Stark Keys) refer to the above [section](#l2-key-pair) in the documentation.

```python
stark_private_key = '(Your Stark Private Key Here)'

order = client.create_complete_order(nonce, stark_private_key)
# calls below functions internally, we recommend using createCompleteOrder for ease of use

# or

from tanxconnector import sign_order_with_stark_private_key

nonce_res = client.create_order_nonce(nonce)
msg_hash = sign_order_with_stark_private_key(stark_private_key, nonce_res['payload'])
order = client.create_new_order(msg_hash)
```

#### Get Order (Private 🔒)

`GET /sapi/v1/orders/{order_id}/`

```python
client.get_order(order_id)
```

#### List Orders (Private 🔒)

`GET /sapi/v1/orders/`

```python
client.list_orders(
  limit=50,
  page=1,
  market='btcusdc',
  state='wait',
  base_unit='btc',
  quote_unit='usdc',
  start_time=1694785739,
  end_time=1694785839,
  side='buy'
)
```

#### Cancel Order (Private 🔒)

`POST /sapi/v1/orders/cancel/`

```python
client.cancel_order(order_id)
```

#### Bulk Cancel (Private 🔒)

`POST /sapi/v1/user/bulkcancel/`

```python
client.bulk_cancel(market,limit)
```


#### List Trades (Private 🔒)

`GET /sapi/v1/trades/`

```python
client.list_trades()
```

### WebSocket Client

Import the WebSocket Client. All WsClient methods are asynchronous (use async/await method).

```py
from tanxconnector import WsClient
import asyncio
```

Create a new instance

```python
ws_client = WsClient('public')
// or
ws_client = WsClient('public', 'mainnet')
// default is mainnet
// or
login = client.complete_login(ETH_ADDRESS, PRIVATE_KEY)
ws_client =  WsClient('private', 'mainnet', login['token']['access'])
```

#### Connect

```py
await ws_client.connect()
```

#### Subscribe

```py
streams = [
  'btcusdc.trades',
  'btcusdc.ob-inc',
  'btcusdc.kline-5m',
]
await ws_client.subscribe(streams)

# or for private

await ws_client.subscribe(['trade', 'order'])
```

#### Unsubscribe

```py
streams = [
  'btcusdc.trades',
  'btcusdc.ob-inc',
  'btcusdc.kline-5m',
]
await ws_client.unsubscribe(streams)

# or for private

await ws_client.unsubscribe(['trade', 'order'])
```

#### Disconnect

```py
ws_client.disconnect()
```

#### Usage

WsClient includes a member called websocket which is initialized with websockets.connect(). You may use it to handle WebSocket operations.

```py
async for message in ws_client.websocket:
    print(message)
```

### Error Handling

Errors thrown are of types `AuthenticationError or requests.exceptions.HTTPError`.  

Example

```py
try:
    # call methods
except tanxconnector.exception.AuthenticationError as exc:
    print(exc)
except requests.exceptions.HTTPError as exc:
    print(exc.response.json())
```

### Deposit

#### Ethereum Network Deposit

This method involves using a custom provider and signer, which can be created using the web3.py library. The `stark_public_key` mentioned in the code should be obtained using the steps described in the [L2 Key Pair](#l2-key-pair) section of the documentation. Here's the code snippet for this method:

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER))
signer = Account.from_key(PRIVATE_KEY)

deposit_res_with_stark_keys = client.deposit_from_ethereum_network_with_stark_key(
  signer,
  provider,
  f'0x{stark_public_key}',
  0.0001,
  'eth'
)
```

For any `ERC20` token (which is not native for the network, like usdc), first allow unlimited allowance for that token using the `approve_unlimited_allowance_ethereum_network` method.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER))
signer = Account.from_key(PRIVATE_KEY)

# approval for unlimited allowance for ERC20 contracts
allowance = client.approve_unlimited_allowance_ethereum_network('usdc', signer, provider)
print(allowance) # prints the hash for the allowance transaction, check this on the etherscan/sepoliascan for success.
```

Once the allowance is success, transactions can be made for `ERC20` token on ETH network.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER))
signer = Account.from_key(PRIVATE_KEY)

deposit_res_with_stark_keys = client.deposit_from_ethereum_network_with_stark_key(
  signer,
  provider,
  f'0x{stark_public_key}',
  0.0001,
  'usdc'
)
```

#### Polygon Network Deposit

There are two ways to make a deposit on the Polygon network:

1. Using ETH Private Key and RPC URL:<br>
In this method, you will use an ETH private key and an RPC URL to execute a Polygon deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:

```python
deposit_res = client.deposit_from_polygon_network(
  RPC_PROVIDER_FOR_POLYGON, # Use 'Polygon Mumbai' for the testnet and 'Polygon mainnet' for the mainnet.
  PRIVATE_KEY,  # ETH Private Key
  'matic',  # Coin Symbol
  0.00001 # Amount to be deposited
)
```

2. Using Custom Provider and Signer:
<br>This method involves using a custom provider and signer, which can be created using the web3.py library. Also, its important to inject a middleware at the 0th layer of the middleware onion for the provider ([See Reference](https://web3py.readthedocs.io/en/stable/middleware.html#proof-of-authority)). Here's the code snippet for this method:

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

polygon_deposit_res = client.deposit_from_polygon_network_with_signer(
  signer, # Signer Created above
  provider, # Provider created above
  'matic',  # Enter the coin symbol
  0.0001, # Amount to be deposited
)
```

For any `ERC20` token (which is not native for the network, like btc), first allow unlimited allowance for that token using the `approve_unlimited_allowance_polygon_network` method.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

# approval for unlimited allowance for ERC20 contracts
allowance = client.approve_unlimited_allowance_polygon_network(coin='btc', signer=signer, w3=provider)
print(allowance)  # prints the hash for the allowance, check on polygon scan for success
```

Once the allowance is success, transactions can be made for `ERC20` token on POLYGON network.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

polygon_deposit_res = client.deposit_from_polygon_network_with_signer(
  signer, # Signer Created above
  provider, # Provider created above
  'btc',  # Enter the coin symbol
  0.0001, # Amount to be deposited
)
```

#### Cross Network Deposit

There are two ways to make a deposit on the Cross network:

1. Using ETH Private Key and RPC URL:<br>
In this method, you will use an ETH private key and an RPC URL to execute a Cross chain/network deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:

```python
deposit_res = client.deposit_from_cross_network(
  RPC_PROVIDER_FOR_NETWORK, # use different RPC for TEST_NET and MAIN_NET 
  PRIVATE_KEY,  # ETH Private Key
  'matic',  # Coin Symbol
  0.00001 # Amount to be deposited
  'optimism' # Network name
)
```

2. Using Custom Provider and Signer:
<br>This method involves using a custom provider and signer, which can be created using the web3.py library. Also, its important to inject a middleware at the 0th layer of the middleware onion for the provider ([See Reference](https://web3py.readthedocs.io/en/stable/middleware.html#proof-of-authority)). Here's the code snippet for this method:

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

deposit_res = client.deposit_from_cross_network_with_signer(
  signer, # Signer Created above
  provider, # Provider created above
  'matic',  # Enter the coin symbol
  0.0001, # Amount to be deposited
  'optimism' # Network name
)
```

For any `ERC20` token (which is not native for the network, like btc), first allow unlimited allowance for that token using the `set_allowance()` method.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

# approval for unlimited allowance for ERC20 contracts
allowance = client.set_allowance(coin='btc', signer=signer, w3=provider, network='ETHEREUM')
print(allowance)  # prints the hash for the allowance, check on network scan for success
```

Once the allowance is success, transactions can be made for `ERC20` token on the network.

```python
# Note: Please use web3>=6.0.0, <7.0.0
from web3 import Web3, Account
from web3.middleware.geth_poa import geth_poa_middleware

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))
provider.middleware_onion.inject(geth_poa_middleware, layer=0)

signer = Account.from_key(PRIVATE_KEY)

deposit_res = client.deposit_from_cross_network_with_signer(
  signer, # Signer Created above
  provider, # Provider created above
  'btc',  # Enter the coin symbol
  0.0001, # Amount to be deposited
  'optimism' # Network name
)
```


#### List Deposits

To get the deposit history, you can use the following code:

```python
deposit_list = client.list_deposits({
  'page': 1,  # This field is optional
  'limit': 1, # This field is optional
  'network': 'ETHEREUM' # Network for which you want to list the deposit history.
})
```

### Withdrawal

Generally, we have two modes of withdrawal: Normal Withdrawal and Fast Withdrawal. For withdrawal methods that require a signer and provider, please refer to the deposit method mentioned above.

#### Normal Withdrawal (Only for ETHEREUM Network)

With Normal Withdrawal, your requested funds will be processed within a standard time frame (24 hours). This mode is suitable for users who are not in a rush to access their funds and are comfortable with the regular processing time. The `stark keys (L2 Key Pair)` can be generated with the help of [this section](#l2-key-pair) of the documentation.

```python
from web3 import Web3, Account

provider = Web3(Web3.HTTPProvider(RPC_PROVIDER))
signer = Account.from_key(PRIVATE_KEY)
gas_price = provider.eth.gas_price # or any custom value

key_pair = {
  'stark_public_key': stark_public_key,
  'stark_private_key': stark_private_key
}

# Withdrawals

# Normal withdrawal:
# 1. Initiate your withdrawal request by calling the "initiateNormalWithdrawal" function.
withdrawal_res = client.initiate_normal_withdrawal(
  key_pair, # The keyPair created for stark keys
  0.0001, # Enter the amount you want to deposit
  'usdc', # Enter the coin symbol
)
# 2. WAIT for up to 24 hours.
# 3. Check whether the withdrawn balance is pending by calling the "getPendingNormalWithdrawalAmountByCoin" function with the required parameters.
pending_balance = client.get_pending_normal_withdrawal_amount_by_coin(
  'eth', # Enter the coin symbol
  eth_address, # User public eth address
  signer, # The signer created above
  provider, # The provider created above
)
# 4. In the final step, if you find the balance is more than 0, you can use the "completeNormalWithdrawal" function to withdraw the cumulative amount to your ETH wallet.
complete_normal_withdrawal_res = client.complete_normal_withdrawal(
  'eth', # Enter the coin symbol
  ethAddress, # User public eth address
  signer, # The signer created above
  provider, # The provider created above
  gas_price, # max gas price for the transaction
)

#Get a list of withdrawals
withdrawals_list = client.list_normal_withdrawals({
  page: 2, # This is an optional field
})
```

#### Fast Withdrawal

With Fast Withdrawal, your funds will be processed in an expedited timeframe, often within a few minutes. This mode is ideal for users who require immediate access to their funds and are comfortable with paying a fee. The `stark keys (L2 Key Pair)` can be generated with the help of [this section](#l2-key-pair) of the documentation.

1. Ethereum Network

```python
key_pair = {
  'stark_public_key': stark_public_key,
  'stark_private_key': stark_private_key
}

fast_withdrawal_res = client.fast_withdrawal(
  key_pair, # The keyPair created above
  0.0001, # Enter the amount you want to deposit
  'usdc', # Enter the coin symbol
  'ETHEREUM', # Enter Network name
)
```

3. Get a list of fast withdrawals
```python
fast_withdrawals_list = client.list_fast_withdrawals({
  'page': 2, # This is an optional field
  'network': 'POLYGON'  # This is an optional field
})
```

### Internal Transfer

Users will be able to seamlessly transfer assets from their CEXs or other chains with minimal fees.

To get started with the feature, follow these two steps:

1. Reach out to tanX (support@tanx.fi) to get the organization key and API key.

2. Generate the L2 key pair with your private key

#### Available methods:

1. To process the internal transfer, call the `initiate_and_process_internal_transfers` method and pass the necessary arguments:

```python
key_pair = {
  'stark_public_key': '(your stark public key here)'
  'stark_private_key': '(your stark private key here)'
}

ETH_ADDRESS_2 = '(destination Eth wallet address here)'

internal_transfer_response = client.initiate_and_process_internal_transfers(
  key_pair=key_pair,
  organization_key=TANX_ORGANIZATION_KEY,
  api_key=TANX_API_KEY,
  currency='usdc',
  amount=1,
  destination_address=ETH_ADDRESS_2,
  client_reference_id=1
)
```

2. Retrieve a list of transfers initiated by the authenticated user:

```python
internal_transfer_list = client.list_internal_transfers({
  'limit': 10,
  'offset': 10
})
```

3. Retrieve an internal transfer using its client reference id:

```python
internal_transfer_by_id = client.get_internal_transfer_by_client_id(client_reference_id)
```

4. Check if a user exists by their destination address.

```python
check_user_res = client.check_internal_transfer_user_exists(
  TANX_ORGANIZATION_KEY,
  TANX_API_KEY,
  destination_address,
)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tanx-connector",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "tanx, connector, finance, api, wrapper, python",
    "author": "tanX",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/03/fc/81742e4b4bded0f587bd7836c802b95a358fe84636b53114ecda21ce3eda/tanx_connector-2.1.0.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">tanX Connector Python</h1>\n\n<p align=\"center\">\n  The official Python connector for <a href=\"https://docs.tanx.fi/tech/api-documentation\">tanX's API</a> \ud83d\ude80\n</p>\n\n<!-- <div align=\"center\">\n\n  [![npm version](https://img.shields.io/npm/v/@tanx-fi/tanx-connector)](https://www.npmjs.org/package/@tanx-fi/tanx-connector)\n  [![Build status](https://img.shields.io/github/actions/workflow/status/tanx-Libs/tanx-connector-nodejs/main.yml)](https://github.com/tanX-Finance-Libs/tanX-connector-nodejs/actions/workflows/main.yml)\n  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@tanx-fi/tanx-connector)](https://bundlephobia.com/package/@tanx-fi/tanx-connector@latest)\n\n</div> -->\n\n\n## Features\n\n- Complete endpoints including REST and WebSockets\n- Methods return parsed JSON.\n- High level abstraction for ease of use.\n- Easy authentication\n- Automatically sets JWT token internally\n- Auto refresh tokens when access token expires\n\nTanx-connector-python includes utility/connector functions which can be used to interact with the Tanx API. It uses requests internally to handle all requests.\n\n## Table of Contents\n\n- [Features](#features)\n- [Table of Contents](#table-of-contents)\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Getting Started](#getting-started)\n  - [Workflow](#workflow)\n  - [L2 Key Pair](#l2-key-pair)\n  - [Rest Client](#rest-client)\n  - [General Endpoints](#general-endpoints)\n    - [Test Connectivity](#test-connectivity)\n    - [24hr Price](#24hr-price)\n    - [Kline/Candlestick Data](#klinecandlestick-data)\n    - [Order Book](#order-book)\n    - [Recent trades](#recent-trades)\n    - [Login](#login)\n    - [Refresh Token](#refersh-token)\n    - [Logout](#logout)\n    - [Profile Information (Private \ud83d\udd12)](#profile-information-private-)\n    - [Balance details (Private \ud83d\udd12)](#balance-details-private-)\n    - [Profit and Loss Details (Private \ud83d\udd12)](#profit-and-loss-details-private-)\n    - [Create order (Private \ud83d\udd12)](#create-order-private-)\n    - [Get Order (Private \ud83d\udd12)](#get-order-private-)\n    - [List Orders (Private \ud83d\udd12)](#list-orders-)\n    - [Cancel Order (Private \ud83d\udd12)](#cancel-order-private-)\n    - [Bulk Cancel (Private \ud83d\udd12)](#bulk-cancel-private-)\n    - [List Trades (Private \ud83d\udd12)](#list-trades-private-)\n  - [WebSocket Client](#websocket-client)\n    - [Connect](#connect)\n    - [Subscribe](#subscribe)\n    - [Unsubscribe](#unsubscribe)\n    - [Disconnect](#disconnect)\n    - [Usage](#usage)\n  - [Error Handling](#error-handling)\n  - [Deposit](#deposit)\n    - [Ethereum Network Deposit](#ethereum-network-deposit)\n    - [Polygon Network Deposit](#polygon-network-deposit)\n    - [Cross Network Deposit](#cross-network-deposit)\n    - [List Deposits](#list-deposits)\n  - [Withdrawal](#withdrawal)\n    - [Normal Withdrawal](#normal-withdrawal-only-for-ethereum-network)\n    - [Fast Withdrawal](#fast-withdrawal)\n  - [Internal Transfer](#internal-transfer)\n    - [Available Methods](#available-methods)\n\n## Installation\n\nFirst go to the [tanX Website](https://www.tanx.fi/) and create an account with your wallet.\n\nInstall the package using pip.\n\n```python\npip install tanx-connector\n```\n\n## Quickstart\n\nMake sure that tanxconnector is [installed](#installation) and up-to-date.\nAlso make sure you have an account on the [mainnet](https://trade.tanx.fi/) or [testnet](https://testnet.tanx.fi/) website.\n\nTo get quickly started, try running the simple example for creating and fetching the order once logged in.\nFor the `stark_private_key`, kindly see the [L2 Key Pair](#l2-key-pair) section of the documentation.\n\n```python\nfrom tanxconnector import Client\n\nETH_ADDRESS = \"(your eth wallet address)\"\nETH_WALLET_PRIVATE_KEY = \"(your wallet's private key)\"\nSTARK_PRIVATE_KEY = \"(stark private key from the L2 Key Pair)\"\n\nclient = Client()\n\n# login to the network\nlogin = client.complete_login(ETH_ADDRESS, PRIVATE_KEY)\n\n# create an order nonce\nnonce: CreateOrderNonceBody = {'market': 'ethusdc', 'ord_type':'market', 'price': 29580.51, 'side': 'sell', 'volume': 0.0005}\n\n# create the order\norder = client.create_complete_order(nonce, STARK_PRIVATE_KEY)\nprint(order)\n\n# fetch the details of the order just created\norder_id = order['payload']['id']\nfetch_order = client.get_order(order_id)\nprint(fetch_order)\n```\n\n## Getting Started\n\nThe default base url for mainnet is https://api.tanx.fi and testnet is https://api-testnet.tanx.fi. You can choose between mainnet and testnet by providing it through the constructor. The default is mainnet. All REST apis, WebSockets are handled by Client, WsClient classes respectively.\n\n### Workflow\n\nCheck out the [example files](./example) to see an example workflow.\n\n### L2 Key Pair\n\nL2 Key Pair generation isn't currently available in the TanX Python SDK. \n\nTo get the L2 Key Pair, follow any of the two steps:\n\n1. Get the Key Pair from the [TanX official website](https://trade.tanx.fi/)'s Account Settings Tab once wallet is connected. Refer to the image below for more reference. Click on `Settings -> tanX key -> Show Keys` and Sign the request to get the keys. Copy these keys and store it securely.\n<img src=\"https://raw.githubusercontent.com/tanx-libs/tanx-connector-python/main/images/tanx-key.png\">\n\n2. Generate the L2 key pair using the [TanX Nodejs SDK](https://github.com/tanx-libs/tanx-connector-nodejs). For generation using the Node SDK, refer to [this section](https://github.com/tanx-libs/tanx-connector-nodejs#create-l2-key-pair) in the documentation of the Nodejs SDK.\n\n### Rest Client\n\nImport the REST Client\n\n```py\nfrom tanxconnector import Client\n```\n\nCreate a new instance\n\n```python\nclient = Client()\n# or\nclient = Client('testnet')\n# default is mainnet, can pass explicitly as well\n```\n\n### General Endpoints\n\n#### Test connectivity\n\n`GET /sapi/v1/health/`\n\n```python\nclient.test_connection()\n```\n\n#### 24hr Price\n\n`GET /sapi/v1/market/tickers/`\n\n```python\nclient.get_24h_price('btcusdt')\n```\n\n#### Kline/Candlestick Data\n\n`GET /sapi/v1/market/kline/`\n\n```python\nclient.get_candlestick('btcusdt')\n```\n\n#### Order Book\n\n`GET /sapi/v1/market/orderbook/`\n\n```python\nclient.get_orderbook('btcusdt')\n```\n\n#### Recent trades\n\n`GET /sapi/v1/market/trades/`\n\n```python\nclient.get_recent_trades('btcusdt')\n```\n\n#### Login\n\nBoth login() and complete_Login() sets tokens internally. Optionally, set_access_token() and set_refresh_token() can be used to set tokens directly.\n\ngetNonce: `POST /sapi/v1/auth/nonce/`  \nlogin: `POST /sapi/v1/auth/login/`\n\n```python\nfrom tanxconnector import sign_msg, Client\n\nclient = Client()\n\nclient.complete_login(ETH_ADDRESS, PRIVATE_KEY)  \n# calls below functions internally, use this for ease\n\n# or\n\nnonce = client.get_nonce(ETH_ADDRESS)\nuser_signature = sign_msg(nonce['payload'], PRIVATE_KEY)\nlogin = client.login(ETH_ADDRESS, user_signature)\n\n# or\n\nclient.set_access_token(access_token)\nclient.set_refresh_token(refresh_token)\n# these functions are called internally when you use login or complete_login\n```\n\n#### Refresh Token\n\n`POST /sapi/v1/auth/token/refresh/`\n\nIf refresh token is set (manually or by using login functions), the refresh endpoint is called automatically when access token expires. Optionally, you can call `refresh_tokens` manually by passing in refresh_token (passing it is optional, it'll work if has been set before).\n\n```python\nres = client.refresh_tokens(refresh_token)\n```\n\n#### Logout\n\nSets tokens to null\n\n```python\nclient.logout()\n```\n\n#### Profile Information (Private \ud83d\udd12)\n\n`GET /sapi/v1/user/profile/`\n\n```python\nclient.get_profile_info()\n```\n\n#### Balance details (Private \ud83d\udd12)\n\n`GET /sapi/v1/user/balance/`\n\n```python\nclient.get_balance()\n```\n\n#### Profit and Loss Details (Private \ud83d\udd12)\n\n`GET /sapi/v1/user/pnl/`\n\n```python\nclient.get_profit_and_loss()\n```\n\n#### Create order (Private \ud83d\udd12)\n\nOrder is created in 2 steps:\n\n1. Create the order nonce body\n2. Process the order nonce body with the stark private key to create the order\n\nCreate Nonce Body\n\n```py\nfrom tanxconnector.typings import CreateOrderNonceBody\nnonce: CreateOrderNonceBody = {'market': 'btcusdt', 'ord_type': 'market',\n                               'price': 29580.51, 'side': 'buy', 'volume': 0.0001}\n```\n\nStop Limit Order\n\n```py\nfrom tanxconnector.typings import CreateOrderNonceBody\nnonce: CreateOrderNonceBody = {'market': 'btcusdt', 'ord_type': 'stop_limit',\n                               'stop_price':29800,'price': 29580.51, 'side': 'buy', 'volume': 0.0001}\n```\n\nCreate Order\n\ncreate_order_nonce: `POST /sapi/v1/orders/nonce/`  \ncreate_new_order: `POST /sapi/v1/orders/create/`\n\nFor getting the L2 Key Pairs (Stark Keys) refer to the above [section](#l2-key-pair) in the documentation.\n\n```python\nstark_private_key = '(Your Stark Private Key Here)'\n\norder = client.create_complete_order(nonce, stark_private_key)\n# calls below functions internally, we recommend using createCompleteOrder for ease of use\n\n# or\n\nfrom tanxconnector import sign_order_with_stark_private_key\n\nnonce_res = client.create_order_nonce(nonce)\nmsg_hash = sign_order_with_stark_private_key(stark_private_key, nonce_res['payload'])\norder = client.create_new_order(msg_hash)\n```\n\n#### Get Order (Private \ud83d\udd12)\n\n`GET /sapi/v1/orders/{order_id}/`\n\n```python\nclient.get_order(order_id)\n```\n\n#### List Orders (Private \ud83d\udd12)\n\n`GET /sapi/v1/orders/`\n\n```python\nclient.list_orders(\n  limit=50,\n  page=1,\n  market='btcusdc',\n  state='wait',\n  base_unit='btc',\n  quote_unit='usdc',\n  start_time=1694785739,\n  end_time=1694785839,\n  side='buy'\n)\n```\n\n#### Cancel Order (Private \ud83d\udd12)\n\n`POST /sapi/v1/orders/cancel/`\n\n```python\nclient.cancel_order(order_id)\n```\n\n#### Bulk Cancel (Private \ud83d\udd12)\n\n`POST /sapi/v1/user/bulkcancel/`\n\n```python\nclient.bulk_cancel(market,limit)\n```\n\n\n#### List Trades (Private \ud83d\udd12)\n\n`GET /sapi/v1/trades/`\n\n```python\nclient.list_trades()\n```\n\n### WebSocket Client\n\nImport the WebSocket Client. All WsClient methods are asynchronous (use async/await method).\n\n```py\nfrom tanxconnector import WsClient\nimport asyncio\n```\n\nCreate a new instance\n\n```python\nws_client = WsClient('public')\n// or\nws_client = WsClient('public', 'mainnet')\n// default is mainnet\n// or\nlogin = client.complete_login(ETH_ADDRESS, PRIVATE_KEY)\nws_client =  WsClient('private', 'mainnet', login['token']['access'])\n```\n\n#### Connect\n\n```py\nawait ws_client.connect()\n```\n\n#### Subscribe\n\n```py\nstreams = [\n  'btcusdc.trades',\n  'btcusdc.ob-inc',\n  'btcusdc.kline-5m',\n]\nawait ws_client.subscribe(streams)\n\n# or for private\n\nawait ws_client.subscribe(['trade', 'order'])\n```\n\n#### Unsubscribe\n\n```py\nstreams = [\n  'btcusdc.trades',\n  'btcusdc.ob-inc',\n  'btcusdc.kline-5m',\n]\nawait ws_client.unsubscribe(streams)\n\n# or for private\n\nawait ws_client.unsubscribe(['trade', 'order'])\n```\n\n#### Disconnect\n\n```py\nws_client.disconnect()\n```\n\n#### Usage\n\nWsClient includes a member called websocket which is initialized with websockets.connect(). You may use it to handle WebSocket operations.\n\n```py\nasync for message in ws_client.websocket:\n    print(message)\n```\n\n### Error Handling\n\nErrors thrown are of types `AuthenticationError or requests.exceptions.HTTPError`.  \n\nExample\n\n```py\ntry:\n    # call methods\nexcept tanxconnector.exception.AuthenticationError as exc:\n    print(exc)\nexcept requests.exceptions.HTTPError as exc:\n    print(exc.response.json())\n```\n\n### Deposit\n\n#### Ethereum Network Deposit\n\nThis method involves using a custom provider and signer, which can be created using the web3.py library. The `stark_public_key` mentioned in the code should be obtained using the steps described in the [L2 Key Pair](#l2-key-pair) section of the documentation. Here's the code snippet for this method:\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER))\nsigner = Account.from_key(PRIVATE_KEY)\n\ndeposit_res_with_stark_keys = client.deposit_from_ethereum_network_with_stark_key(\n  signer,\n  provider,\n  f'0x{stark_public_key}',\n  0.0001,\n  'eth'\n)\n```\n\nFor any `ERC20` token (which is not native for the network, like usdc), first allow unlimited allowance for that token using the `approve_unlimited_allowance_ethereum_network` method.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER))\nsigner = Account.from_key(PRIVATE_KEY)\n\n# approval for unlimited allowance for ERC20 contracts\nallowance = client.approve_unlimited_allowance_ethereum_network('usdc', signer, provider)\nprint(allowance) # prints the hash for the allowance transaction, check this on the etherscan/sepoliascan for success.\n```\n\nOnce the allowance is success, transactions can be made for `ERC20` token on ETH network.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER))\nsigner = Account.from_key(PRIVATE_KEY)\n\ndeposit_res_with_stark_keys = client.deposit_from_ethereum_network_with_stark_key(\n  signer,\n  provider,\n  f'0x{stark_public_key}',\n  0.0001,\n  'usdc'\n)\n```\n\n#### Polygon Network Deposit\n\nThere are two ways to make a deposit on the Polygon network:\n\n1. Using ETH Private Key and RPC URL:<br>\nIn this method, you will use an ETH private key and an RPC URL to execute a Polygon deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:\n\n```python\ndeposit_res = client.deposit_from_polygon_network(\n  RPC_PROVIDER_FOR_POLYGON, # Use 'Polygon Mumbai' for the testnet and 'Polygon mainnet' for the mainnet.\n  PRIVATE_KEY,  # ETH Private Key\n  'matic',  # Coin Symbol\n  0.00001 # Amount to be deposited\n)\n```\n\n2. Using Custom Provider and Signer:\n<br>This method involves using a custom provider and signer, which can be created using the web3.py library. Also, its important to inject a middleware at the 0th layer of the middleware onion for the provider ([See Reference](https://web3py.readthedocs.io/en/stable/middleware.html#proof-of-authority)). Here's the code snippet for this method:\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\npolygon_deposit_res = client.deposit_from_polygon_network_with_signer(\n  signer, # Signer Created above\n  provider, # Provider created above\n  'matic',  # Enter the coin symbol\n  0.0001, # Amount to be deposited\n)\n```\n\nFor any `ERC20` token (which is not native for the network, like btc), first allow unlimited allowance for that token using the `approve_unlimited_allowance_polygon_network` method.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\n# approval for unlimited allowance for ERC20 contracts\nallowance = client.approve_unlimited_allowance_polygon_network(coin='btc', signer=signer, w3=provider)\nprint(allowance)  # prints the hash for the allowance, check on polygon scan for success\n```\n\nOnce the allowance is success, transactions can be made for `ERC20` token on POLYGON network.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_POLYGON))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\npolygon_deposit_res = client.deposit_from_polygon_network_with_signer(\n  signer, # Signer Created above\n  provider, # Provider created above\n  'btc',  # Enter the coin symbol\n  0.0001, # Amount to be deposited\n)\n```\n\n#### Cross Network Deposit\n\nThere are two ways to make a deposit on the Cross network:\n\n1. Using ETH Private Key and RPC URL:<br>\nIn this method, you will use an ETH private key and an RPC URL to execute a Cross chain/network deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:\n\n```python\ndeposit_res = client.deposit_from_cross_network(\n  RPC_PROVIDER_FOR_NETWORK, # use different RPC for TEST_NET and MAIN_NET \n  PRIVATE_KEY,  # ETH Private Key\n  'matic',  # Coin Symbol\n  0.00001 # Amount to be deposited\n  'optimism' # Network name\n)\n```\n\n2. Using Custom Provider and Signer:\n<br>This method involves using a custom provider and signer, which can be created using the web3.py library. Also, its important to inject a middleware at the 0th layer of the middleware onion for the provider ([See Reference](https://web3py.readthedocs.io/en/stable/middleware.html#proof-of-authority)). Here's the code snippet for this method:\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\ndeposit_res = client.deposit_from_cross_network_with_signer(\n  signer, # Signer Created above\n  provider, # Provider created above\n  'matic',  # Enter the coin symbol\n  0.0001, # Amount to be deposited\n  'optimism' # Network name\n)\n```\n\nFor any `ERC20` token (which is not native for the network, like btc), first allow unlimited allowance for that token using the `set_allowance()` method.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\n# approval for unlimited allowance for ERC20 contracts\nallowance = client.set_allowance(coin='btc', signer=signer, w3=provider, network='ETHEREUM')\nprint(allowance)  # prints the hash for the allowance, check on network scan for success\n```\n\nOnce the allowance is success, transactions can be made for `ERC20` token on the network.\n\n```python\n# Note: Please use web3>=6.0.0, <7.0.0\nfrom web3 import Web3, Account\nfrom web3.middleware.geth_poa import geth_poa_middleware\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER_FOR_NETWORK))\nprovider.middleware_onion.inject(geth_poa_middleware, layer=0)\n\nsigner = Account.from_key(PRIVATE_KEY)\n\ndeposit_res = client.deposit_from_cross_network_with_signer(\n  signer, # Signer Created above\n  provider, # Provider created above\n  'btc',  # Enter the coin symbol\n  0.0001, # Amount to be deposited\n  'optimism' # Network name\n)\n```\n\n\n#### List Deposits\n\nTo get the deposit history, you can use the following code:\n\n```python\ndeposit_list = client.list_deposits({\n  'page': 1,  # This field is optional\n  'limit': 1, # This field is optional\n  'network': 'ETHEREUM' # Network for which you want to list the deposit history.\n})\n```\n\n### Withdrawal\n\nGenerally, we have two modes of withdrawal: Normal Withdrawal and Fast Withdrawal. For withdrawal methods that require a signer and provider, please refer to the deposit method mentioned above.\n\n#### Normal Withdrawal (Only for ETHEREUM Network)\n\nWith Normal Withdrawal, your requested funds will be processed within a standard time frame (24 hours). This mode is suitable for users who are not in a rush to access their funds and are comfortable with the regular processing time. The `stark keys (L2 Key Pair)` can be generated with the help of [this section](#l2-key-pair) of the documentation.\n\n```python\nfrom web3 import Web3, Account\n\nprovider = Web3(Web3.HTTPProvider(RPC_PROVIDER))\nsigner = Account.from_key(PRIVATE_KEY)\ngas_price = provider.eth.gas_price # or any custom value\n\nkey_pair = {\n  'stark_public_key': stark_public_key,\n  'stark_private_key': stark_private_key\n}\n\n# Withdrawals\n\n# Normal withdrawal:\n# 1. Initiate your withdrawal request by calling the \"initiateNormalWithdrawal\" function.\nwithdrawal_res = client.initiate_normal_withdrawal(\n  key_pair, # The keyPair created for stark keys\n  0.0001, # Enter the amount you want to deposit\n  'usdc', # Enter the coin symbol\n)\n# 2. WAIT for up to 24 hours.\n# 3. Check whether the withdrawn balance is pending by calling the \"getPendingNormalWithdrawalAmountByCoin\" function with the required parameters.\npending_balance = client.get_pending_normal_withdrawal_amount_by_coin(\n  'eth', # Enter the coin symbol\n  eth_address, # User public eth address\n  signer, # The signer created above\n  provider, # The provider created above\n)\n# 4. In the final step, if you find the balance is more than 0, you can use the \"completeNormalWithdrawal\" function to withdraw the cumulative amount to your ETH wallet.\ncomplete_normal_withdrawal_res = client.complete_normal_withdrawal(\n  'eth', # Enter the coin symbol\n  ethAddress, # User public eth address\n  signer, # The signer created above\n  provider, # The provider created above\n  gas_price, # max gas price for the transaction\n)\n\n#Get a list of withdrawals\nwithdrawals_list = client.list_normal_withdrawals({\n  page: 2, # This is an optional field\n})\n```\n\n#### Fast Withdrawal\n\nWith Fast Withdrawal, your funds will be processed in an expedited timeframe, often within a few minutes. This mode is ideal for users who require immediate access to their funds and are comfortable with paying a fee. The `stark keys (L2 Key Pair)` can be generated with the help of [this section](#l2-key-pair) of the documentation.\n\n1. Ethereum Network\n\n```python\nkey_pair = {\n  'stark_public_key': stark_public_key,\n  'stark_private_key': stark_private_key\n}\n\nfast_withdrawal_res = client.fast_withdrawal(\n  key_pair, # The keyPair created above\n  0.0001, # Enter the amount you want to deposit\n  'usdc', # Enter the coin symbol\n  'ETHEREUM', # Enter Network name\n)\n```\n\n3. Get a list of fast withdrawals\n```python\nfast_withdrawals_list = client.list_fast_withdrawals({\n  'page': 2, # This is an optional field\n  'network': 'POLYGON'  # This is an optional field\n})\n```\n\n### Internal Transfer\n\nUsers will be able to seamlessly transfer assets from their CEXs or other chains with minimal fees.\n\nTo get started with the feature, follow these two steps:\n\n1. Reach out to tanX (support@tanx.fi) to get the organization key and API key.\n\n2. Generate the L2 key pair with your private key\n\n#### Available methods:\n\n1. To process the internal transfer, call the `initiate_and_process_internal_transfers` method and pass the necessary arguments:\n\n```python\nkey_pair = {\n  'stark_public_key': '(your stark public key here)'\n  'stark_private_key': '(your stark private key here)'\n}\n\nETH_ADDRESS_2 = '(destination Eth wallet address here)'\n\ninternal_transfer_response = client.initiate_and_process_internal_transfers(\n  key_pair=key_pair,\n  organization_key=TANX_ORGANIZATION_KEY,\n  api_key=TANX_API_KEY,\n  currency='usdc',\n  amount=1,\n  destination_address=ETH_ADDRESS_2,\n  client_reference_id=1\n)\n```\n\n2. Retrieve a list of transfers initiated by the authenticated user:\n\n```python\ninternal_transfer_list = client.list_internal_transfers({\n  'limit': 10,\n  'offset': 10\n})\n```\n\n3. Retrieve an internal transfer using its client reference id:\n\n```python\ninternal_transfer_by_id = client.get_internal_transfer_by_client_id(client_reference_id)\n```\n\n4. Check if a user exists by their destination address.\n\n```python\ncheck_user_res = client.check_internal_transfer_user_exists(\n  TANX_ORGANIZATION_KEY,\n  TANX_API_KEY,\n  destination_address,\n)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Tanx Fi  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "The official Python connector for Tanx's API",
    "version": "2.1.0",
    "project_urls": {
        "Homepage": "https://github.com/tanx-libs/tanx-connector-python",
        "Issues": "https://github.com/tanx-libs/tanx-connector-python/issues"
    },
    "split_keywords": [
        "tanx",
        " connector",
        " finance",
        " api",
        " wrapper",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c2f87f758a23bf1e6a400c0962aa2dbdb8c1a6020b61cd25fb6c84b1e0b85d7",
                "md5": "f76d91bb65a5a1bf0ff7b85a55755669",
                "sha256": "8be7ba8a748b4066577e77382ab5a0b591112e279c7ff5105250ec0907aab3b5"
            },
            "downloads": -1,
            "filename": "tanx_connector-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f76d91bb65a5a1bf0ff7b85a55755669",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 73840,
            "upload_time": "2024-06-28T11:11:27",
            "upload_time_iso_8601": "2024-06-28T11:11:27.140493Z",
            "url": "https://files.pythonhosted.org/packages/8c/2f/87f758a23bf1e6a400c0962aa2dbdb8c1a6020b61cd25fb6c84b1e0b85d7/tanx_connector-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03fc81742e4b4bded0f587bd7836c802b95a358fe84636b53114ecda21ce3eda",
                "md5": "283eceefe805944351373cc31fb42b59",
                "sha256": "0ac5e0060e152805bcd6e51f883fe1becad646e2e4624fa839c321532181417e"
            },
            "downloads": -1,
            "filename": "tanx_connector-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "283eceefe805944351373cc31fb42b59",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 82092,
            "upload_time": "2024-06-28T11:11:28",
            "upload_time_iso_8601": "2024-06-28T11:11:28.729108Z",
            "url": "https://files.pythonhosted.org/packages/03/fc/81742e4b4bded0f587bd7836c802b95a358fe84636b53114ecda21ce3eda/tanx_connector-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-28 11:11:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tanx-libs",
    "github_project": "tanx-connector-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "<",
                    "3.0.0"
                ],
                [
                    ">=",
                    "2.22.0"
                ]
            ]
        },
        {
            "name": "web3",
            "specs": [
                [
                    ">=",
                    "6.0.0"
                ],
                [
                    "<",
                    "7.0.0"
                ]
            ]
        },
        {
            "name": "ecdsa",
            "specs": [
                [
                    ">=",
                    "0.16.0"
                ],
                [
                    "<",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "websockets",
            "specs": []
        },
        {
            "name": "sympy",
            "specs": [
                [
                    "==",
                    "1.12"
                ]
            ]
        },
        {
            "name": "typing-extensions",
            "specs": [
                [
                    ">=",
                    "4.3.0"
                ]
            ]
        }
    ],
    "lcname": "tanx-connector"
}
        
Elapsed time: 0.62978s