Overview

Namespaces

  • Sotr
    • Crypto
      • Bitstamp
      • Btce

Classes

  • Sotr\Crypto\AbstractApi
  • Sotr\Crypto\AbstractRequestSigner
  • Sotr\Crypto\AccountBalance
  • Sotr\Crypto\Bitstamp\BitstampApi
  • Sotr\Crypto\Bitstamp\BitstampRequestSigner
  • Sotr\Crypto\Btce\BtceApi
  • Sotr\Crypto\Btce\BtceCurrencyPairResolver
  • Sotr\Crypto\Btce\BtceRequestSigner
  • Sotr\Crypto\CurrencyPair
  • Sotr\Crypto\Ticker
  • Sotr\Crypto\TimestampNonceGenerator

Interfaces

  • Sotr\Crypto\CurrencyPairResolverInterface
  • Sotr\Crypto\ExchangeApiInterface
  • Sotr\Crypto\NonceGeneratorInterface
  • Sotr\Crypto\RequestSignerInterface
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Sotr\Crypto\Btce;
 3: 
 4: use RuntimeException;
 5: 
 6: use Sotr\Crypto\AbstractApi;
 7: use Sotr\Crypto\AccountBalance;
 8: use Sotr\Crypto\Btce\BtceCurrencyPairResolver;
 9: use Sotr\Crypto\CurrencyPair;
10: use Sotr\Crypto\Ticker;
11: 
12: class BtceApi extends AbstractApi
13: {
14:     public function __construct($key = null, $secret = null)
15:     {
16:         parent::__construct($key, $secret);
17:         $this->setCurrencyPairResolver(new BtceCurrencyPairResolver());
18:     }
19: 
20:     public function getPublicBaseUri()
21:     {
22:         return 'https://btc-e.com/api/2';
23:     }
24: 
25:     public function getTradingBaseUri()
26:     {
27:         return 'https://btc-e.com/tapi';
28:     }
29: 
30:     public function getTicker(CurrencyPair $pair = null)
31:     {
32:         if (! $pair) {
33:             throw new RuntimeException('BTC-e ticker needs a currency pair');
34:         }
35: 
36:         $pairString = $this->resolver->resolve($pair);
37:         $response = $this->client->request('GET', $this->getPublicBaseUri() . '/' . $pairString . '/ticker');
38:         $data = json_decode($response->getBody()->getContents());
39:         return new Ticker(
40:             $data->ticker->last,
41:             $data->ticker->high,
42:             $data->ticker->low,
43:             $data->ticker->sell,
44:             $data->ticker->buy
45:         );
46:     }
47: 
48:     public function getBalance()
49:     {
50:         $params = ['method' => 'getInfo'];
51:         $request = new \GuzzleHttp\Psr7\Request('POST', $this->getTradingBaseUri(), ['Content-Type' => 'application/x-www-form-urlencoded'], http_build_query($params));
52:         $signer = new BtceRequestSigner();
53:         $signed = $signer->sign($request, $this->key, $this->secret);
54:         $response = $this->client->send($signed);
55:         $data = json_decode($response->getBody()->getContents());
56:         $balance = new AccountBalance();
57:         foreach ($data->return->funds as $currency => $value) {
58:             $balance->set($currency, $value);
59:         }
60:         return $balance;
61:     }
62: }
63: 
API documentation generated by ApiGen