Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
trivex_frontend/node_modules/
/.pnp
.pnp.js

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ npm install
npm run start
```

## Trivex Smart Contracts

```bash
cd trivex_web
cd trivex_contract
```

## Trivex Titan Bot

```bash
cd trivex_web
cd trivex titan
```

## 🌐 Community & Support

- Website: [https://official-trivex.xyz](https://official-trivex.xyz)
Expand Down
83 changes: 83 additions & 0 deletions titan/titan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from starknet_py.contract import Contract
import asyncio
from starknet_py.net.full_node_client import FullNodeClient
from trader.hyperliquidTrader import hyperliquidTrader
import math

contract_address = "0x05083aa7aba0aa78514ac84d70a7c969360a6095189d2fdfaafcb689b4734d38"

async def get_all_user_addresses(contract):
addresses_result = await contract.functions["get_all_user_addresses"].call()
addresses = addresses_result[0]
hex_addresses = ["0x" + hex(addr)[2:].rjust(64, "0") for addr in addresses]
return hex_addresses

async def get_internal_order_book(contract):
order_book_result = await contract.functions["get_internal_order_book"].call()
order_book_raw = order_book_result[0]

order_book_cleaned = []
for order in order_book_raw:
symbol_int = order['symbol']
try:
symbol_str = bytes.fromhex(hex(symbol_int)[2:]).decode('utf-8').rstrip('\x00')
except:
symbol_str = str(symbol_int)
cleaned_order = {
'symbol': symbol_str,
'leverage': order['leverage'],
'amount': order['amount'] / 1_000_000
}
order_book_cleaned.append(cleaned_order)

return order_book_cleaned

def dynamic_round(num, size):
if num == 0:
return 0
abs_num = abs(num)

if abs_num >= 1:
digits_before_decimal = int(math.log10(abs_num)) + 1
else:
digits_before_decimal = 0
decimal_places = max(1, digits_before_decimal)
return float(round(size, decimal_places))

async def external_hedge(orders):
trader = hyperliquidTrader()
exchange = trader.getExchange()
info = trader.getInfo()
external_balance = info["marginSummary"]["accountValue"]

print(external_balance)

for order in orders:
print("************************************")
print(f"Order — Symbol: {order['symbol']}, Amount: {order['amount']}, Leverage: {order['leverage']}")
symbol = order["symbol"]
price = trader.getCurrentPrice(order["symbol"])
price = float(price)
print(f"{symbol} price: {price}")
amount = order["amount"]
amount = float(amount)
leverage = order['leverage']
size = dynamic_round(price, leverage*amount/price)
print(f"{symbol} size: {size}")
# trader.updateLeverage(exchange, leverage, symbol)
# trader.openOrder(True, symbol, size, exchange)
print("************************************")

async def main():
client = FullNodeClient(node_url="https://starknet-sepolia.public.blastapi.io")
contract = await Contract.from_address(contract_address, client)

addresses = await get_all_user_addresses(contract)
print("User Addresses:", addresses)

order_book = await get_internal_order_book(contract)
print("Internal Order Book:", order_book)

await external_hedge(order_book)

asyncio.run(main())
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.