Skip to content

thiagoamarante/Deadlock.Robinhood

Repository files navigation

Deadlock.Robinhood (1.0.2)

Robinhood Free stock trading. Stop paying up to $10 for every trade.

C# Framework to make trades with the private Robinhood API. Using this API is not encouraged, since it's not officially available.

This framework was inspired by a deprecated Python framework originally developed by @Rohanpai.

Disclaimer: This is an unofficial client package. I'm not affiliated with the folks at Robinhood Markets Inc.

Features

  • Login
  • Get User
  • Get Accounts
  • Get Positions
  • Get Portfolio
  • Get Orders
  • New Order
  • Cancel Order
  • Get Instrument
  • Get Quote
using Deadlock.Robinhood;

static string _token = "";
static string _account = "";
static string _username = "";
static string _password = "";
static string _instrumentTwitter = "https://api.robinhood.com/instruments/3a47ca97-d5a2-4a55-9045-053a588894de/";
static string _orderId = "";

Login with username and password

static async Task Login()
{
    using (RobinhoodClient client = new RobinhoodClient())
    {
        var result = await client.Login(_username, _password);
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(result.Data.Token);
        }
    }
}

Login with token

static async Task LoginWithToken()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Quote("TWTR");
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(result.Data.Symbol);
        }
    }
}

Get user informations

static async Task GetUserInformations()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.User();
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(result.Data.Username);
        }
    }
}

List Accounts

static async Task ListAccounts()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Accounts();
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            result.Data.Results.ForEach(account =>
                Console.WriteLine(account.AccountNumber)
            );
        }
    }
}

List Positions

static async Task ListPositions()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Positions();
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            result.Data.Results.ForEach(position =>
                Console.WriteLine(position.Quantity)
            );
        }
    }
}

Get Portfolio

static async Task GetPortfolio()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var resultPortfolios = await client.Portfolios();
        if (resultPortfolios.StatusCode == System.Net.HttpStatusCode.OK)
        {
            resultPortfolios.Data.Results.ForEach(portfolio =>
                Console.WriteLine(portfolio.MarketValue)
            );
        }

        //by accountNumber
        var resultPortfolio = await client.Portfolios(UrlManager.GetAccountNumber(_account));
        if (resultPortfolio.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(resultPortfolio.Data.MarketValue);
        }
    }
}

List Orders

static async Task ListOrders()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Orders();
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            result.Data.Results.ForEach(order =>
                Console.WriteLine(order.Price)
            );
        }
    }
}

New Order

static async Task NewOrder()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Orders(new Model.NewOrder()
        {
            Account = _account,                 
            Price = 10,
            Quantity = 1,
            Side = Model.Side.Buy,
            TimeInForce = "gfd",
            Trigger = "immediate",
            Type = "market",
            Symbol = "TWTR",
            Instrument = _instrumentTwitter
        });
        if (result.IsSuccessStatusCode)
        {
            _orderId = result.Data.Id;
        }
    }
}

Cancel Order

static async Task CancelOrder()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.CancelOrder(_orderId);
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {

        }
    }
}

Get Instrument

static async Task GetInstrument()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Instrument("3a47ca97-d5a2-4a55-9045-053a588894de"); //twitter
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(result.Data.Name);
        }
    }
}

Get Quote

static async Task GetQuote()
{
    using (RobinhoodClient client = new RobinhoodClient(_token))
    {
        var result = await client.Quote("TWTR");
        if (result.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Console.WriteLine(result.Data.BidPrice);
        }
    }
}

About

Robinhood Client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages