-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPositionClient.php
102 lines (90 loc) · 3 KB
/
PositionClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* This file is part of the Mab05k Oanda Client Bundle.
* (c) Michael A. Bos <mab05k@gmail.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Mab05k\OandaClient\Client;
use Mab05k\OandaClient\Request\Position\ClosePositionRequest;
use Mab05k\OandaClient\Response\Position\ClosePositionResponse;
use Mab05k\OandaClient\Response\Position\PositionResponse;
use Mab05k\OandaClient\Response\Position\PositionsResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* Class PositionClient.
*/
class PositionClient extends AbstractOandaClient
{
/**
* @throws \Http\Client\Exception
* @throws \Throwable
*
* List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of an the Account.
*
* @return PositionsResponse|null
*/
public function positions(): ?PositionsResponse
{
$request = $this->createRequest(
Request::METHOD_GET,
'/accounts/%s/positions'
);
return $this->sendRequest($request, PositionsResponse::class, 200);
}
/**
* @throws \Http\Client\Exception
* @throws \Throwable
*
* List all open Positions for an Account. An open Position is a Position in an Account that currently has a Trade opened for it.
*
* @return PositionsResponse|null
*/
public function openPositions(): ?PositionsResponse
{
$request = $this->createRequest(
Request::METHOD_GET,
'/accounts/%s/openPositions'
);
return $this->sendRequest($request, PositionsResponse::class, 200);
}
/**
* @param string $instrument
*
* @throws \Http\Client\Exception
* @throws \Throwable
*
* Get the details of a single Instrument’s Position in an Account. The Position may by open or not.
*
* @return PositionResponse|null
*/
public function position(string $instrument): ?PositionResponse
{
$request = $this->createRequest(
Request::METHOD_GET,
'/accounts/%s'.sprintf('/positions/%s', $instrument)
);
return $this->sendRequest($request, PositionResponse::class, 200);
}
/**
* @param string $instrument
* @param ClosePositionRequest $closePositionRequest
*
* @throws \Http\Client\Exception
* @throws \Throwable
*
* Closeout the open Position for a specific instrument in an Account
*
* @return ClosePositionResponse|null
*/
public function close(string $instrument, ClosePositionRequest $closePositionRequest): ?ClosePositionResponse
{
$request = $this->createRequest(
Request::METHOD_PUT,
'/accounts/%s'.sprintf('/positions/%s/close', $instrument),
$closePositionRequest
);
return $this->sendRequest($request, ClosePositionResponse::class, 200);
}
}