Esempio n. 1
0
def get_orders(status: str) -> Tuple[List[OrderType], Any]:
    query_str = """
        query($status: GetOrdersStatus!) {
          getOrders(status: $status) {
          dynamicPriceExpiry
            orders {
              edges {
                node {
                  id
                  cryptocurrency
                  coinAmount
                  side
                  status
                  createdAt
                  pricePerCoin
                  priceType
                  staticPrice
                  dynamicExchangeRate
                }
              }
            }
          }
        }
    """
    variables = dict(status=status)
    result = execute_query(query_str, variables)
    _res = result["getOrders"]

    orders = []
    for o in _res["orders"]["edges"]:
        orders.append(_make_order(o["node"]))
    return orders, _res["dynamicPriceExpiry"]
Esempio n. 2
0
def get_market_book():
    query_str = """
        query {
          getMarketBook {
            dynamicPriceExpiry
            orders {
              edges {
                node {
                  id
                  cryptocurrency
                  coinAmount
                  side
                  status 
                  createdAt
                  pricePerCoin
                  priceType
                  staticPrice
                  dynamicExchangeRate
                }
              }
            }
          }
        }    
    """
    result = execute_query(query_str)
    _res = result["getMarketBook"]

    orders = []
    for o in _res["orders"]["edges"]:
        orders.append(_make_order(o["node"]))
    return orders, _res["dynamicPriceExpiry"]
def send(*, cryptocurrency: str, amount: float,
         address: str) -> SendReturnValueType:
    query_str = """
        mutation($crypto: String!, $amount: Number!, $address: String!) {
          send(cryptocurrency: $crypto, amount: $amount, address: $address) {
            id
            address
            amount
            cryptocurrency
            fee
            status
            transaction {
              txhash
              id
            }
          }
        }    
    """
    variables = dict(crypto=cryptocurrency, amount=amount, address=address)
    res = execute_query(query_str, variables)
    send_val = res["send"]
    return SendReturnValueType(
        id=send_val["id"],
        address=send_val["address"],
        amount=Decimal(send_val["amount"]),
        cryptocurrency=send_val["cryptocurrency"],
        fee=Decimal(send_val["fee"]),
        status=send_val["status"],
        transaction=TransactionType(
            id=send_val["transaction"]["id"],
            hash=send_val["transaction"]["txhash"],
        ),
    )
def create_address(cryptocurrency: str):
    query_str = """
        mutation($crypto: Cryptocurrency) {
          createAddress(cryptocurrency: $crypto) {
            cryptocurrency
            address
          }
        }
    """
    variables = dict(crypto=cryptocurrency)
    res = execute_query(query_str, variables)
    res = res["createAddress"]
    return AddressType(cryptocurrency=res["cryptocurrency"],
                       address=res["address"])
def estimate_network_fee(cryptocurrency: str, amount: float) -> NetworkFeeType:
    query_str = """
        query($crypto: Cryptocurrency, $amount: BigDecimal!) {
          getEstimatedNetworkFee(cryptocurrency: $crypto, amount: $amount) {
            estimatedFee
            total
          }
        }
    """
    variables = dict(crypto=cryptocurrency, amount=amount)
    res = execute_query(query_str, variables)
    fee = res["getEstimatedNetworkFee"]

    return NetworkFeeType(estimated_fee=Decimal(fee["estimatedFee"]),
                          total=Decimal(fee["total"]))
Esempio n. 6
0
def place_market_order(*, side: str, coin_amount: float, cryptocurrency: str):
    query_str = """
        mutation($side: OrderSide!, $amount: BigDecimal!, $crypto: Cryptocurrency) {
          postMarketOrder(orderSide: $side, coinAmount: $amount, cryptocurrency: $crypto){
            id
            cryptocurrency
            coinAmount
            side
            status 
            createdAt
            pricePerCoin
            priceType
            staticPrice
            dynamicExchangeRate
          }
        }
    """
    variables = dict(side=side, amount=coin_amount, crypto=cryptocurrency)
    result = execute_query(query_str, variables)
    return _make_order(result["postMarketOrder"])
def get_balances() -> List[CoinBalanceType]:
    query_str = """
        query {
          getBalances{
            id
            cryptocurrency
            confirmedBalance
          }
        }
    """
    result = execute_query(query_str)
    balances = []
    for bal in result["getBalances"]:
        balances.append(
            CoinBalanceType(
                id=bal["id"],
                cryptocurrency=bal["cryptocurrency"],
                confirmed_balance=Decimal(bal["confirmedBalance"]),
            ))
    return balances
Esempio n. 8
0
def create_deposit(account_name: str) -> VirtualDepositAccountType:
    query_str = """
        mutation($name: String!) {
          createDepositAccount(accountName: $name) {
            accountNumber
            accountName
            accountType
            bankName
            accountReference
         }
       }
    """

    result = execute_query(query_str, dict(name=account_name))
    account = result["createDepositAccount"]
    return VirtualDepositAccountType(
        account["accountNumber"],
        account["accountName"],
        account["accountType"],
        account["bankName"],
        account["accountReference"],
    )
Esempio n. 9
0
def place_limit_order(
    *,
    side: str,
    coin_amount: float,
    cryptocurrency: str,
    price_type: str,
    static_price: float = None,
    dynamic_exchange_rate: float = None,
):
    query_str = """
        mutation($side: OrderSide!, $amount: BigDecimal!, $crypto: Cryptocurrency, $type_: PriceType!, 
                 $static_price: BigDecimal!, $dynamic_exchange_rate: BigDecimal) {
          postLimitOrder(orderSide: $side, coinAmount: $amount, cryptocurrency: $crypto, %s, priceType: $type_){
            id
            cryptocurrency
            coinAmount
            side
            status 
            createdAt
            pricePerCoin
            priceType
            staticPrice
            dynamicExchangeRate
          }
        }    
    """ % (("staticPrice: $static_price" if price_type == "static" else
            "dynamicExchangeRate: $dynamic_exchange_rate"))

    variables = dict(
        side=side,
        amount=coin_amount,
        crypto=cryptocurrency,
        type_=price_type,
        static_price=static_price,
        dynamic_exchange_rate=dynamic_exchange_rate,
    )
    result = execute_query(query_str, variables)
    return _make_order(result["postLimitOrder"])