PHPackages                             sammarks/stockfighter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. sammarks/stockfighter

ActiveLibrary[API Development](/categories/api)

sammarks/stockfighter
=====================

A Stockfighter API Wrapper.

019PHP

Since Dec 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/sammarks/stockfighter-php)[ Packagist](https://packagist.org/packages/sammarks/stockfighter)[ RSS](/packages/sammarks-stockfighter/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Stockfighter PHP API Wrapper
============================

[](#stockfighter-php-api-wrapper)

I use this library inside my solutions repository, and thought I'd share it with the world. My solutions repository can be found [here](https://github.com/sammarks/stockfighter-solution-php)(*spoiler alert*).

Installation
------------

[](#installation)

Just install this library using Composer.

```
composer install sammarks/stockfighter

```

Or you can require it into your project using:

```
composer require sammarks/stockfighter

```

**Note:** You'll also need to specify the repository settings as this package relies on my fork of [phpws.](https://github.com/Devristo/phpws) Add the following to your `composer.json`:

```
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/sammarks/phpws"
    }
],

```

Additionally, because the library relies on a fork like this, you'll need to make sure the minimum stability of your project is set to "dev:"

```
"minimum-stability": "dev"

```

Usage
-----

[](#usage)

This library is setup so that it follows the URL structure of the Stockfighter API documentation very closely. With that said, here's an example of the library usage:

```
use \Marks\Stockfighter\Stockfighter;

// Set the API key.
Stockfighter::setApiKey('apikey');

// Create an instance of the API.
$stockfighter = new Stockfighter();

// Check if the API is working.
$api_working = $stockfighter->heartbeat();

// Check if a venue exists and is working.
$test_working = $stockfighter->venue('test')->heartbeat();

// Get all stocks in a venue.
$stocks = $stockfighter->venue('test')->stocks();

// Get information about a stock.
$stock_info = $stockfighter->venue('test')->stock('ABCD')->info();

// Order some ABCD stock.
$order = $stockfighter->venue('test')->stock('ABCD')->order($account, $price, $quantity, $direction, $order_type);
// Direction and Order Type have constants in the Order class, like Order::DIRECTION_BUY,
// Order::DIRECTION_SELL, Order::TYPE_MARKET, etc.
```

### Web Sockets

[](#web-sockets)

You can also connect and listen for quotes using WebSockets. Here's an example of that:

```
// Create a websocket instance.
$websocket = $this->stockfighter->getWebSocketCommunicator()->quotes($account, $venue, $stock);

// Set the receive callback.
$websocket->receive(function (Quote $quote) {
	// Do stuff with the quote...
	// Once you're done with the websocket connection, return true
	// from this method and the connection will be closed.
});

// Open the connection.
$websocket->connect();
```

### Asynchronous Calling

[](#asynchronous-calling)

This library uses [Guzzle](https://github.com/guzzle/guzzle) for its HTTP requests, which uses PSR-7 promises. Naturally, I have included support for promises in this library. Here's an example of how to place an order using asynchronous calls:

```
// Assuming you already have a stockfighter instance...
// Here's an example that places an order asynchronously.
$stockfighter->venue('test')->stock('ABCD')->orderAsync($account, $price, $quantity, $direction,
	$order_type)->then(function (Order $order) {
		echo "Oh boy, the order finished! " . $order->totalFulfilled;
	}, function (StockfighterRequestException $e) {
		echo "Oh no, there was an error with the order! " . $e->getMessage();
	});
```

### Event Loop

[](#event-loop)

**Important Note:** If you're using either the websockets or the asynchronous calling, you'll need to initialize the [ReactPHP](https://github.com/reactphp) event loop. Usually this is done as the last call of your application (as it is a blocking method). Do all of your initialization and processing logic, and then call the following right before the end of your application:

```
// Start the Event Loop.
$stockfighter->run();
```

Contributing
------------

[](#contributing)

If you find an error in my Stockfighter library, or would like to improve it because you're using it in your own Stockfighter solutions, just send me a pull request! I promise I'll be very open to suggestions.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/424093?v=4)[Sam Marks](/maintainers/sammarks)[@sammarks](https://github.com/sammarks)

---

Top Contributors

[![sammarks](https://avatars.githubusercontent.com/u/424093?v=4)](https://github.com/sammarks "sammarks (49 commits)")

### Embed Badge

![Health badge](/badges/sammarks-stockfighter/health.svg)

```
[![Health](https://phpackages.com/badges/sammarks-stockfighter/health.svg)](https://phpackages.com/packages/sammarks-stockfighter)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M19](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k12](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
