MockingMagician / coinbase-pro-sdk

Coinbase Pro API SDK - Communicate easily with the Coinbase Pro API in PHP
https://mockingmagician.github.io/coinbase-pro-sdk/
MIT License
22 stars 8 forks source link

I cannot place a limit order #21

Closed tb100 closed 3 years ago

tb100 commented 3 years ago

My problem:

The limit order feature fails because the tool cannot find LimitOrdertoPlace class

This feature provides an error when executing the complex limit order as listed on the website not sure why it is not found...

MockingMagician commented 3 years ago

Hi @tb100,

Are you the Terry Trusty who is talking to me via email?

Can you provide this issue with your piece of code not working.

From the description it seems to be an import defect, are you using Composer to install the library as I recommended last time?

tb100 commented 3 years ago

yes...i apologize for being a novice.  i am working my way throu the product, but there are these errors that pop up.  maybe not errors just my misunderstanding

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 3:11 am Subject: Re: [MockingMagician/coinbase-pro-sdk] limit order features (#21)

Hi @tb100,Are you the Terry Trusty who is talking to me via email?Can you provide this issue with your piece of code not working.From the description it seems to be an import defect, are you using Composer to install the library as I recommended last time?— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tb100 commented 3 years ago

I am using xampp on windows installed with composer.  i have been able to purchase several items with market orders.  no success yet with limit orders. I am seeking to place orders followed by a limit order and change the limit order as the product price increases

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 3:11 am Subject: Re: [MockingMagician/coinbase-pro-sdk] limit order features (#21)

Hi @tb100,Are you the Terry Trusty who is talking to me via email?Can you provide this issue with your piece of code not working.From the description it seems to be an import defect, are you using Composer to install the library as I recommended last time?— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tb100 commented 3 years ago

$api = CoinbaseFacade::createDefaultCoinbaseApi(    'https://api.pro.coinbase.com',    $_API_KEY,    $_API_SECRET,    $_API_PASS);

/ Start to develop here. Best regards https://php-download.com/ /include 'db_connection.php';$db = OpenCon(); $getaccounts= "N";$getcurrencies = "Y";$placeorder = "Y";$placelimits ="Y";$sellorders = "Y";

//get account informationif($getaccounts= "Y"){ echo 'getting accounts';$accts = $api->accounts()->list();$output='';file_put_contents('file.txt', $output);$i=0;foreach($accts as $myaccounts){$output = print_r($myaccounts, true);file_put_contents('file.txt', $output,FILE_APPEND);}$sql='TRUNCATE TABLE account';$result = mysqli_query($db,$sql);$fh = fopen('file.txt','r');while ($line = fgets($fh)) {  // <... Do your work with the line ...>   $item = 'id';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli="INSERT INTO ACCOUNT(id,currency,balance,holdFunds,availableFunds,isTradingEnabled,profileId) VALUES (";    $sqli=$sqli."'".$item."',"; }    $item = 'currency';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli."'".$item."',"; }   $item = 'balance';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli.$item.","; } $item = 'holdFunds';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli.$item.","; }

 $item = 'availableFunds';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli.$item.","; }  $item = 'isTradingEnabled';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli.$item.","; } $item = 'profileId';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli."'".$item."')"; $profileId= 'YES'; }

if (isset($profileId)){ $result = mysqli_query($db,$sqli); unset($profileId);}

//die;

 }fclose($fh); }//end of get accounts

//this command fails $currencylist =$api->products()->get24hrStats('19d88d23-744c-498b-96bc-63541f326a40');

foreach($currencylist as $listitems){ echo '

';$output = print_r($listitems);echo '
';echo '
';}

echo 'about to place an order';

//Place a market order //$orderToPlace = CoinbaseFacade::createMarketOrderToPlace('buy', 'ANKR-USD', 10.00); //$placedOrder = $api->orders()->placeOrder($orderToPlace);

//$orderToPlace = CoinbaseFacade::createMarketOrderToPlace('buy', 'MKR-USD', 50.00);//$placedOrder = $api->orders()->placeOrder($orderToPlace);

//$placedOrderId =$api->orders()->getOrderById($placedOrder->getId()); //echo $placedOrderID; / public static function createLimitOrderToPlace(        string $side,        string $productId,        float $price,        float $size,        ?string $timeInForce = null,        ?string $cancelAfter = null,        bool $postOnly = false,        ?string $selfTradePrevention = null,        ?string $stop = null,        ?float $stopPrice = null,        ?string $clientOrderId = null    ): LimitOrderToPlace {        return new LimitOrderToPlace(            $side,            $productId,            $price,            $size,            $timeInForce,            $cancelAfter,            $postOnly,            $selfTradePrevention,            $stop,            $stopPrice,            $clientOrderId        );    }     /   //$orderToPlace = CoinbaseFacade::createLimitOrderToPlace('sell','ANKR-USD',.13,5,'' ,'' ,'' ,'' ,'' ,.13,'');/*

$limitOrder = CoinbaseFacade::createLimitOrderToPlace(    sell,    'ANKR-USD',    .13, // Price    5, // Sice    'TIME_IN_FORCE_GOOD_TILL_CANCELED', // The TIF flag    'CANCEL_AFTER_DAY', // A cancel after time    true, // Define if post-only or taker allowed, post_only is disabled by default   'SELF_TRADE_PREVENTION_DECREASE_AND_CANCEL', // The self trade prevention flag,    'Entry', // Direction flag for stop   .13, // Stop price    '132fb6ae-456b-4654-b4e0-d681ac05cea1' // A custom id that you defined (UUID format only)); */

//$placedOrder = $api->orders()->placeOrder($limitOrder);

$db = CloseCon($db); //hEADER("refresh:3");

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 3:11 am Subject: Re: [MockingMagician/coinbase-pro-sdk] limit order features (#21)

Hi @tb100,Are you the Terry Trusty who is talking to me via email?Can you provide this issue with your piece of code not working.From the description it seems to be an import defect, are you using Composer to install the library as I recommended last time?— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

MockingMagician commented 3 years ago

Just for a better understanding, you're code indented a bit and highlighted, I'll take a look on it tonight :

<?php

$api = CoinbaseFacade::createDefaultCoinbaseApi('https://api.pro.coinbase.com', $_API_KEY, $_API_SECRET, $_API_PASS);

/* Start to develop here. Best regards https://php-download.com/ */include 'db_connection.php';$db = OpenCon();
$getaccounts= "N";
$getcurrencies = "Y";
$placeorder = "Y";
$placelimits ="Y";
$sellorders = "Y";

//get account informationif($getaccounts= "Y"){ echo 'getting accounts';$accts = $api->accounts()->list();$output='';file_put_contents('file.txt', $output);$i=0;foreach($accts as $myaccounts){$output = print_r($myaccounts, true);file_put_contents('file.txt', $output,FILE_APPEND);}$sql='TRUNCATE TABLE account';$result = mysqli_query($db,$sql);$fh = fopen('file.txt','r');while ($line = fgets($fh)) {  // <... Do your work with the line ...>   $item = 'id';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ;  $sqli="INSERT INTO ACCOUNT(id,currency,balance,holdFunds,availableFunds,isTradingEnabled,profileId) VALUES (";     $sqli=$sqli."'".$item."',";  }    $item = 'currency';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ;  $sqli=$sqli."'".$item."',";  }   $item = 'balance';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ;  $sqli=$sqli.$item.",";  } $item = 'holdFunds';if (substr($line,5,strlen($item)) == $item){   $strpos = strripos($line,"=>")+2;    $item= substr($line,$strpos) ; $sqli=$sqli.$item.",";  }

$item = 'availableFunds';
if (substr($line,5,strlen($item)) == $item){
    $strpos = strripos($line,"=>")+2;
    $item= substr($line,$strpos);
    $sqli=$sqli.$item.",";
}

$item = 'isTradingEnabled';

if (substr($line,5,strlen($item)) == $item){ 
    $strpos = strripos($line,"=>")+2; 
    $item= substr($line,$strpos) ; $sqli=$sqli.$item.",";  
}

$item = 'profileId';
if (substr($line,5,strlen($item)) == $item){ 
    $strpos = strripos($line,"=>")+2; 
    $item= substr($line,$strpos); 
    $sqli=$sqli."'".$item."')"; $profileId= 'YES';  
}

if (isset($profileId)){  $result = mysqli_query($db,$sqli);  unset($profileId);}

//die;

}
fclose($fh);
}//end of get accounts

//this command fails
$currencylist =$api->products()->get24hrStats('19d88d23-744c-498b-96bc-63541f326a40');

foreach($currencylist as $listitems){ echo '<pre>';$output = print_r($listitems);echo '</pre>';echo '<br>';}

echo 'about to place an order';

//Place a market order
//$orderToPlace = CoinbaseFacade::createMarketOrderToPlace('buy', 'ANKR-USD', 10.00);
//$placedOrder = $api->orders()->placeOrder($orderToPlace);

//$orderToPlace = CoinbaseFacade::createMarketOrderToPlace('buy', 'MKR-USD', 50.00);//$placedOrder = $api->orders()->placeOrder($orderToPlace);

//$placedOrderId =$api->orders()->getOrderById($placedOrder->getId()); //echo $placedOrderID; /* public static function createLimitOrderToPlace(        string $side,        string $productId,        float $price,        float $size,        ?string $timeInForce = null,        ?string $cancelAfter = null,        bool $postOnly = false,        ?string $selfTradePrevention = null,        ?string $stop = null,        ?float $stopPrice = null,        ?string $clientOrderId = null    ): LimitOrderToPlace {        return new LimitOrderToPlace(            $side,            $productId,            $price,            $size,            $timeInForce,            $cancelAfter,            $postOnly,            $selfTradePrevention,            $stop,            $stopPrice,            $clientOrderId        );    }     */  
//$orderToPlace = CoinbaseFacade::createLimitOrderToPlace('sell','ANKR-USD',.13,5,'' ,'' ,'' ,'' ,'' ,.13,'');/*

$limitOrder = CoinbaseFacade::createLimitOrderToPlace(    sell,    'ANKR-USD',    .13, // Price    5, // Sice    'TIME_IN_FORCE_GOOD_TILL_CANCELED', // The TIF flag    'CANCEL_AFTER_DAY', // A cancel after time    true, // Define if post-only or taker allowed, post_only is disabled by default   'SELF_TRADE_PREVENTION_DECREASE_AND_CANCEL', // The self trade prevention flag,    'Entry', // Direction flag for stop   .13, // Stop price    '132fb6ae-456b-4654-b4e0-d681ac05cea1' // A custom id that you defined (UUID format only));
*/

//$placedOrder = $api->orders()->placeOrder($limitOrder);

$db = CloseCon($db);
//hEADER("refresh:3");
MockingMagician commented 3 years ago

In a quick read, I've already spotted that :

$limitOrder = CoinbaseFacade::createLimitOrderToPlace( sell, 'ANKR-USD', .13, // Price 5, // Sice 'TIME_IN_FORCE_GOOD_TILL_CANCELED', // The TIF flag 'CANCEL_AFTER_DAY', // A cancel after time true, // Define if post-only or taker allowed, post_only is disabled by default 'SELF_TRADE_PREVENTION_DECREASE_AND_CANCEL', // The self trade prevention flag, 'Entry', // Direction flag for stop .13, // Stop price '132fb6ae-456b-4654-b4e0-d681ac05cea1' // A custom id that you defined (UUID format only));

sell should be a string

MockingMagician commented 3 years ago

Also, I've spotted that line too:

/* Start to develop here. Best regards https://php-download.com/ */include 'db_connection.php';$db = OpenCon();

Are you sure you are using composer for library import ??? Cause when I see this kind of lines, I have serious doubts about it.

tb100 commented 3 years ago

composer could not find pcntl.dll {    "name": "mocking-magician/coinbase-pro-sdk",    "type": "library",    "description": "Library for coinbase pro API calls",    "keywords": [        "coinbase",        "coinbase pro",        "sdk",        "crypto",        "exchange",        "bitcoin",        "etherum",        "blockchain"    ],    "homepage": "https://github.com/MockingMagician/coinbase-pro-sdk",    "license": "MIT",    "authors": [        {            "name": "Marc MOREAU",            "email": @.**"        }    ],    "autoload": {        "psr-4": {            "MockingMagician\CoinbaseProSdk\": "src"        }    },    "autoload-dev": {        "psr-4": {            "MockingMagician\CoinbaseProSdk\Tests\CommonHelpers\": "tests/common_helpers",            "MockingMagician\CoinbaseProSdk\Tests\Func\": "tests/func",            "MockingMagician\CoinbaseProSdk\Tests\Unit\": "tests/unit",            "MockingMagician\CoinbaseProSdk\Tests\Exp\": "tests/experimental"        }    },    "config": {        "sort-packages": true    },    "require": {        "amphp/websocket-client": "^1.0",        "ext-json": "",        "ext-openssl": "",        "guzzlehttp/guzzle": "^6.0 | ^7.0",        "php": ">=7.2",        "psr/http-client": "^1.0",        "symfony/yaml": "^4.0"    },    "require-dev": {        "ext-pcntl": "",        "friendsofphp/php-cs-fixer": "^2.16",        "phpstan/phpstan": "^0.12.42",        "phpunit/phpunit": "^7.5",        "vlucas/phpdotenv": "^4.0",        "symfony/var-dumper": "^4.0"    }}

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 3:44 am Subject: Re: [MockingMagician/coinbase-pro-sdk] I cannot place a limit order (#21)

Also, I've spotted that line too:/ Start to develop here. Best regards https://php-download.com/ /include 'db_connection.php';$db = OpenCon();Are you sure you are using composer for library import ??? Cause when I see this kind of lines, I have serious doubts about it.— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tb100 commented 3 years ago

Limit order is now working.  problem was that I did not understand the acceptable values for the parameters.  

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 3:40 am Subject: Re: [MockingMagician/coinbase-pro-sdk] I cannot place a limit order (#21)

In a quick read, I always spotted that :$limitOrder = CoinbaseFacade::createLimitOrderToPlace( sell, 'ANKR-USD', .13, // Price 5, // Sice 'TIME_IN_FORCE_GOOD_TILL_CANCELED', // The TIF flag 'CANCEL_AFTER_DAY', // A cancel after time true, // Define if post-only or taker allowed, post_only is disabled by default 'SELF_TRADE_PREVENTION_DECREASE_AND_CANCEL', // The self trade prevention flag, 'Entry', // Direction flag for stop .13, // Stop price '132fb6ae-456b-4654-b4e0-d681ac05cea1' // A custom id that you defined (UUID format only));sell should be a string— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

MockingMagician commented 3 years ago

composer could not find pcntl.dll

Hi @tb100 ,

This error is due to missing dependencies on your machine, you can install if you ignore dev dependencies that are not required on production, use command as is composer require --no-dev mocking-magician/coinbase-pro-sdk

tb100 commented 3 years ago

Thank you for your assistance.  I have been successful in placing market orders and limit orders.  Still need the ability to obtain last price data.

this command does not work as yet>

$productinfo = $api->products()->get24hrStats('19d88d23-744c-498b-96bc-63541f326a40');

Regards,Terry Trusty443.506.4204

-----Original Message----- From: 2M @.> To: MockingMagician/coinbase-pro-sdk @.> Cc: tb100 @.>; Mention @.> Sent: Tue, Apr 13, 2021 1:04 pm Subject: Re: [MockingMagician/coinbase-pro-sdk] I cannot place a limit order (#21)

composer could not find pcntl.dll Hi @tb100 ,This error is due to missing dependencies on your machine, you can install if you ignore dev dependencies that are not required on production, use command as is composer require --no-dev mocking-magician/coinbase-pro-sdk— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

MockingMagician commented 3 years ago

$productinfo = $api->products()->get24hrStats('19d88d23-744c-498b-96bc-63541f326a40');

Hi @tb100 ,

You've spotted a lack in documentation, it is not a uuid like 19d88d23-744c-498b-96bc-63541f326a40 to pass as parameter but the product id like BTC-USD

I'm going to modify the doc quickly so that it reflects better the reality

MockingMagician commented 3 years ago

Hi @tb100 , documentation is now updated :clap: Commit 1012842