{"id":15490724,"url":"https://github.com/sammarks/stockfighter-php","last_synced_at":"2025-03-28T16:28:12.444Z","repository":{"id":62539776,"uuid":"48337548","full_name":"sammarks/stockfighter-php","owner":"sammarks","description":"Stockfighter API wrapper in PHP.","archived":false,"fork":false,"pushed_at":"2016-01-24T00:03:48.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T16:56:13.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sammarks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-20T21:18:43.000Z","updated_at":"2015-12-21T02:23:34.000Z","dependencies_parsed_at":"2022-11-02T15:45:17.547Z","dependency_job_id":null,"html_url":"https://github.com/sammarks/stockfighter-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fstockfighter-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fstockfighter-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fstockfighter-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fstockfighter-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sammarks","download_url":"https://codeload.github.com/sammarks/stockfighter-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246061909,"owners_count":20717526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T07:23:30.961Z","updated_at":"2025-03-28T16:28:10.010Z","avatar_url":"https://github.com/sammarks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stockfighter PHP API Wrapper\n\nI use this library inside my solutions repository, and thought I'd share it with the world.\nMy solutions repository can be found [here](https://github.com/sammarks/stockfighter-solution-php)\n(*spoiler alert*).\n\n## Installation\n\nJust install this library using Composer.\n\n```\ncomposer install sammarks/stockfighter\n```\n\nOr you can require it into your project using:\n\n```\ncomposer require sammarks/stockfighter\n```\n\n**Note:** You'll also need to specify the repository settings as this package\nrelies on my fork of [phpws.](https://github.com/Devristo/phpws) Add the following\nto your `composer.json`:\n\n```\n\"repositories\": [\n    {\n        \"type\": \"vcs\",\n        \"url\": \"https://github.com/sammarks/phpws\"\n    }\n],\n```\n\nAdditionally, because the library relies on a fork like this, you'll need to make sure\nthe minimum stability of your project is set to \"dev:\"\n\n```\n\"minimum-stability\": \"dev\"\n```\n\n## Usage\n\nThis library is setup so that it follows the URL structure of the Stockfighter API documentation\nvery closely. With that said, here's an example of the library usage:\n\n```php\nuse \\Marks\\Stockfighter\\Stockfighter;\n\n// Set the API key.\nStockfighter::setApiKey('apikey');\n\n// Create an instance of the API.\n$stockfighter = new Stockfighter();\n\n// Check if the API is working.\n$api_working = $stockfighter-\u003eheartbeat();\n\n// Check if a venue exists and is working.\n$test_working = $stockfighter-\u003evenue('test')-\u003eheartbeat();\n\n// Get all stocks in a venue.\n$stocks = $stockfighter-\u003evenue('test')-\u003estocks();\n\n// Get information about a stock.\n$stock_info = $stockfighter-\u003evenue('test')-\u003estock('ABCD')-\u003einfo();\n\n// Order some ABCD stock.\n$order = $stockfighter-\u003evenue('test')-\u003estock('ABCD')-\u003eorder($account, $price, $quantity, $direction, $order_type);\n// Direction and Order Type have constants in the Order class, like Order::DIRECTION_BUY,\n// Order::DIRECTION_SELL, Order::TYPE_MARKET, etc.\n```\n\n### Web Sockets\n\nYou can also connect and listen for quotes using WebSockets. Here's an example of that:\n\n```php\n// Create a websocket instance.\n$websocket = $this-\u003estockfighter-\u003egetWebSocketCommunicator()-\u003equotes($account, $venue, $stock);\n\n// Set the receive callback.\n$websocket-\u003ereceive(function (Quote $quote) {\n\t// Do stuff with the quote...\n\t// Once you're done with the websocket connection, return true\n\t// from this method and the connection will be closed.\n});\n\n// Open the connection.\n$websocket-\u003econnect();\n```\n\n### Asynchronous Calling\n\nThis library uses [Guzzle](https://github.com/guzzle/guzzle) for its HTTP requests, which uses PSR-7\npromises. Naturally, I have included support for promises in this library. Here's an example of how\nto place an order using asynchronous calls:\n\n```php\n// Assuming you already have a stockfighter instance...\n// Here's an example that places an order asynchronously.\n$stockfighter-\u003evenue('test')-\u003estock('ABCD')-\u003eorderAsync($account, $price, $quantity, $direction,\n\t$order_type)-\u003ethen(function (Order $order) {\n\t\techo \"Oh boy, the order finished! \" . $order-\u003etotalFulfilled;\t\n\t}, function (StockfighterRequestException $e) {\n\t\techo \"Oh no, there was an error with the order! \" . $e-\u003egetMessage();\t\n\t});\n```\n\n### Event Loop\n\n**Important Note:** If you're using either the websockets or the asynchronous calling, you'll need\nto initialize the [ReactPHP](https://github.com/reactphp) event loop. Usually this is done as the\nlast call of your application (as it is a blocking method). Do all of your initialization and\nprocessing logic, and then call the following right before the end of your application:\n\n```php\n// Start the Event Loop.\n$stockfighter-\u003erun();\n```\n\n## Contributing\n\nIf you find an error in my Stockfighter library, or would like to improve it because you're using\nit in your own Stockfighter solutions, just send me a pull request! I promise I'll be very open\nto suggestions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsammarks%2Fstockfighter-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsammarks%2Fstockfighter-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsammarks%2Fstockfighter-php/lists"}