ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - FirstArtaxer/karbitrage: arbitrage finder
arbitrage finder. Contribute to FirstArtaxer/karbitrage development by creating an account on GitHub.
Visit Site

GitHub - FirstArtaxer/karbitrage: arbitrage finder

GitHub - FirstArtaxer/karbitrage: arbitrage finder

Karbitrage

Karbitrage, which stands for "arbitrage finder," is a Kotlin-based project designed to extract cryptocurrency prices from various exchanges using the Ktor framework. This project focuses on exploring Ktor in addition to designing an application with maximum changeability and extensibility. The application periodically persists data to a PostgreSQL database and provides APIs to retrieve the price data.

Technologies Used

  • Ktor: For building asynchronous servers and web applications in Kotlin.
  • Exposed: A lightweight SQL library on top of JDBC for Kotlin.
  • PostgreSQL: For persisting cryptocurrency price data.
  • Caffeine Cache: For in-memory caching to improve performance.
  • Reflection: For dynamic class loading and manipulation.
  • Koin: A pragmatic lightweight dependency injection framework for Kotlin.

Getting Started

Prerequisites

  • Kotlin 1.8+
  • Gradle 7.0+
  • Java 11+
  • PostgreSQL
  • H2 Database (for testing)

Installation

  1. Clone the repository:
    git clone https://github.com/FirstArtaxer/karbitrage.git
    
  2. Navigate to the project directory:
    cd karbitrage
    
  3. Build the project:
    ./gradlew build
    
  4. Set up PostgreSQL and configure the connection settings in your application.

Running the Application

  1. Start the server:
    ./gradlew run
    
  2. The application will be available at http://localhost:8080.

API Endpoints

  • Get Cryptocurrency Prices:

    GET /cryptos/prices?from={fromDateTime}&to={toDateTime}&symbol={symbol}
    

    Retrieves the prices of a specific cryptocurrency symbol within a date range from all implemented exchanges.

  • Get Latest Prices:

    GET /cryptos/last-prices
    

    Retrieves the latest prices of all cryptocurrencies from all implemented exchanges.

Extending with New Exchanges

To add a new exchange, implement the PriceExtractor and RequestMaker interfaces:

Implementing RequestMaker

/**
 * Interface for creating HTTP requests to a cryptocurrency exchange API.
 */
interface RequestMaker {

    /**
     * Constructs an HTTP request to retrieve data from the exchange.
     *
     * @return A [HttpRequestBuilder] configured to make the request to the exchange's API.
     */
    fun getRequest(): HttpRequestBuilder
}

Implementing PriceExtractor

/**
 * Abstract class for extracting price data from a cryptocurrency exchange.
 */
abstract class PriceExtractor {

    /**
     * Gets a function that processes the API response from the exchange.
     *
     * @return A function that takes a string response from the exchange's API and returns
     *         a map where the key is the cryptocurrency symbol and the value is the price.
     *         This function extracts the relevant data from the API response string.
     */
    abstract fun getExtractor(): (String) -> Map<String, Double>
}

Example

  1. Create a new class in the exchange package.
  2. Implement the required interfaces and abstract methods.
package exchange

import io.ktor.client.request.*
import io.ktor.client.request.HttpRequestBuilder

class NewExchangeRequestMaker : RequestMaker {
    override fun getRequest(): HttpRequestBuilder {
        // Define the HTTP request for the new exchange
    }
}

class NewExchangePriceExtractor : PriceExtractor() {
    override fun getExtractor(): (String) -> Map<String, Double> {
        // Define the extraction logic for the new exchange
    }
}

Testing

  1. Run the tests:
    ./gradlew test
    

Running with Docker

To build and run the application using Docker Compose, execute the following command in the project directory:

docker-compose up --build

Contributing

Contributions are welcome! Please fork the repository and create a pull request.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory