Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client instance error #66

Closed
DanielBedensky14 opened this issue Dec 25, 2024 · 14 comments
Closed

Client instance error #66

DanielBedensky14 opened this issue Dec 25, 2024 · 14 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@DanielBedensky14
Copy link

Hello, please help, after localy try to run the code and make instance of client i got error like this
**Warning: stream_socket_client(): Unable to connect to ssl://xapi.xtb.com:5112 (Connection timed out) in /var/www/html/src/Connections/SocketConnection.php on line 53

Fatal error: Uncaught Timirey\XApi\Exceptions\SocketException: 110: Connection timed out in /var/www/html/src/Connections/SocketConnection.php:56 Stack trace: #0 /var/www/html/src/Connections/SocketConnection.php(32): Timirey\XApi\Connections\SocketConnection->open() #1 /var/www/html/src/Client.php(761): Timirey\XApi\Connections\SocketConnection->__construct('ssl://xapi.xtb....') #2 /var/www/html/src/Client.php(129): Timirey\XApi\Client->connect() #3 /var/www/html/public/index.php(9): Timirey\XApi\Client->__construct(, '', Object(Timirey\XApi\Enums\Host), 'My Test App') #4 {main} thrown in /var/www/html/src/Connections/SocketConnection.php on line 56**

:/

@timirey
Copy link
Owner

timirey commented Dec 25, 2024

Hey, can you share the code you are having error with?

@DanielBedensky14
Copy link
Author

Hi,

i just run this

`<?php

require DIR . '/../vendor/autoload.php';

use Timirey\XApi\Client;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Responses\LoginResponse;

$client = new Client(
userId: 444,
password: '',
host: Host::REAL,
appName: 'My Test App'
);

/**

  • @var LoginResponse $response
  • @var Client $client
    */
    $response = $client->login(
    userId: 444,
    password: '',
    appName: 'My App'
    );

var_dump($response);
die;
`

@DanielBedensky14
Copy link
Author

Can i text you somewhere else ?

@timirey
Copy link
Owner

timirey commented Dec 25, 2024

You dont need to login. When you create the client, the connection is already made.

Try to send commands right after the client instance is created.

@DanielBedensky14
Copy link
Author

DanielBedensky14 commented Dec 25, 2024

Yes but problem is with making client instance

MacBook-Pro:~ danielbedensky$ curl -v https://xapi.xtb.com:5124

  • Host xapi.xtb.com:5124 was resolved.
  • IPv6: (none)
  • IPv4: 81.2.190.183, 81.2.190.163
  • Trying 81.2.190.183:5124...
  • connect to 81.2.190.183 port 5124 from 10.10.2.159 port 53064 failed: Operation timed out
  • Trying 81.2.190.163:5124...
  • connect to 81.2.190.163 port 5124 from 10.10.2.159 port 53092 failed: Operation timed out
  • Failed to connect to xapi.xtb.com port 5124 after 150047 ms: Couldn't connect to server
  • Closing connection
    curl: (28) Failed to connect to xapi.xtb.com port 5124 after 150047 ms: Couldn't connect to server
    MacBook-Pro:~ danielbedensky$

the endpoint of xtb cant answer

@timirey
Copy link
Owner

timirey commented Dec 25, 2024 via email

@DanielBedensky14
Copy link
Author

thanks a lot ... i will be waiting for your info

@timirey
Copy link
Owner

timirey commented Dec 26, 2024

Please check that you are using proper credentials. I just did this and it worked without any issues. I have checked: both demo and real environment are operational, can you confirm that it works for you as well? If no, you can contact XTB developers, as issue is whether on your side or their.

XTB support: [email protected]

This repository is only a wrapper around their API.

<?php

require_once "vendor/autoload.php";

$client = new \Timirey\XApi\Client(
    1234567,
    'MyVerySecurePassword',
    \Timirey\XApi\Enums\Host::REAL
);

$response = $client->getSymbol('EURUSD');

var_dump($response);

This gives me the following response:

