GithubHelp home page GithubHelp logo

invertee / coinbasepro-powershell Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 6.0 73 KB

Powershell module for the CoinbasePro API.

License: MIT License

PowerShell 100.00%
coinbase-pro gdax powershell powershell-module

coinbasepro-powershell's People

Contributors

invertee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

coinbasepro-powershell's Issues

Get-CoinbaseProAccount (plural or not plural?)

On this page, https://github.com/Invertee/CoinbasePro-Powershell, the cmdlet is singular: Get-CoinbaseProAccount. But in the module, it's plural: Get-CoinbaseProAccounts. To be consistent, however, perhaps Get-CoinbaseAccount and Get-CoinbaseProAccounts should both be singular (or both plural). I'm still learning what they do. At least the documentation on GitHub and the cmdlet are not consistent and I thought you'd like to know. Thank you.

Valid CmdLets

Get-Help Get-Coinbase* | Sort Name | Select Name

Name

Get-CoinbaseAccount
Get-CoinbaseAccountHistory
Get-CoinbaseAccountHolds
Get-CoinbaseAccounts
Get-CoinbaseCurrencies
Get-CoinbaseFills
Get-CoinbaseOrder
Get-CoinbaseOrders
Get-CoinbaseProAccountHistory
Get-CoinbaseProAccounts
Get-CoinbaseProCurrencies
Get-CoinbaseProductOrderBook
Get-CoinbaseProducts
Get-CoinbaseProductStats
Get-CoinbaseProductTicker
Get-CoinbaseProductTrades
Get-CoinbaseProFees
Get-CoinbaseProFills
Get-CoinbaseProOrder
Get-CoinbaseProOrders
Get-CoinbaseProPaymentMethods
Get-CoinbaseProProductOrderBook
Get-CoinbaseProProducts
Get-CoinbaseProProductStats
Get-CoinbaseProProductTicker
Get-CoinbaseProProductTrades
Get-CoinbaseProTime
Get-CoinbaseTime

There is no Runspace available to run scripts in this thread

I have done a script that use Get-CoinbaseProProductTicker every 15 sec.

Don't know if it matters. but the script and two other functions inside, one of those function that are nested inside the script is the Get-CoinbaseProProductTicker.

The script can sometimes run between 1-2 hours before the module crash, and it end up with errors and all the coinbase functions not working.

I tried to optimize the code in my script to limit the API calls, and also make sure no memory leaks was done.
when the issue happens, i cannot remove-module or import-module, and trying to import specific functions, result in the thread problem i never seen before in Powershell

When I try to import module
PSMessageDetails :
Exception : System.Management.Automation.RuntimeException: Unable to import Coinbase Pro products & currencies.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject : Unable to import Coinbase Pro products & currencies.
CategoryInfo : OperationStopped: (Unable to impor...s & currencies.:String) [], RuntimeException
FullyQualifiedErrorId : Unable to import Coinbase Pro products & currencies.
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at , C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\CoinbasePro-Powershell.psm1: line 47
at , : line 1
PipelineIterationInfo : {}

PSMessageDetails :
Exception : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $true
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
TargetObject : System.Net.HttpWebRequest
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Invoke-CoinbaseProRequest, C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\Functions\Invoke-CoinbaseRequest.ps1: line 23
at Get-CoinbaseProCurrencies, C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\Functions\Public\Get-CoinbaseProCurrencies.ps1: line 16
at , C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\CoinbasePro-Powershell.psm1: line 44
at , : line 1
PipelineIterationInfo : {}

PSMessageDetails :
Exception : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $true
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
TargetObject : System.Net.HttpWebRequest
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Invoke-CoinbaseProRequest, C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\Functions\Invoke-CoinbaseRequest.ps1: line 23
at Get-CoinbaseProProducts, C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\Functions\Public\Get-CoinbaseProProducts.ps1: line 17
at , C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\CoinbasePro-Powershell.psm1: line 43
at , : line 1
PipelineIterationInfo : {}

When i try one of the command
Exception : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $true at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() TargetObject : System.Net.HttpWebRequest CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at Invoke-CoinbaseProRequest, <No file>: line 23 at Get-CoinbaseProProductTicker, <No file>: line 16 at <ScriptBlock>, <No file>: line 1 PipelineIterationInfo : {}

