async def cancel_order( exchange: str, txid: str = Query(..., title="ID of Order to cancel"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.cancel_order(txid=txid) return response
async def get_open_orders( exchange: str, trades: bool = Query(None, title="Wether to include trades in output"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_open_orders(trades=trades, retries=retries) return response["data"]
async def get_spread(exchange: str, pair: str = Query(..., title="Dash Separated Pair", maxlength=8), since: int = Query(None, title="Return data since given timestamp"), retries: int = Query(None, title="Number of times to retry the request if it fails") ): api = rest_api_map[exchange]() response = await api.get_spread_as_pandas(pair=[pair], since=since, retries=retries) html_table = response["data"].to_html() return f"{html_table}<br><p>last : {response['last']}</p>"
async def get_spread( exchange: str, pair: str = Query(..., title="Dash Separated Pair", maxlength=8), since: int = Query(None, title="Return data since given timestamp"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_spread(pair=[pair], since=since, retries=retries) return response["data"]
async def get_orderbook(exchange: str, pair: str = Query(..., title="Dash Separated Pair", maxlength=8), count: int = Query(None, title="Maximum number of asks/bids to return"), retries: int = Query(None, title="Number of times to retry the request if it fails") ): api = rest_api_map[exchange]() response = await api.get_orderbook_as_pandas(pair=[pair], count=count, retries=retries) html_asks_table = response["asks"].to_html() html_bids_table = response["bids"].to_html() return f"<table><tr><td><h3>asks</h3>{html_asks_table}</td><td><h3>bids</h3>{html_bids_table}</td></tr></table>"
async def get_trade_balance( exchange: str, asset: str = Query(None, title="Base Asset used to determine balance", maxlength=4), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_trade_balance(asset=asset, retries=retries) return response["data"]
async def get_positions( exchange: str, txid: List[int] = Query(None, title="List of transaction ids to query"), show_pnl: bool = Query(None, title="Show profit and loss of positions"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_open_positions(txid=txid, show_pnl=show_pnl, retries=retries) return response["data"]
async def get_ohlc( exchange: str, pair: str = Query(..., title="Dash Separated Pair", maxlength=8), timeframe: int = Query(..., title="OHLC Candle Interval in minutes"), since: int = Query(None, title="Return data since given timestamp"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_ohlc(pair=[pair], timeframe=timeframe, since=since, retries=retries) return response["data"]
async def get_trade_balance( exchange: str, asset: str = Query(None, title="Base Asset used to determine balance", maxlength=4), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_trade_balance_as_pandas(asset=asset, retries=retries) df = pd.DataFrame.from_dict(response) return df.to_html()
async def get_orderbook( exchange: str, pair: str = Query(..., title="Dash Separated Pair", maxlength=8), count: int = Query(None, title="Maximum number of asks/bids to return"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_orderbook(pair=[pair], count=count, retries=retries) # asks_table_json = response["asks"].to_json(orient="table") # bids_table_json = response["bids"].to_json(orient="table") # return {"asks": asks_table_json, "bids": bids_table_json} return response
async def get_user_trades( exchange: str, trade_type: str = Query(None, title="Type of trade"), trades: bool = Query(None, title="Wether to include trades in output"), start: int = Query(None, title="Start Unix Timestamp"), end: int = Query(None, title="End Unix Timestamp"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_user_trades(trade_type=trade_type, trades=trades, start=start, end=end, retries=retries) return response["data"]
async def get_ticker(exchange: str, pair: List[str] = Query(..., title="Dash Separated Pair", maxlength=8)): api = rest_api_map[exchange]() response = await api.get_ticker(pair=pair) return response["data"]
async def get_websocket_auth_token( exchange: str, validity: int = Query( None, title="Number of minutes the returned token will be valid")): api = rest_api_map[exchange]() response = await api.get_websocket_auth_token(validity=validity) return response
async def get_closed_orders( exchange: str, trades: bool = Query(None, title="Wether to include trades in output"), start: int = Query(None, title="Start Unix Timestamp"), end: int = Query(None, title="End Unix Timestamp"), closetime: str = Query( None, title="Which time to use (candle close, open or both)"), retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() response = await api.get_closed_orders(trades=trades, start=start, end=end, closetime=closetime, retries=retries) return response["data"]
async def get_ticker(exchange: str, pair: List[str] = Query(..., title="Dash Separated Pair", maxlength=8) ): api = rest_api_map[exchange]() response = await api.get_ticker_as_pandas(pair=pair) html_table = response.to_html() return html_table
async def cancel_all_orders( exchange: str, retries: int = Query( None, title="Number of times to retry the request if it fails")): api = rest_api_map[exchange]() # open_orders = api.get_open_orders() # response = await api.cancel_order(txid=txid) # return response pass
async def place_order( exchange: str, pair: str = Query(..., title="Dash Separated Pair"), side: str = Query(..., title="Direction of the trade (buy or sell)"), ordertype: str = Query(..., title="Market/Limit/Stop Loss/Take Profit"), price: float = Query(None, title="Price - Leave empty if order type is market"), volume: float = Query(..., title="Volume of Order in lots"), price2: float = Query( None, title= "2nd Price - Depends on ordertype - Usually used for stops/take profits" ), leverage: float = Query(None, title="Leverage Used"), validate: bool = Query( None, title="Only validate Order Input, without actually placing the order"), retries: int = Query( None, title="Number of times to retry the request if it fails"), start_time: int = Query(None, title="Start Time"), expire_time: int = Query(None, title="Expire Time")): api = rest_api_map[exchange]() # no price = market order => we set order price to last close to calculate slippage later if not price: price = await api.get_ticker_as_pandas([pair]) price = float(price[pair.upper(), "close"][0]) response = await api.place_order(pair=[pair], side=side, ordertype=ordertype, price=price, volume=volume, price2=price2, leverage=leverage, validate=validate) return response