get open orders

This commit is contained in:
2026-04-23 16:34:47 +00:00
parent ff209603b6
commit 73c9ed67f5
2 changed files with 98 additions and 70 deletions

166
main.py
View File

@@ -61,6 +61,92 @@ EXTEND_OPEN_ORDERS = []
### FLAGS ###
LIQUIDATE_POS_AND_KILL_ALGO_FLAG: bool = False
### OPEN ORDERS ###
async def get_aster_open_orders():
global ASTER_OPEN_ORDERS
fut_acct_openOrders = {
"url": "/fapi/v3/openOrders",
"method": "GET",
"params": {}
}
ASTER_OPEN_ORDERS = aster_auth.post_authenticated_url(fut_acct_openOrders)
async def get_extend_open_orders():
global EXTEND_OPEN_ORDERS
EXTEND_OPEN_ORDERS = list(dict(await EXTEND_CLIENT.account.get_open_orders()).get('data', 0))
### WALLLET ###
async def get_aster_collateral():
global ASTER_AVAIL_COLLATERAL
fut_acct_balances = {
"url": "/fapi/v3/balance",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_balances)
ASTER_AVAIL_COLLATERAL = float([d for d in r if d.get('asset')==ASTER_RH_ASSET][0].get('availableBalance'))
async def get_aster_notional_position():
global ASTER_NOTIONAL_POSITION
global ASTER_MULT
fut_acct_positionRisk = {
"url": "/fapi/v3/positionRisk",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_positionRisk)
d = [d for d in r if d.get('symbol', None) == ASTER_TICKER][0]
ASTER_NOTIONAL_POSITION = float(d.get('notional' ,0))
ASTER_MULT = float(d.get('leverage', ASTER_MULT))
async def get_extend_collateral():
global EXTEND_AVAIL_COLLATERAL
get_bals = dict(dict(await EXTEND_CLIENT.account.get_balance()).get('data', {}))
EXTEND_AVAIL_COLLATERAL = get_bals.get('available_for_trade', 0) if get_bals.get('collateral_name', None)==EXTEND_RH_ASSET else 0
async def get_extend_notional():
global EXTEND_NOTIONAL_POSITION
global EXTEND_MULT
get_pos = dict(await EXTEND_CLIENT.account.get_positions()).get('data', {})
pos_dict = [d for d in get_pos if d.get('market') == EXTEND_TICKER]
if pos_dict:
pos_dict = pos_dict[0]
EXTEND_NOTIONAL_POSITION = pos_dict.get('value', 0)
EXTEND_MULT = pos_dict.get('leverage', EXTEND_MULT)
else:
EXTEND_NOTIONAL_POSITION = 0
### EXCHANGE INFO ###
async def get_aster_exch_info():
global ASTER_MIN_ORDER_QTY
fut_acct_exchangeInfo = {
"url": "/fapi/v3/exchangeInfo",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_exchangeInfo)
s = r['symbols']
d = [d for d in s if d.get('symbol', None) == 'ETHUSDT'][0]
f = [f for f in d['filters'] if f.get('filterType', None) == 'LOT_SIZE'][0]
ASTER_MIN_ORDER_QTY = float(f['minQty'])
async def get_extend_exch_info():
global EXTEND_MIN_ORDER_QTY
r = await EXTEND_CLIENT.markets_info.get_markets_dict()
EXTEND_MIN_ORDER_QTY = float(r['ETH-USD'].trading_config.min_order_size)
### ROUTES ###
async def aster_remainder_route():
# Check open orders...cancel replace or new order?
# Check collateral to confirm you have enough money to trade
@@ -69,12 +155,13 @@ async def aster_remainder_route():
# if good to order, then create and post order. ADD to LOCAL OPEN ORDERS LIST
pass
async def extend_remainder_route():
pass
### ALGO LOOP ###
async def run_algo():
try:
while True:
@@ -158,6 +245,8 @@ async def run_algo():
### SCAN VALKEY USER FEEDS FOR BALANCE UPDATES ###
# or just to begin hit the rest API before ordering and update bals then
### SCAN VALKEY USER FEEDS FOR ORDER UPDATES ###
### ROUTES ###
if ASTER_TGT_TAIL_ORDERABLE:
@@ -167,7 +256,6 @@ async def run_algo():
await extend_remainder_route()
print(f'__________ End ___________ (Algo Engine ms: {(time.time() - loop_start)*1000})')
time.sleep(5)
@@ -179,73 +267,8 @@ async def run_algo():
logging.error(traceback.format_exc())
# await cancel_all_orders(CLIENT=CLIENT)
### WALLLET ###
async def get_aster_collateral():
global ASTER_AVAIL_COLLATERAL
fut_acct_balances = {
"url": "/fapi/v3/balance",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_balances)
ASTER_AVAIL_COLLATERAL = float([d for d in r if d.get('asset')==ASTER_RH_ASSET][0].get('availableBalance'))
async def get_aster_notional_position():
global ASTER_NOTIONAL_POSITION
global ASTER_MULT
fut_acct_positionRisk = {
"url": "/fapi/v3/positionRisk",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_positionRisk)
d = [d for d in r if d.get('symbol', None) == ASTER_TICKER][0]
ASTER_NOTIONAL_POSITION = float(d.get('notional' ,0))
ASTER_MULT = float(d.get('leverage', ASTER_MULT))
async def get_extend_collateral():
global EXTEND_AVAIL_COLLATERAL
get_bals = dict(dict(await EXTEND_CLIENT.account.get_balance()).get('data', {}))
EXTEND_AVAIL_COLLATERAL = get_bals.get('available_for_trade', 0) if get_bals.get('collateral_name', None)==EXTEND_RH_ASSET else 0
async def get_extend_notional():
global EXTEND_NOTIONAL_POSITION
global EXTEND_MULT
get_pos = dict(await EXTEND_CLIENT.account.get_positions()).get('data', {})
pos_dict = [d for d in get_pos if d.get('market') == EXTEND_TICKER]
if pos_dict:
pos_dict = pos_dict[0]
EXTEND_NOTIONAL_POSITION = pos_dict.get('value', 0)
EXTEND_MULT = pos_dict.get('leverage', EXTEND_MULT)
else:
EXTEND_NOTIONAL_POSITION = 0
### EXCHANGE INFO ###
async def get_aster_exch_info():
global ASTER_MIN_ORDER_QTY
fut_acct_exchangeInfo = {
"url": "/fapi/v3/exchangeInfo",
"method": "GET",
"params": {}
}
r = aster_auth.post_authenticated_url(fut_acct_exchangeInfo)
s = r['symbols']
d = [d for d in s if d.get('symbol', None) == 'ETHUSDT'][0]
f = [f for f in d['filters'] if f.get('filterType', None) == 'LOT_SIZE'][0]
ASTER_MIN_ORDER_QTY = float(f['minQty'])
async def get_extend_exch_info():
global EXTEND_MIN_ORDER_QTY
r = await EXTEND_CLIENT.markets_info.get_markets_dict()
EXTEND_MIN_ORDER_QTY = float(r['ETH-USD'].trading_config.min_order_size)
### MAIN STARTUP ###
async def main():
global EXTEND_CLIENT
global VAL_KEY
@@ -256,11 +279,16 @@ async def main():
engine = create_async_engine('mysql+asyncmy://root:pwd@localhost/fund_rate')
async with engine.connect() as CON:
# await create_executions_orders_table(CON=CON)
### ASTER SETUP ###
await get_aster_collateral()
await get_aster_notional_position()
await get_aster_exch_info()
await get_aster_open_orders()
### EXTEND SETUP ###
await get_extend_collateral()
await get_extend_notional()
await get_extend_exch_info()
await get_extend_open_orders()
await run_algo()

View File

@@ -17,7 +17,7 @@ async def create_fr_aster_user_order_trade_table(
CREATE TABLE IF NOT EXISTS fr_aster_user_order_trade (
timestamp_arrival BIGINT,
timestamp_msg BIGINT,
timestamp_value BIGINT,
timestamp_transaction BIGINT,
symbol VARCHAR(20),
client_order_id VARCHAR(100),
side VARCHAR(20),