I am trying to create an ether buy and sell bot on coinbase. They have a truly wonderfull description on their developer page. There is one thing I am missing.
Somehow all functions automatically refer to bitcoin and not to ether. I assume there is a setting to change that in the code but I am not finding or succeeding in this. All examples on their developer page are with bitcoin. For example:
buy_price = client.get_buy_price(currency = 'EUR')
This returns: amount, base and currency. So I noticed I can change the currency. Now I tried to change the base with
buy_price = client.get_buy_price(currency = 'EUR', base = 'ETH')
It still returns BTC (bitcoin) as base.
Hope someone can help me out here.
Try this:
buy_price = client.get_buy_price(currency_pair = 'ETH-USD')
From https://developers.coinbase.com/api/v2#get-exchange-rates
EDIT: the Python API seems not to work. But the raw GET request works, so here's a replacement function for you:
import urllib.request
import json
def myGetBuyPrice(crypto, fiat):
ret = (urllib.request.urlopen("https://api.coinbase.com/v2/prices/"+crypto+"-"+fiat+"/buy").read()).decode("utf-8")
return json.loads(ret)["data"]
print myGetBuyPrice("ETH", "USD")
Related
I'm using the BLP Package as a wrapper around Bloomberg's API.
In the excel bloomberg api, I'm pulling a ticker called FUND_TOTAL_ASSETS. That value can be in any of several currencies. But by adding the "FX=USD" parameter to my BDH() query, it normalizes all the values to USD. Eg. ticker '1671 JP Equity' for 'FUND_TOTAL_ASSETS' field becomes 188.3905USD instead of 25915. =#BDH(E$4,E$6,$B1,$B2,"Dir=V","CDR=5D","Days=A","FX=USD","Dts=H","cols=1;rows=22")
I want to pull up the same data with the same conversion-to-usd operation using blp wrapper. I thought that I can do this via an override parameter.
From the bloomberg api guide I see
so I thought something like the following would work:
xf = bquery.bdh(securities=search, fields=['FUND_TOTAL_ASSETS',],
start_date=dt.date(2022,10,1).strftime("%Y%m%d"),
end_date=dt.datetime.now().date().strftime("%Y%m%d"),
overrides= [('currency','USD')])
It returns the data, but the value remains in the native currency.
I tried the same code as the excel api (FX,USD) but that fails with a bloomberg INVALID_OVERRIDE_FIELD.
The underlying Bloomberg DAPI differentiates between Overrides and Options (but even then there is some confusing overlap).
Typically an Override is applied to a Bloomberg Field. Eg the field FUND_CRNCY_ADJ_TOTAL_ASSETS for 1671 JP Equity has an override of FUND_TOTAL_ASSETS_CRNCY, where you can set the currency. You can see this by typing 1671 JP Equity FLDS in the Terminal and searching the available fields. The overrides are specific to the field.
In addition the HistoricalDataRequest schema also has various options which can be specified. These are elements of the request, in the same way as startDate and endDate. These are the options in the reference to which the OP links. The options apply to all the fields and usually govern how the data is returned (eg date periodicity).
With the blp package, options are supplied as a dictionary of key:value pairs.
This snippet demonstrates how this can be done to specify the currency of the returned data:
from blp import blp
import datetime as dt
bquery = blp.BlpQuery().start()
dtEnd = dt.datetime.now().date()
dtStart = dtEnd - dt.timedelta(days=7)
xf = bquery.bdh(securities='1671 JP Equity', fields=['FUND_TOTAL_ASSETS',],
start_date=dtStart.strftime("%Y%m%d"),
end_date=dtEnd.strftime("%Y%m%d"))
print(xf)
xfUSD = bquery.bdh(securities='1671 JP Equity', fields=['FUND_TOTAL_ASSETS',],
start_date=dtStart.strftime("%Y%m%d"),
end_date=dtEnd.strftime("%Y%m%d"),
options={'currency':'USD'})
print(xfUSD)
The output should reflect the different currency used.
I am trying to get the most recently added coin added to Coingecko. Any ideas which API to use or how to achieve this.
Ideally I am trying to get this in near realtime.
Thanks
I don't think Coingecko provides a direct API to retrieve recently added coins. For your development purposes, you can definitely try web scraping.
https://www.coingecko.com/en/coins/recently_added
You can read the name of the latest coins directly from https://www.coingecko.com/en/coins/recently_added and then use CoinGecko API to search info by name.
In Python:
import requests
# get all coins listed on CoinGecko
coins = requests.get('https://api.coingecko.com/api/v3/coins/list').json()
# extract the name of the latest coins
r = requests.get('https://www.coingecko.com/it/monete/recently_added')
for line in r.text.splitlines():
if '<td class="py-0 coin-name" data-sort=' in line:
name = line[len('<td class="py-0 coin-name" data-sort=')+1:-2]
print(name)
# then search coin in the list retrieved above
for coin in coins:
if coin['name'] == name:
r = requests.get('https://api.coingecko.com/api/v3/coins/'+coin['id'])
print(r.json())
I want to use PDBLP to return historic market cap for a stock, which I can do with the code below:
df = con.bdh('BHP AU Equity', 'CUR_MKT_CAP','20180129', '20180129')
Does anyone know how to include a currency option so that the returned data is in USD? I have tried below using notes from the GitHub site.
df = con.bdh('BHP AU Equity', 'CUR_MKT_CAP','20180129', '20180129',elms=[('Currency','USD')])
But this is not working.
Lets say that i have URL to channel9 movie;
Ex: https://channel9.msdn.com/Series/Office-365-Tips--Tricks/01-Wprowadzenie
And I want to display this movie on my site, and display some information for it ex. duration.
All what I know already is that, I can get list of movies by calling
https://channel9.msdn.com/odata/Entries and skipping it +25 for showing next 25 results.
My implementation right now is something like:
Get first 25 elements from api
Iterate throught them
compare my url with elementFromApi[i].url
Its working but I don't like this solution, it is non elegant and slow as hell. I have no knowledge about the api so i dunno know how to refactor this^.
Maybe someone of You can help me.
PS. I need information from api, embed iframe with given url is not the solution here :)
PS2. Sorry for my english.
I got this requirement through my client and I ended up doing it using RSS! In your use case the URL is https://channel9.msdn.com/Series/Office-365-Tips--Tricks/01-Wprowadzenie - Simply we can read the rss by using the link https://s.ch9.ms/Series/Office-365-Tips--Tricks/rss/mp4 - In PowerShell we can explore the content with the below piece of code
$Sessions = Invoke-Restmethod -Uri 'https://s.ch9.ms/Series/Office-365-Tips--Tricks/rss/mp4' -UseDefaultCredentials
foreach($Session in $Sessions) {
$Duration = [timespan]::FromSeconds($Session.duration)
[pscustomobject]#{
Title = $Session.title
Duration = ("{0:0}:{1:00}:{2:00}" -f ($Duration.Hours , $Duration.Minutes , $Duration.Seconds))
Creator = $Session.creator
"URl(MP3)" = $Session.group.content.url[0]
"URl(MP4)" = $Session.group.content.url[1]
"URl(webm)" = $Session.group.content.url[2]
"URl(MP4High)" = $Session.group.content.url[3]
}
}
Note: Code needs to be improvised!
The same can be achieved using C# - But I am not a certified developer - So , I used PowerShell to meet client requirement.
I'm trying to replace some un-reliable sap scripting we have in place to do an MB01 from a custom goods receipt application. I have come across the .NET connector and it looks like it could do a job for me.
Research has churned up the BAPI called BAPI_GOODSMVT_CREATE but can anyone tell me what parameters might be required to perform this transaction?
I have access to a SAP test environment.
BAPI_GOODSMVT_CREATE accepts a table of values called GOODSMVT_ITEM which contains 121 fields. I'm sure that not all of these fields are required.
Ultimately I guess my question is, what how can I work out which ones are required?
Do you have access to a SAP system? I have recently used this BAPI, and it has quite detailed documentation. To view the documentation, use transaction SE37, and enter the BAPI name. Unfortunately I don't currently have access to a system.
You will have to ask one of your MM/Logistics people to tell you what the movement type (BWART) is, and depending on the config you will need details like material number (MATNR), plant (WERKS), storage location etc.
MB01 is a Post GR for PO transaction, it is an equivalent of GM_Code 01 in MIGO or BAPI_GOODSMVT_CREATE. MIGO transaction is a modern successor for obsolete MB01.
So, as per the BAPI_GOODSMVT_CREATE documentation for GM_Code 01 the following fields are mandatory:
Purchase order
Purchase order item
Movement type
Movement indicator
Quantity in unit of entry
ISO code unit of measurement for unit of entry or
quantity proposal
Here is the sample:
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'.
loop at pcitab.
itab-move_type = pcitab-mvt_type.
itab-mvt_ind = 'B'.
itab-plant = pcitab-plant.
itab-material = pcitab-material.
itab-entry_qnt = pcitab-qty.
itab-move_stloc = pcitab-recv_loc.
itab-stge_loc = pcitab-issue_loc.
itab-po_number = pcitab-pur_doc.
itab-po_item = pcitab-po_item.
concatenate pcitab-del_no pcitab-del_item into itab-item_text.
itab-move_reas = pcitab-scrap_reason.
append itab.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gmhead
goodsmvt_code = gmcode
IMPORTING
goodsmvt_headret = mthead
tables
goodsmvt_item = itab
return = errmsg