Closed AndyWylde closed 3 years ago
Hello @AndyWylde
It seems to be an internal error related to your configuration/system. You can check the last tests done, everything is ok : https://github.com/MockingMagician/coinbase-pro-sdk/runs/4060656823?check_suite_focus=true
I'm also running PHP 7.4 on Ubuntu 20.04 and I don't have any problem.
Concerning the installation, are you familiar with the PHP environment and composer ?
On the other hand, you said that you had to use composer as root, but this is a bad practice. How did you install composer?
On the other hand, the good practice in a PHP project is the structure of your project:
So in your terminal, run these commands:
mkdir my-crypto-project
cd my-crypto-project
compose init
The last command allows you to create a php project config, follow the instructions of the command.
when it asks you if you want to add dependencies, don't forget to add mocking-magician/coinbase-pro-sdk
Your src
folder must contain your classes
Now let's suppose you have a main.php file which is the input of your program, as an example, it could look like this:
<?php
use MockingMagician\CoinbaseProSdk\CoinbaseFacade;
require_once __DIR__.'/vendor/autoload.php';
$api = CoinbaseFacade::createDefaultCoinbaseApi(
'https://api.exchange.coinbase.com',
'key', //replace with yours
'secret', //replace with yours
'passphrase' //replace with yours
);
$accounts = $api->accounts()->list();
foreach ($accounts as $account) {
echo sprintf(
"On my account %s (id: %s), I have %s available funds, %s on holds. So, my balance is %s. Currently trading is %s.\n",
$account->getCurrency(),
$account->getId(),
$account->getAvailableFunds(),
$account->getHoldFunds(),
$account->getBalance(),
$account->isTradingEnabled() ? 'enable' : 'not enabled'
);
}
Just run in your terminal :
php main.php
Try it, and everything should be fine :)
Hi, I want to thank you very much for responding and the good advice. I am familiar with php, but not so much composer. I had never used it before, and although I read the documentation there are several errors in it that cause it to be non-functional if followed. Composer was already on my machine before I started and that may have been part of the problem.
I actually completely uninstalled it from the machine I am using and just installed it locally after a couple more failed attempts.
I used the following to get it installed locally:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
At that point I was finally able to run the composer init and add the dependencies. That was the part I was missing and I did not know how to do that.
After I finally got that to run and added your sdk to the dependencies I was able to run your example code without problems. I expect my own code will run fine now also, and with all your examples I should be able to put together a program doing what I want.
Thank you again for responding, and I hope maybe you will incorporate a little of this in the instructions for your SDK as I think it would save many people quite a bit of time. Now to start coding…..
Andy
From: 2M @.> Sent: Monday, November 1, 2021 3:41 PM To: MockingMagician/coinbase-pro-sdk @.> Cc: AndyWylde @.>; Mention @.> Subject: Re: [MockingMagician/coinbase-pro-sdk] Need better install instructions. (Issue #26)
Hello @AndyWylde https://github.com/AndyWylde
It seems to be an internal error related to your configuration/system. You can check the last tests done, everything is ok : https://github.com/MockingMagician/coinbase-pro-sdk/runs/4060656823?check_suite_focus=true
I'm also running PHP 7.4 on Ubuntu 20.04 and I don't have any problem.
Concerning the installation, are you familiar with the PHP environment and composer ?
On the other hand, you said that you had to use composer as root, but this is a bad practice. How did you install composer?
On the other hand, the good practice in a PHP project is the structure of your project:
So in your terminal, run these commands:
mkdir my-crypto-project cd my-crypto-project compose init
The last command allows you to create a php project config, follow the instructions of the command. when it asks you if you want to add dependencies, don't forget to add mocking-magician/coinbase-pro-sdk
Your src folder must contain your classes
Now let's suppose you have a main.php file which is the input of your program, as an example, it could look like this:
<?php
use MockingMagician\CoinbaseProSdk\CoinbaseFacade;
require_once DIR.'/vendor/autoload.php';
$api = CoinbaseFacade::createDefaultCoinbaseApi( 'https://api.exchange.coinbase.com', 'key', //replace with yours 'secret', //replace with yours 'passphrase' //replace with yours );
$accounts = $api->accounts()->list();
foreach ($accounts as $account) { echo sprintf( "On my account %s (id: %s), I have %s available funds, %s on holds. So, my balance is %s. Currently trading is %s.\n", $account->getCurrency(), $account->getId(), $account->getAvailableFunds(), $account->getHoldFunds(), $account->getBalance(), $account->isTradingEnabled() ? 'enable' : 'not enabled' ); }
Just run in your terminal :
php main.php
Try it, and everything should be fine :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MockingMagician/coinbase-pro-sdk/issues/26#issuecomment-956782858 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZ55L4ZAWMIDLBIZM2MKKDUJ4JO7ANCNFSM5G6LGHWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . https://github.com/notifications/beacon/AHZ55L5LF3CVKBJ47CGRKHLUJ4JO7A5CNFSM5G6LGHW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHEDVSCQ.gif
After I finally got that to run and added your sdk to the dependencies I was able to run your example code without problems. I expect my own code will run fine now also, and with all your examples I should be able to put together a program doing what I want.
Great !
Thank you again for responding, and I hope maybe you will incorporate a little of this in the instructions for your SDK as I think it would save many people quite a bit of time.
This out of the scope of this SDK. It is purely related to PHP environement. Every provider of a library must assume users knows how to use PHP coding environement. You don't see any instruction on how to run PHP, composer or autoload class in Laravel or Symfony or Guzzle, or etc...
@AndyWylde If you have any problem with your code, feel free to create a public or private repo and invite me to contribute. I could always give you a hand if I have some time left on my free time.
I do understand, and I realize it’s pretty much impossible to provide something like this without some sort of dependency manager. I just wish the composer docs were a little more “correct”. I followed 3 different “getting started” tutorials on it, all of which ended up with an unusable configuration. I never did see anything about running the “composer init” you mentioned which was what I was looking for …. so I could add the dependencies. It might be in there somewhere but I didn’t find it.
Yes, the fact that I had never used composer before definitely made it much more difficult, and even though I had to slightly modify your instructions to work in my environment, those two sentences gave me what I was looking for so I could figure it out. It was more helpful than the many pages of docs I read on composer before talking to you. I’ve been programming in php for over 20 years and never used composer ever before. I can see that it has some nice advantages, but it’s a big barrier to entry for people wanting to use your code who aren’t already familiar with it. The other items are more accessible in my opinion.
One final question, In the example you sent me you used the syntax:
$accounts = $api->accounts()->list();
Then you pull the values out of the structure. In the github docs you show the method
$api->coinbaseAccounts()->listCoinbaseAccounts();
Is there any documentation as the parameters the method supports, or do I need to look at the source to determine the data structures?
Andy
From: 2M @.> Sent: Tuesday, November 2, 2021 2:38 AM To: MockingMagician/coinbase-pro-sdk @.> Cc: AndyWylde @.>; Mention @.> Subject: Re: [MockingMagician/coinbase-pro-sdk] Need better install instructions. (Issue #26)
After I finally got that to run and added your sdk to the dependencies I was able to run your example code without problems. I expect my own code will run fine now also, and with all your examples I should be able to put together a program doing what I want.
Great !
Thank you again for responding, and I hope maybe you will incorporate a little of this in the instructions for your SDK as I think it would save many people quite a bit of time.
This out of the scope of this SDK. It is purely related to PHP environement. Every provider of a library must assume users knows how to use PHP coding environement. You don't see any instruction on how to run PHP, composer or autoload class in Laravel or Symfony or Guzzle, or etc...
— You are receiving this because you were mentioned. Reply to this email directly, https://github.com/MockingMagician/coinbase-pro-sdk/issues/26#issuecomment-957268984 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AHZ55L56JRPVLYKGUN6YWQLUJ6WQNANCNFSM5G6LGHWQ unsubscribe. Triage notifications on the go with GitHub Mobile for https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 iOS or https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub Android. https://github.com/notifications/beacon/AHZ55LZ2P5D2CUKABYQEO43UJ6WQNA5CNFSM5G6LGHW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHEHMH6A.gif
Thank you very much. I have a lot to do before I would even know where to ask for help. My first goal is to get the ticker information and put what I am interested in into a SQL database. Your examples are pretty good on the Websocket and I think I can get through that part. Once I have the data where I can work with and run some tests it I’ll eventually want to automatically place and/or cancel trades and then I might need some help.
Thanks Again.
From: 2M @.> Sent: Tuesday, November 2, 2021 2:44 AM To: MockingMagician/coinbase-pro-sdk @.> Cc: AndyWylde @.>; Mention @.> Subject: Re: [MockingMagician/coinbase-pro-sdk] Need better install instructions. (Issue #26)
@AndyWylde https://github.com/AndyWylde If you have any problem with your code, feel free to create a public or private repo and invite me to contribute. I could always give you a hand if I have some time left on my free time.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MockingMagician/coinbase-pro-sdk/issues/26#issuecomment-957273294 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZ55L5IEW4QDNYRA6MS6PLUJ6XGVANCNFSM5G6LGHWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . https://github.com/notifications/beacon/AHZ55L7UR43MSGK5YQMFQULUJ6XGVA5CNFSM5G6LGHW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHEHNJTQ.gif
I’ve been programming in php for over 20 years and never used composer ever before :eyes:
Composer exist since PHP is POO... Any modern library use composer. It is the way you have to do for autoloading classes. It is the same has Maven for Java, npm or yarn for js...
If you look at the structure of composer.json you will see an autoload
key containing another key psr-4
where you difine the namespace of your classes and the root directory where they are stored.
So, when you call at the entry point of your project require_once __DIR__.'/vendor/autoload.php';
this file create auoloading for all dependencies of your project. So, now you able to call any of thems without to care.
Post composer, it was fastidious, you should have to require any file of the dependencies... humanly borring and source of mistakes...
I can see that it has some nice advantages, but it’s a big barrier to entry for people wanting to use your code who aren’t already familiar with it
I recommand you always use it, cause benefits are more than the pain to learn about it. Do just one project with it and you will understand all the necessary basics.
Is there any documentation as the parameters the method supports
Yeah, the documentation have lacks about parameters. I've already started to give more information like in the Account page of the doc :
There you can see what is expected has parameter and what is returned. But it is not terminated, because I deccided to stop improving docs until the stable version release. I should release it quicly in few weeks, majors change comming, some methods and endpoint should evolve. So documentation could be definitively wright at this point.
Between this time you could look at the source, if you have any doubt. But if you are coding with a modern IDE you don't have to do it. Generally, modern IDE tell you what are parameters, and what the method return :)
So I used composer to install this package and after numerous warnings about running it as root (I did not, I deleted the vendor directory it made in the root directory) and ran it as an unprivileged user. The code is all there, but the make file refers most functions /vendor/bin/..... which does not exist and was not created. The php functions are all there, but I can't run your test files and I can't seem to use the Namespace you created to access the functions. The Makefile fails for every option but help.
The code looks good and it is just what I was looking for, but I've spent all evening trying to get it installed correctly. The docker tests looked like they were going to work (after installing docker and docker.io) but ended up in a loop saying:
cc -DONIG_ESCAPE_UCHAR_COLLISION=1 -DUChar=OnigUChar -DHAVE_CONFIG_H -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/src/php/ext/mbstring -DPHP_ATOM_INC -I/usr/src/php/ext/mbstring/include -I/usr/src/php/ext/mbstring/main -I/usr/src/php/ext/mbstring -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/src/php/ext/mbstring/libmbfl -I/usr/src/php/ext/mbstring/libmbfl/mbfl -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/mbstring/libmbfl/filters/mbfilter_iso8859_6.c -fPIC -DPIC -o libmbfl/filters/.libs/mbfilter_iso8859_6.o /bin/bash /usr/src/php/ext/mbstring/libtool --mode=compile cc -DONIG_ESCAPE_UCHAR_COLLISION=1 -DUChar=OnigUChar -DHAVE_CONFIG_H -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/src/php/ext/mbstring -DPHP_ATOM_INC -I/usr/src/php/ext/mbstring/include -I/usr/src/php/ext/mbstring/main -I/usr/src/php/ext/mbstring -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/src/php/ext/mbstring/libmbfl -I/usr/src/php/ext/mbstring/libmbfl/mbfl -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/mbstring/libmbfl/filters/mbfilter_iso8859_7.c -o libmbfl/filters/mbfilter_iso8859_7.lo
Over and over.
I am running PHP 7.,4 on Ubuntu Linux 20.04 LTS. Could you provide a little more information than the one line install instruction in the docs? The rest of the docs are good and I think I could really use this if I can figure out the environment to get started.