Get-CoinbaseProductTicker fails to return the price of many trading pairs

For starters, it appears the only valid ProdcutID values this commandlet will accept are:

BTC-GBP,BTC-EUR,ETH-BTC,ETH-EUR,LTC-BTC,LTC-EUR,LTC-USD,ETH-USD,BTC-USD,BCH-USD

But Coinbase has more products. Get-CoinbaseProducts | Select ID | Sort ID provides these prodcut IDs:

id

BAT-USDC
BCH-BTC
BCH-EUR
BCH-GBP
BCH-USD
BTC-EUR
BTC-GBP
BTC-USD
BTC-USDC
CVC-USDC
DAI-USDC
DNT-USDC
ETC-BTC
ETC-EUR
ETC-GBP
ETC-USD
ETH-BTC
ETH-EUR
ETH-GBP
ETH-USD
ETH-USDC
GNT-USDC
LOOM-USDC
LTC-BTC
LTC-EUR
LTC-GBP
LTC-USD
MANA-USDC
MKR-USDC
ZEC-USDC
ZIL-USDC
ZRX-BTC
ZRX-EUR
ZRX-USD

If I run each one of these, most will fail:

Get-CoinbaseProductTicker -ProductID BAT-USDC
Get-CoinbaseProductTicker -ProductID BCH-BTC
Get-CoinbaseProductTicker -ProductID BCH-EUR
Get-CoinbaseProductTicker -ProductID BCH-GBP
Get-CoinbaseProductTicker -ProductID BCH-USD
Get-CoinbaseProductTicker -ProductID BTC-EUR
Get-CoinbaseProductTicker -ProductID BTC-GBP
Get-CoinbaseProductTicker -ProductID BTC-USD
Get-CoinbaseProductTicker -ProductID BTC-USDC
Get-CoinbaseProductTicker -ProductID CVC-USDC
Get-CoinbaseProductTicker -ProductID DAI-USDC
Get-CoinbaseProductTicker -ProductID DNT-USDC
Get-CoinbaseProductTicker -ProductID ETC-BTC
Get-CoinbaseProductTicker -ProductID ETC-EUR
Get-CoinbaseProductTicker -ProductID ETC-GBP
Get-CoinbaseProductTicker -ProductID ETC-USD
Get-CoinbaseProductTicker -ProductID ETH-BTC
Get-CoinbaseProductTicker -ProductID ETH-EUR
Get-CoinbaseProductTicker -ProductID ETH-GBP
Get-CoinbaseProductTicker -ProductID ETH-USD
Get-CoinbaseProductTicker -ProductID ETH-USDC
Get-CoinbaseProductTicker -ProductID GNT-USDC
Get-CoinbaseProductTicker -ProductID LOOM-USDC
Get-CoinbaseProductTicker -ProductID LTC-BTC
Get-CoinbaseProductTicker -ProductID LTC-EUR
Get-CoinbaseProductTicker -ProductID LTC-GBP
Get-CoinbaseProductTicker -ProductID LTC-USD
Get-CoinbaseProductTicker -ProductID MANA-USDC
Get-CoinbaseProductTicker -ProductID MKR-USDC
Get-CoinbaseProductTicker -ProductID ZEC-USDC
Get-CoinbaseProductTicker -ProductID ZIL-USDC
Get-CoinbaseProductTicker -ProductID ZRX-BTC
Get-CoinbaseProductTicker -ProductID ZRX-EUR
Get-CoinbaseProductTicker -ProductID ZRX-USD

How do I get pricing information for the trading pairs that fail?

Bad Request. Invalid request format

Hello,
Thank you for making this. I'm using 0.8.1, buying and selling return. Thanks for the help!

New-CoinbaseProMarketOrder -ProductID LINK-USD -Side buy -Funds 5
New-CoinbaseProMarketOrder -Side sell -ProductID ETH-USD -Size 0.00368652

Invoke-CoinbaseProRequest : Bad Request. Invalid request format At C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.8.1\Functions\Private\New-CoinbaseProMarketOrder.ps1:52 char:17 $response = Invoke-CoinbaseProRequest $api ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CoinbaseProRequest
image