object(Timirey\XApi\Responses\GetSymbolResponse)#8 (1) {
  ["symbolRecord"]=>
  object(Timirey\XApi\Responses\Data\SymbolRecord)#10 (48) {
    ["quoteId"]=>
    enum(Timirey\XApi\Enums\QuoteId::FIVE)
    ["marginMode"]=>
    enum(Timirey\XApi\Enums\MarginMode::FOREX)
    ["profitMode"]=>
    enum(Timirey\XApi\Enums\ProfitMode::FOREX)
    ["expiration"]=>
    NULL
    ["starting"]=>
    NULL
    ["time"]=>
    object(DateTime)#21 (3) {
      ["date"]=>
      string(26) "2024-12-26 17:10:43.957000"
      ["timezone_type"]=>
      int(1)
      ["timezone"]=>
      string(6) "+00:00"
    }
    ["swapRollover3Days"]=>
    int(0)
    ["symbol"]=>
    string(6) "EURUSD"
    ["currency"]=>
    string(3) "EUR"
    ["categoryName"]=>
    string(2) "FX"
    ["currencyProfit"]=>
    string(3) "USD"
    ["quoteIdCross"]=>
    int(4)
    ["pipsPrecision"]=>
    int(4)
    ["contractSize"]=>
    int(100000)
    ["exemode"]=>
    int(1)
    ["stopsLevel"]=>
    int(0)
    ["precision"]=>
    int(5)
    ["swapType"]=>
    int(3)
    ["stepRuleId"]=>
    int(5)
    ["type"]=>
    int(982)
    ["instantMaxVolume"]=>
    int(2147483647)
    ["groupName"]=>
    string(5) "Major"
    ["description"]=>
    string(23) "Euro to American Dollar"
    ["longOnly"]=>
    bool(false)
    ["trailingEnabled"]=>
    bool(true)
    ["marginHedgedStrong"]=>
    bool(false)
    ["swapEnable"]=>
    bool(true)
    ["percentage"]=>
    float(100)
    ["bid"]=>
    float(1.0419)
    ["ask"]=>
    float(1.04204)
    ["high"]=>
    float(1.04223)
    ["low"]=>
    float(1.03899)
    ["lotMin"]=>
    float(0.01)
    ["lotMax"]=>
    float(100)
    ["lotStep"]=>
    float(0.01)
    ["tickSize"]=>
    float(1.0E-5)
    ["tickValue"]=>
    float(1)
    ["swapLong"]=>
    float(-0.006712)
    ["swapShort"]=>
    float(0.001159)
    ["leverage"]=>
    float(3.33)
    ["spreadRaw"]=>
    float(0.00014)
    ["spreadTable"]=>
    float(1.4)
    ["marginMaintenance"]=>
    int(0)
    ["marginHedged"]=>
    int(0)
    ["initialMargin"]=>
    int(0)
    ["timeString"]=>
    string(28) "Thu Dec 26 18:10:43 CET 2024"
    ["shortSelling"]=>
    bool(true)
    ["currencyPair"]=>
    bool(true)
  }
}

@timirey timirey closed this as completed Dec 26, 2024
@timirey timirey self-assigned this Dec 26, 2024
@timirey timirey added the help wanted Extra attention is needed label Dec 26, 2024
@DanielBedensky14
Copy link
Author

DanielBedensky14 commented Dec 26, 2024

Hi,

I found an error, it works. Thanks a lot.

@timirey
Copy link
Owner

timirey commented Dec 26, 2024

Dont forget to star the repository so you dont miss any updates :)

@DanielBedensky14
Copy link
Author

can u call getAllSymbols() ? without fattal error ? maybe is problem only on my side

i got error like this Fatal error: Uncaught ValueError: 6 is not a valid backing value for enum Timirey\XApi\Enums\QuoteId in /var/www/html/src/Responses/Data/SymbolRecord.php:154 Stack trace: #0 /var/www/html/src/Responses/Data/SymbolRecord.php(154): Timirey\XApi\Enums\QuoteId::from(6) #1 /var/www/html/src/Responses/GetAllSymbolsResponse.php(29): Timirey\XApi\Responses\Data\SymbolRecord->__construct('TGNA.US_9', 'USD', 'STC', 'USD', 6, 15, 104, 6, 2, 1, 1, 1735246799778, NULL, 0, 2, 2, 12, 2724, 2147483647, 'US', 'TEGNA Inc ', true, false, false, true, 100.0, 18.54, 18.55, 18.55, 18.18, 1.0, 1000000.0, 1.0, 0.01, 0.01, 0.0, 0.0, 100.0, 0.01, 1.0, NULL, 0, 0, 0, 0, 'Thu Dec 26 21:5...', false, false) #2 [internal function]: Timirey\XApi\Responses\GetAllSymbolsResponse::Timirey\XApi\Responses{closure}(Array) #3 /var/www/html/src/Responses/GetAllSymbolsResponse.php(28): array_map(Object(Closure), Array) #4 /var/www/html/src/Responses/AbstractResponse.php(33): Timirey\XApi\Responses\GetAllSymbolsResponse::create(Array) #5 /var/www/html/src/Client.php(791): Timirey\XApi\Responses\AbstractResponse::instantiate('{"status":true,...') #6 /var/www/html/src/Client.php(194): Timirey\XApi\Client->request(Object(Timirey\XApi\Payloads\GetAllSymbolsPayload), 'Timirey\XApi\Re...') #7 /var/www/html/public/index.php(19): Timirey\XApi\Client->getAllSymbols() #8 {main} thrown in /var/www/html/src/Responses/Data/SymbolRecord.php on line 154 another calls are fine.

@timirey
Copy link
Owner

timirey commented Dec 27, 2024

I think they added a new type of Quote. I will update it.

@timirey timirey reopened this Dec 27, 2024
@timirey
Copy link
Owner

timirey commented Dec 27, 2024

@DanielBedensky14

Here is a new release: https://github.com/timirey/xapi-php/releases/tag/6.2.0

Their documentation is outdated, so there are more things to consider.

@timirey timirey closed this as completed Dec 27, 2024
@timirey
Copy link
Owner

timirey commented Jan 4, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants