The Stock Walk App is a simple Android application designed to fetch and display stock data in real-time using the YH Finance API. The app allows users to search for stock symbols and view details such as company name, stock price, and percentage change.
- Real-time stock data fetching.
- Displays stock name, price, and percentage change.
- Simple and clean UI using Android's ConstraintLayout, MVVM and Material Design components.
- Robust error handling and loading state management.
StockWalkApp/
├── app/
│ ├── manifests/
│ ├── java/
│ │ └── com.example.stockwalkapp/
│ │ ├── MainActivity.java # MainActivity for handling the UI logic
│ │ ├── api/
│ │ │ ├── ApiClient.java # Retrofit setup and API client configuration
│ │ │ └── StockApi.java # Interface defining the API calls and endpoints
│ │ ├── model/
│ │ │ └── StockResponse.java # Model class to represent the stock data response from API
│ │ ├── utils/
│ │ │ └── ConfigManager.java # Utility class for managing config values (API keys)
│ │ ├── viewmodel/
│ │ │ └── StockViewModel.java # ViewModel class for managing UI-related data for stocks
│ ├── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml # Layout file for MainActivity
│ │ ├── raw/
│ │ │ └── config.properties # Contains API keys (API_KEY, API_HOST)
│ │ ├── values/
│ │ │ ├── strings.xml # String resources for the app
│ │ │ └── colors.xml # Color resources for the app
│ ├── build.gradle # Gradle build script
└── README.md # Project documentation
-
User enters a stock symbol and presses the search button in the MainActivity.
-
MainActivity sends a request to StockViewModel to fetch stock data.
-
StockViewModel calls the ApiClient, which uses the StockApi interface to fetch the data from the YH Finance API.
-
The API response is mapped to a StockResponse object.
-
StockViewModel updates the MainActivity UI with the fetched stock data or shows an error message if the request fails.
This flow ensures separation of concerns and follows the MVVM pattern, making it easier to maintain and test.
-
Android Studio installed
-
API Key for YH Finance API
-
Steps:
-
Clone the repository:
git clone https://github.com/Abhishek-Bansode/StockWalkApp.git cd StockWalkApp
-
Add your YH Finance API Key & Host in config.properties:
X_RAPID_API_KEY=your_api_key_here X_RAPID_API_HOST=yahoo-finance15.p.rapidapi.com
-
Build the project in Android Studio:
-> Open the project in Android Studio.
-> Add Retrofit and OkHttp to build.gradle(module):
implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.okhttp3:okhttp:4.9.3'
-
Add Network permission in manifests file:
<uses-permission android:name="android.permission.INTERNET" />
-
Sync your project to ensure the dependencies are downloaded. Sync Gradle files and build the project.
-
Run the app on an Emulator or a Physical device.
-
The app uses the YH Finance API from RapidAPI to fetch stock details.
Stock Details: Fetch stock details like company name, stock price, and percentage change.
Endpoint: /api/v1/markets/quote
Method: GET
Parameters: ticker & type (e.g., ticker=TSLA&type=STOCKS)
Headers: X-RapidAPI-Key & X-RapidAPI-Host
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(chain -> {
Request request = chain.request().newBuilder()
.addHeader("X-RapidAPI-Key", apiKey)
.addHeader("X-RapidAPI-Host", apiHost)
.build();
return chain.proceed(request);
}).build();
retrofit = new Retrofit.Builder()
.baseUrl("https://yahoo-finance15.p.rapidapi.com/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
StockApi api = ApiClient.getClient().create(StockApi.class);
api.getStockData(ticker, "STOCKS").enqueue(new Callback<StockResponse>()
-
The YH Finance API is used in this app for fetching stock data. More information can be found in their YH Finance API Documentation.
-
The app follows the MVVM pattern for better code separation. Learn more about it MVVM Pattern in Android.
-
The app uses Retrofit for making HTTP requests. More information can be found in Retrofit Documentation.