Can't get Accounts

When invoking "Get-CoinbaseProAccounts" I get this:

`Invoke-CoinbaseProRequest : Bad Request. Invalid request format
En C:\Program Files\WindowsPowerShell\Modules\CoinbasePro-Powershell\0.7.6\Functions\Private\Get-CoinbaseProAccounts.ps1:
19 Carácter: 17

  • $response = Invoke-CoinbaseProRequest $api
    
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CoinbaseProRequest`

Any clues?

Pagination (-Before and -After)

Either I am unable to figure out how to use -Before and -After (I think they make use of the Coinbase Pro API Pagination at https://docs.pro.coinbase.com/#pagination), or it's not working properly.

Objective:
Retrieve all of my Fills. The quantity of fills exceeds the default -Limit 100.

Testing -Before:
Here's a test. I'm attempting to retrieve the five most recent BTC-USD fills, then the next 5, then the next 5. The result should be the 15 most recent BTC-USD fills.

# Get the five most recent BTC-USD fills (1-5)
Get-CoinbaseProFills -APIKey $APIKeyViewOnly -APISecret $APISecretViewOnly -APIPhrase $APIPhraseViewOnly -ProductID BTC-USD -Limit 5 | Format-Table created_at, trade_id -AutoSize

created_at               trade_id
----------               --------
2020-01-23T12:00:42.78Z  81616182
2020-01-23T02:10:28.494Z 81597680
2020-01-21T19:41:42.511Z 81540634
2020-01-19T11:03:26.573Z 81433806
2020-01-19T11:01:54.112Z 81431376


# Get the next 5 most recent BTC-USD fills (6-10)
Get-CoinbaseProFills -APIKey $APIKeyViewOnly -APISecret $APISecretViewOnly -APIPhrase $APIPhraseViewOnly -ProductID BTC-USD -Limit 5 -Before 1 | Format-Table created_at, trade_id -AutoSize
 
created_at               trade_id
----------               --------
2017-08-02T13:37:08.414Z 18838454
2017-07-30T05:45:22.854Z 18731934
2017-07-30T05:38:29.166Z 18730012
2017-07-26T06:45:26.241Z 18618952
2017-07-25T19:01:58.041Z 18598131



# Get the next 5 most recent BTC-USD fills (11-15)
Get-CoinbaseProFills -APIKey $APIKeyViewOnly -APISecret $APISecretViewOnly -APIPhrase $APIPhraseViewOnly -ProductID BTC-USD -Limit 5 -Before 2 | Format-Table created_at, trade_id -AutoSize
 
created_at               trade_id
----------               --------
2017-08-02T13:37:08.414Z 18838454
2017-07-30T05:45:22.854Z 18731934
2017-07-30T05:38:29.166Z 18730012
2017-07-26T06:45:26.241Z 18618952
2017-07-25T19:01:58.041Z 18598131

Unexpected Results:
The results above are not what I expected.

For the Get-CoinbaseProFills, -Before is not used. The five most recent Fills are retrieved (fills 1 to 5) that occurred in 2020. This works as expected.

For the next Get-CoinbaseProFills, I add -Before 1. My expectation is that the function retrieves the next five fills (fills 6 to 10). Instead, the function retrieves the first 5 fills I ever made on Coinbase in 2017.

For my third Get-CooinbaseProFills test, I add -Before 2. Now my expectation is that the function would retrieve the five fills that I made in 2017. If so, then I could retrieve all of my fills by working backwards. Instead, the function again retrieves the first 5 fills I ever made on Coinbase in 2017.

Is Pagination working correctly and I'm just not smart enough to figure it out?
I've tried several other test usages of -Before and -After. Either pagination is not working correctly, or I'm unable to figure out how to properly use these pagination options.

At best, I'm able to retrieve my 100 most recent fills and my first 100 fills for a total of 200 unique fills. If pagination isn't broken, would you kindly provide me an example of how to retrieve the fills in the middle (before and after the first and last 100 fills)?

Thank you.

Get-CoinbaseProducts could use a -Filter

Get-CoinbaseProdcuts returns all products. To filter, I have to pipe to a Where-Object. I'd like to do more just within the commadlet.

This Works: Get a list of USD trading pairs (but exclude USDC trading pairs)

Get-CoinbaseProducts | Where {$.ID -like "*-USD" -and $.ID -notlike "*-USDC"} | Sort ID | FT -AutoSize

Wish list: But these options would be nice to have

Get-CoinbaseProducts -Filter {ID -like "-USD" -and ID -notlike "-USDC"}
Get-CoinbaseProdcuts -ID BTC-USD,ETH-USD,LTC-USD

Can´t connect to new created API because of "wrong" API Key

Hi,
i just startet new with this API and the Powershell extension. First of all, thanks for creating it!
Yesterday i created my API for Coinbase and Pro. Now i want to connect.
Created variables for $ApiKey, $ApiPassphrase and $ApiSecret (values are correct)
Used command:
$Account = Get-CoinbaseAccounts -APIKey $APIKey -APISecret $APISecret -APIPhrase $APIPassphrase

Result:
Invoke-CoinbaseProRequest : Unauthorized. Invalid API Key
In D:_GIT\CoinbasePro-Powershell\Functions\Private\Get-CoinbaseAccounts.ps1:17 Zeichen:17
$response = Invoke-CoinbaseProRequest $api
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CoinbaseProRequest

What do i make wrong? Any help would be nice.
Thanks

Code Samples (not an issue): A thread to share and document scripts as I learn this module

If it is inappropriate for me to create a thread here that lets me document and share some scripts I've written using your module, please let me know and I'll stop. Optionally, would enabling the Wiki feature for this GitHub module be a better option? Or would you prefer I fork your module and use the Wiki or Issues section within my own fork of this module?

Basically, I want to contribute to your module and share in my own small way without being a nuisance. So let me know if I'm being a nuisance by creating a new Issue called Code Samples. :-)

My first set of code samples that I'll post here were written to get me familiar with your module and the data it retrieves from Coinbase's API. All they do is create variables and arrays that I might use in future scripts that will perform more functionality.

These scripts are variable overkill, because they each also create an array. I start with just the Public functions you created. When done, you'll end up with almost 2,400 $CBP* variables.

Public Functions

Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
Get-CoinbaseProCurrencies         Function  CoinbasePro-Powershell    ...
Get-CoinbaseProPaymentMethods     Function  CoinbasePro-Powershell    ...
Get-CoinbaseProProductOrderBook   Function  CoinbasePro-Powershell    ...
Get-CoinbaseProProducts           Function  CoinbasePro-Powershell    ...
Get-CoinbaseProProductStats       Function  CoinbasePro-Powershell    ...
Get-CoinbaseProProductTicker      Function  CoinbasePro-Powershell    ...
Get-CoinbaseProProductTrades      Function  CoinbasePro-Powershell    ...
Get-CoinbaseProTime               Function  CoinbasePro-Powershell    ...                                                                                                          

Thanks for the great start.

I love this. I'd like to make some suggestions, ask questions, and submit some tickets. Please know I'm grateful for what you've already created and do not expect anything in return. But if you are interested in working on this more, here are my thoughts in a few issues I'll soon open.

Piping Get-CoinbaseProducts to Get-CoinbaseProductTicker

I'd like to be able to pipe values to Get-CoinbaseProductTicker. Assuming that Get-CoinbaseProductTicker will eventually report pricing for all trading pairs, I'd like to pipe IDs to it. I'd like for the following examples to work.

Get-CoinbaseProducts | Get-CoinbaseProductTicker
Get-CoinbaseProducts | Get-CoinbaseProductTicker -ProdcutID $_.ID

$Products = Get-CoinbaseProducts | Where-Object {$_.ID -like "BTC-*"}
$Products.ID =Get-CoinbaseProductTicker

Pull Requests

Hey, @Invertee are you open to pull requests. I've started to use this for a side project and have a couple issues that I want to fix.

Seeking -Examples

Could use some help files with examples of what would work. Something like:

Get-Help Get-CoinbaseProductTicker -Examples

Example 1: Get the ticker price of a single trading pair

PS C:>Get-CoinbaseProductTicker -ProductID BTC-USD

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.