Exemplo n.º 1
0
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
Exemplo n.º 2
0
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"]
Exemplo n.º 3
0
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>"
Exemplo n.º 4
0
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"]
Exemplo n.º 5
0
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>"
Exemplo n.º 6
0
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"]
Exemplo n.º 7
0
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"]
Exemplo n.º 8
0
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"]
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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"]
Exemplo n.º 12
0
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"]
Exemplo n.º 13
0
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
Exemplo n.º 14
0
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"]
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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