Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Added activity functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymarois committed Nov 19, 2019
1 parent a589ff9 commit 4b88001
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 50 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ $alpaca = $polygon->orders()->replace('ORDER_ID',[
]);
```

**[Get Activity](https://docs.alpaca.markets/api-documentation/api-v2/account-activities/)**: Get the account activity, like order filles, dividends etc.

```php
// type can be many, such as FILL, DIV, TRANS etc
// view on this page https://docs.alpaca.markets/api-documentation/api-v2/account-activities/
$alpaca = $polygon->activity()->get('TYPE');
```

There are more in the [Alpaca Documentation](https://docs.alpaca.markets/) than what is presented above, if you want to extend this, please send in a pull request or request features you'd like to see added. Thanks!

## Contributions
Expand Down
41 changes: 41 additions & 0 deletions src/Account/Activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace Alpaca\Account;

class Activity
{

/**
* Response array
*
* @var Alpaca\Alpaca
*/
private $alpaca;

/**
* __construct
*
*/
public function __construct(\Alpaca\Alpaca $alpaca)
{
$this->alpaca = $alpaca;
}

/**
* get()
*
* @return array
*/
public function get($type, $options=[])
{
return $this->alpaca->request('activity',array_merge(['type'=>$type],$options))->contents();
}

/**
* getFilledOrders()
*
* @return array
*/
public function getFilledOrders($from, $to, $options = [])
{
return $this->get('FILL',array_merge(['after'=>$from,'until'=>$to],$options));
}
}
69 changes: 19 additions & 50 deletions src/Alpaca.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use Alpaca\Request;
use Alpaca\Account\Account;
use Alpaca\Account\Order;
use Alpaca\Account\Orders;
use Alpaca\Account\Activity;

class Alpaca
{
Expand Down Expand Up @@ -50,7 +50,8 @@ class Alpaca
*/
private $paths = [
"account" => "/v2/account",
"activities" => "/v2/account/activities/{type}",
"activity" => "/v2/account/activities/{type}",
"activities" => "/v2/account/activities",
"orders" => "/v2/orders",
"order" => "/v2/orders/{id}",
"positions" => "/v2/positions",
Expand All @@ -64,6 +65,13 @@ class Alpaca
*/
private $orders;

/**
* activity
*
* @var Alpaca\Account\Activity
*/
private $activity;

/**
* Set Alpaca
*
Expand Down Expand Up @@ -157,57 +165,18 @@ public function orders()
return ($this->orders = (new Orders($this)));
}




/**
* getOrder()
* activity()
*
* @return Alpaca\Account\Order
* @return Alpaca\Account\Activity
*/
// public function getOrder($id)
// {
// return (new Order($this->request('order',['id'=>$id],'GET')->contents()));
// }

/**
* getOrder()
*
* @return Alpaca\Account\Order
*/
// public function getOrder($id)
// {
// return (new Order($this->request('order',['id'=>$id],'GET')->contents()));
// }

/**
* orders()
*
* @return Alpaca\Account\Orders
*/
// public function orders()
// {
// return (new Orders($this->request('orders')->contents()));
// }

/**
* cancelOrders()
*
* @return array
*/
// public function cancelOrder($id)
// {
// return $this->request('orders',['id'=>$id,'DELETE')->contents();
// }
public function activity()
{
if ($this->activity) {
return $this->activity;
}

/**
* cancelOrders()
*
* @return array
*/
// public function cancelOrders()
// {
// return $this->request('orders',[],'DELETE')->contents();
// }
return ($this->activity = (new Activity($this)));
}

}

0 comments on commit 4b88001

Please sign in to comment.