feedhandlers extended
This commit is contained in:
147
modules/aster_db.py
Normal file
147
modules/aster_db.py
Normal file
@@ -0,0 +1,147 @@
|
||||
import logging
|
||||
from typing import AsyncContextManager
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
### Orders and Trades Tables ####
|
||||
async def create_fr_aster_user_order_trade_table(
|
||||
CON: AsyncContextManager,
|
||||
engine: str = 'mysql', # mysql | duckdb
|
||||
) -> None:
|
||||
if CON is None:
|
||||
logging.info("NO DB CONNECTION, SKIPPING Create Statements")
|
||||
else:
|
||||
if engine == 'mysql':
|
||||
logging.info('Creating Table if Does Not Exist: fr_aster_user_order_trade')
|
||||
await CON.execute(text("""
|
||||
CREATE TABLE IF NOT EXISTS fr_aster_user_order_trade (
|
||||
timestamp_arrival BIGINT,
|
||||
timestamp_msg BIGINT,
|
||||
timestamp_value BIGINT,
|
||||
symbol VARCHAR(20),
|
||||
client_order_id VARCHAR(100),
|
||||
side VARCHAR(20),
|
||||
order_type VARCHAR(100),
|
||||
time_in_force VARCHAR(20),
|
||||
original_qty DOUBLE,
|
||||
original_price DOUBLE,
|
||||
avg_price DOUBLE,
|
||||
stop_price DOUBLE,
|
||||
execution_type VARCHAR(100),
|
||||
order_status VARCHAR(100),
|
||||
order_id BIGINT,
|
||||
last_filled_qty DOUBLE,
|
||||
filled_accumulated_qty DOUBLE,
|
||||
last_filled_price DOUBLE,
|
||||
commission_asset VARCHAR(20),
|
||||
commission DOUBLE,
|
||||
order_trade_time_ts BIGINT,
|
||||
trade_id VARCHAR(100),
|
||||
bid_notional DOUBLE,
|
||||
ask_notional DOUBLE,
|
||||
trade_is_maker BOOL,
|
||||
trade_is_reduce_only BOOL,
|
||||
stop_px_working_type VARCHAR(100),
|
||||
original_order_type VARCHAR(100),
|
||||
position_side VARCHAR(100),
|
||||
pushed_w_conditional_order BOOL,
|
||||
activation_price DOUBLE,
|
||||
callback_rate DOUBLE,
|
||||
realized_profit DOUBLE
|
||||
);
|
||||
"""))
|
||||
await CON.commit()
|
||||
else:
|
||||
raise ValueError('Only MySQL engine is implemented')
|
||||
|
||||
### Margin Calls Table ####
|
||||
async def create_fr_aster_user_margin_table(
|
||||
CON: AsyncContextManager,
|
||||
engine: str = 'mysql', # mysql | duckdb
|
||||
) -> None:
|
||||
if CON is None:
|
||||
logging.info("NO DB CONNECTION, SKIPPING Create Statements")
|
||||
else:
|
||||
if engine == 'mysql':
|
||||
logging.info('Creating Table if Does Not Exist: fr_aster_user_margin')
|
||||
await CON.execute(text("""
|
||||
CREATE TABLE IF NOT EXISTS fr_aster_user_margin (
|
||||
timestamp_arrival BIGINT,
|
||||
timestamp_msg BIGINT,
|
||||
cross_wallet_balance DOUBLE,
|
||||
symbol VARCHAR(20),
|
||||
position_side VARCHAR(20),
|
||||
position_amount DOUBLE,
|
||||
margin_type VARCHAR(20),
|
||||
isolated_wallet DOUBLE,
|
||||
mark_price DOUBLE,
|
||||
unrealized_pnl DOUBLE,
|
||||
maint_margin_required DOUBLE
|
||||
);
|
||||
"""))
|
||||
await CON.commit()
|
||||
else:
|
||||
raise ValueError('Only MySQL engine is implemented')
|
||||
|
||||
### Account Balance Table ####
|
||||
async def create_fr_aster_user_account_bal(
|
||||
CON: AsyncContextManager,
|
||||
engine: str = 'mysql', # mysql | duckdb
|
||||
) -> None:
|
||||
if CON is None:
|
||||
logging.info("NO DB CONNECTION, SKIPPING Create Statements")
|
||||
else:
|
||||
if engine == 'mysql':
|
||||
logging.info('Creating Table if Does Not Exist: fr_aster_user_account_bal')
|
||||
await CON.execute(text("""
|
||||
CREATE TABLE IF NOT EXISTS fr_aster_user_account_bal (
|
||||
timestamp_arrival BIGINT,
|
||||
timestamp_msg BIGINT,
|
||||
timestamp_transaction BIGINT,
|
||||
event_reason_type VARCHAR(20),
|
||||
asset VARCHAR(20),
|
||||
wallet_balance DOUBLE,
|
||||
cross_wallet_balance DOUBLE,
|
||||
balance_change_excl_pnl_comms DOUBLE
|
||||
);
|
||||
"""))
|
||||
await CON.commit()
|
||||
else:
|
||||
raise ValueError('Only MySQL engine is implemented')
|
||||
|
||||
### Account Positions Table ####
|
||||
async def create_fr_aster_user_account_pos(
|
||||
CON: AsyncContextManager,
|
||||
engine: str = 'mysql', # mysql | duckdb
|
||||
) -> None:
|
||||
if CON is None:
|
||||
logging.info("NO DB CONNECTION, SKIPPING Create Statements")
|
||||
else:
|
||||
if engine == 'mysql':
|
||||
logging.info('Creating Table if Does Not Exist: fr_aster_user_account_pos')
|
||||
await CON.execute(text("""
|
||||
CREATE TABLE IF NOT EXISTS fr_aster_user_account_pos (
|
||||
timestamp_arrival BIGINT,
|
||||
timestamp_msg BIGINT,
|
||||
timestamp_transaction BIGINT,
|
||||
event_reason_type VARCHAR(20),
|
||||
symbol VARCHAR(20),
|
||||
position_amount DOUBLE,
|
||||
entry_price DOUBLE,
|
||||
accumulated_realized_pre_fees DOUBLE,
|
||||
unrealized_pnl DOUBLE,
|
||||
margin_type VARCHAR(20),
|
||||
isolated_wallet DOUBLE,
|
||||
position_side VARCHAR(20)
|
||||
);
|
||||
"""))
|
||||
await CON.commit()
|
||||
else:
|
||||
raise ValueError('Only MySQL engine is implemented')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user