Connector Open-Source Code

Browse connector files locally. Exchange API keys stay on your device.

exchange_loader.php

<?php
declare(strict_types=1);

function load_exchange_adapter(string $exchangeName): array
{
    $exchangeName = strtolower(trim($exchangeName));
    if ($exchangeName === '') throw new RuntimeException('exchange.name is empty');

    $path = __DIR__ . '/exchanges/' . $exchangeName . '.php';
    if (!is_file($path)) throw new RuntimeException("Missing exchange adapter: {$path}");

    $adapter = require $path;
    if (!is_array($adapter)) throw new RuntimeException("Invalid adapter (must return array): {$path}");

    $required = [
        'normalize_symbol',
        'wallet',
        'place_buy',
        'place_sell',
        'order_info',
        'cancel_order',
        'map_status',
        'calc_buy_fill',
        'calc_sell_fill',
    ];
    foreach ($required as $k) {
        if (!isset($adapter[$k]) || !is_callable($adapter[$k])) {
            throw new RuntimeException("Adapter missing callable: {$exchangeName}.{$k}");
        }
    }
    return $adapter;
}