MWS: ListPrice confusion - amazon-mws

I am really confused with one API result.
API Request: GetMatchingProductForIdRequest / IdType ASIN
Market: DE A1PA6795UKMFR9
ASIN: B001B603YU
API Response ListPrice: €81.99
Amazon URL: http://www.amazon.de/gp/product/B001B603YU
Price on Amazon: €44.17
Its the only product from a large list where the price doesn't match.

I think you misunderstood this API. ListPrice means RRP = recommended retail price (in German UVP = unverbindliche Preisempfehlung). This is not the price you can buy the product on amazon. See API call GetCompetitivePricingForASIN to get the prices you whant.
Example:
<?xml version="1.0"?>
<GetCompetitivePricingForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetCompetitivePricingForASINResult ASIN="B001B603YU" status="Success">
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A1PA6795UKMFR9</MarketplaceId>
<ASIN>B001B603YU</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="false" condition="New" subcondition="New">
<CompetitivePriceId>1</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>EUR</CurrencyCode>
<Amount>44.13</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>EUR</CurrencyCode>
<Amount>44.13</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>EUR</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
</CompetitivePrice>
</CompetitivePrices>
<NumberOfOfferListings>
<OfferListingCount condition="Any">15</OfferListingCount>
<OfferListingCount condition="New">15</OfferListingCount>
</NumberOfOfferListings>
</CompetitivePricing>
<SalesRankings>
<SalesRank>
<ProductCategoryId>pet_products_display_on_website</ProductCategoryId>
<Rank>21552</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>470605031</ProductCategoryId>
<Rank>453</Rank>
</SalesRank>
</SalesRankings>
</Product>
</GetCompetitivePricingForASINResult>
<ResponseMetadata>
<RequestId>aa089a13374fcd2ad</RequestId>
</ResponseMetadata>
</GetCompetitivePricingForASINResponse>

Related

HOW TO FILTER DJANGO QUERYSETS WITH MULTIPLE AGGREGATIONS

Lets say I have a django model table
class Table(models.Model):
name = models.CharField()
date_created = models.DatetimeField()
total_sales = models.DecimalField()
some data for context
Name
date-created
total-sales
a
2020-01-01
200
b
2020-02-01
300
c
2020-04-01
400
*
**********
***
c
2020-12-01
1000
c
2020-12-12
500
now I want to filter an aggregate of
total_yearly_sales = 10500
current month being December
total_monthly_sales = 1500
daily_sales
total_daily_sales = 500
also do a Group by by name
models.Table.objects.values('Name').annotate(Sum('total-sales')).order_by()
I want to do this in one query(one db hit)
Hence the query should generate
total_yearly_sales
total_monthly_sales
total_daily_sales
total_sales_grouped_by_name ie {a:200, b:300, c:1900}
I know this is too much to ask. Hence let me express my immense gratitude and thanks for having a look at this.
cheers
The above queries I can generate them individually like so
today = timezone.now().date()
todays_sales = models.Table.filter(date_created__date__gte=today, date_created___date__lte=today).aggregate(Sum('total_sales'))
=> 500
monthly_sales(this month) = models.Table.objects.filter(date_created__year=today.year, date_created__month=today.month).aggregate(Sum('total_sales'))
=>10500
total_yearly_sales = models.Table.objects.filter(date_created__year=today.year).aggregate(Sum('total_sales')) => 10500

display the extensions of a church in relation to the location or the address entered by the user with django

someone can help me?
I am creating a website for my church with django with an extension menu that will represent all church extensions worldwide. my problem is that i want a system that will show the user churches near him or in his area. put a text box to ask for his current address and show him all the parishes near him and their locations. except that the extensions are classified as follows: country > Province > city > Commune > district > parish
at my first reflection I tried to create the following models
from django.db import models
# Create your models here.
class Pays(models.Model):
Ctn = (
('Africa', 'Africa'),
('America','America'),
('Asia','Asia'),
('Europe','Europe'),
)
STATUS = (
('True', 'True'),
('False','False'),
)
name=models.CharField(max_length=100)
continent=models.CharField(max_length=50, default="Afrique")
slug=models.SlugField()
date_created=models.DateTimeField(auto_now_add=True)
status=models.CharField( choices=STATUS, max_length=100)
def __str__(self):
return self.name
class Church(models.Model):
STATUT = (
('En Service', 'En Service'),
('Fermée','Fermée'),
)
CAT = (
('Siège', 'Siège'),
('Eglise centrale', 'Eglise centrale'),
('Eglise locale','Eglise locale'),
)
name=models.CharField(max_length=100)
address=models.CharField(max_length=255)
Town=models.CharField(max_length=150)
Contry=models.ForeignKey(Pays,on_delete=models.CASCADE )
description=models.CharField(max_length=255)
effectif=models.IntegerField()
slug=models.SlugField()
date_created=models.DateTimeField(auto_now_add=True)
statut=models.CharField(choices=STATUT,max_length=100)
category=models.CharField(choices=CAT,max_length=100)
def __str__(self):
return self.name
but the problem is when I want to display a parish which is in a district of a municipality of a city of a province of a country of a determined continent example: continent= africa, country=DRC (democratic republic of congo), province= Kantanga, city=Lubumbashi, commune=rwashi and parish=bel'air 1.
I can't manage to build a django query that will return the parish to me in this order that I just showed above

Parsing XML in SQL Server with duplicate tags

Here is the DDL and table structure of the XML that I am working on. I'm able to parse a lot of the basic XML now but now I have a tag that repeats several times with this same name and then with the same child tags. I would like to get a separate column for each combination of parent and child tags and somehow have different names for each one of those. Here is the tag that repeats several times along with the four child tags.
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>338351</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Equipment</Desc>
</ProgSrvcAccomActyOtherGrp>
Again, thank you!
-- DDL and sample data population, start
DECLARE #tbl TABLE (ID INT IDENTITY PRIMARY KEY, XMLData XML);
INSERT INTO #tbl (XMLData) VALUES
('<?xml version="1.0" encoding="utf-8"?>
<Return returnVersion="2019v5.0" xmlns="http://www.irs.gov/efile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ReturnHeader binaryAttachmentCnt="0">
<ReturnTs>2021-02-11T21:27:00-07:00</ReturnTs>
<TaxPeriodEndDt>2020-06-30</TaxPeriodEndDt>
<ReturnTypeCd>990</ReturnTypeCd>
<TaxPeriodBeginDt>2019-07-01</TaxPeriodBeginDt>
<Filer>
<EIN>936022772</EIN>
<BusinessName>
<BusinessNameLine1Txt>OREGON STATE UNIVERSITY FOUNDATION</BusinessNameLine1Txt>
</BusinessName>
<BusinessNameControlTxt>OREG</BusinessNameControlTxt>
<PhoneNum>5417374218</PhoneNum>
<USAddress>
<AddressLine1Txt>4238 SW Research Way</AddressLine1Txt>
<CityNm>Corvallis</CityNm>
<StateAbbreviationCd>OR</StateAbbreviationCd>
<ZIPCd>973331068</ZIPCd>
</USAddress>
</Filer>
<BusinessOfficerGrp>
<PersonNm>Steven Schauble</PersonNm>
<PersonTitleTxt>Vice President & CFO</PersonTitleTxt>
<PhoneNum>5417377499</PhoneNum>
<SignatureDt>2021-02-12</SignatureDt>
</BusinessOfficerGrp>
<FilingSecurityInformation>
<IPAddress>
<IPv4AddressTxt>73.25.170.86</IPv4AddressTxt>
</IPAddress>
</FilingSecurityInformation>
<TaxYr>2019</TaxYr>
<BuildTS>2021-01-29 14:40:06Z</BuildTS>
</ReturnHeader>
<ReturnData documentCnt="11">
<IRS990 documentId="R000001" referenceDocumentId="R000010" softwareId="19009572" softwareVersionNum="v1.00">
<PrincipalOfficerNm>Shawn Scoville</PrincipalOfficerNm>
<USAddress>
<AddressLine1Txt>4238 SW Research Way</AddressLine1Txt>
<CityNm>Corvallis</CityNm>
<StateAbbreviationCd>OR</StateAbbreviationCd>
<ZIPCd>973331068</ZIPCd>
</USAddress>
<GrossReceiptsAmt>336252171</GrossReceiptsAmt>
<GroupReturnForAffiliatesInd>0</GroupReturnForAffiliatesInd>
<Organization501c3Ind>X</Organization501c3Ind>
<WebsiteAddressTxt>www.osufoundation.org</WebsiteAddressTxt>
<TypeOfOrganizationCorpInd>X</TypeOfOrganizationCorpInd>
<FormationYr>1947</FormationYr>
<LegalDomicileStateCd>OR</LegalDomicileStateCd>
<ActivityOrMissionDesc>The OSU Foundation partners with Oregon State University to engage our community, inspire investment, and steward resources to enhance the university''s excellence and impact.</ActivityOrMissionDesc>
<VotingMembersGoverningBodyCnt>39</VotingMembersGoverningBodyCnt>
<VotingMembersIndependentCnt>36</VotingMembersIndependentCnt>
<TotalEmployeeCnt>183</TotalEmployeeCnt>
<TotalVolunteersCnt>39</TotalVolunteersCnt>
<TotalGrossUBIAmt>0</TotalGrossUBIAmt>
<NetUnrelatedBusTxblIncmAmt>-568422</NetUnrelatedBusTxblIncmAmt>
<PYContributionsGrantsAmt>74724577</PYContributionsGrantsAmt>
<CYContributionsGrantsAmt>93028322</CYContributionsGrantsAmt>
<PYProgramServiceRevenueAmt>510476</PYProgramServiceRevenueAmt>
<CYProgramServiceRevenueAmt>1338931</CYProgramServiceRevenueAmt>
<PYInvestmentIncomeAmt>31179603</PYInvestmentIncomeAmt>
<CYInvestmentIncomeAmt>20095789</CYInvestmentIncomeAmt>
<PYOtherRevenueAmt>21307467</PYOtherRevenueAmt>
<CYOtherRevenueAmt>17916447</CYOtherRevenueAmt>
<PYTotalRevenueAmt>127722123</PYTotalRevenueAmt>
<CYTotalRevenueAmt>132379489</CYTotalRevenueAmt>
<PYGrantsAndSimilarPaidAmt>0</PYGrantsAndSimilarPaidAmt>
<CYGrantsAndSimilarPaidAmt>0</CYGrantsAndSimilarPaidAmt>
<PYBenefitsPaidToMembersAmt>0</PYBenefitsPaidToMembersAmt>
<CYBenefitsPaidToMembersAmt>0</CYBenefitsPaidToMembersAmt>
<PYSalariesCompEmpBnftPaidAmt>31629477</PYSalariesCompEmpBnftPaidAmt>
<CYSalariesCompEmpBnftPaidAmt>31621515</CYSalariesCompEmpBnftPaidAmt>
<PYTotalProfFndrsngExpnsAmt>0</PYTotalProfFndrsngExpnsAmt>
<CYTotalProfFndrsngExpnsAmt>0</CYTotalProfFndrsngExpnsAmt>
<CYTotalFundraisingExpenseAmt>17996976</CYTotalFundraisingExpenseAmt>
<PYOtherExpensesAmt>81790834</PYOtherExpensesAmt>
<CYOtherExpensesAmt>92045058</CYOtherExpensesAmt>
<PYTotalExpensesAmt>113420311</PYTotalExpensesAmt>
<CYTotalExpensesAmt>123666573</CYTotalExpensesAmt>
<PYRevenuesLessExpensesAmt>14301812</PYRevenuesLessExpensesAmt>
<CYRevenuesLessExpensesAmt>8712916</CYRevenuesLessExpensesAmt>
<TotalAssetsBOYAmt>816417531</TotalAssetsBOYAmt>
<TotalAssetsEOYAmt>833330950</TotalAssetsEOYAmt>
<TotalLiabilitiesBOYAmt>89894344</TotalLiabilitiesBOYAmt>
<TotalLiabilitiesEOYAmt>94381459</TotalLiabilitiesEOYAmt>
<NetAssetsOrFundBalancesBOYAmt>726523187</NetAssetsOrFundBalancesBOYAmt>
<NetAssetsOrFundBalancesEOYAmt>738949491</NetAssetsOrFundBalancesEOYAmt>
<InfoInScheduleOPartIIIInd>X</InfoInScheduleOPartIIIInd>
<MissionDesc>MISSION: The OSU Foundation partners with Oregon State University to engage our community, inspire investment, and steward resources to enhance the university''s excellence and impact. VISION: To create a better world by inspiring support of - and for - Oregon State University.</MissionDesc>
<SignificantNewProgramSrvcInd>0</SignificantNewProgramSrvcInd>
<SignificantChangeInd>0</SignificantChangeInd>
<ExpenseAmt>12674058</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>SCHOLARSHIPS & OTHER STUDENT SUPPORT: The OSU Foundation distributed these amounts, in accordance with donor intent, to the University in FY20 to support students through scholarships, fellowships, and other awards. Through the years, donors have created over 1,975 unique scholarship and fellowship funds of various types and amounts at the OSU Foundation. These funds help ensure that an OSU education is accessible to qualified students, regardless of economic circumstances, and allow the University to recruit and retain the best and brightest students from Oregon and beyond.</Desc>
<ProgSrvcAccomActy2Grp>
<ExpenseAmt>39071677</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>CAPITAL PROGRAMS: The OSU Foundation distributed these amounts, in accordance with donor intent, to the University, in FY20, to support the construction or renovation of campus facilities. Major projects in FY20 included: the Marine Studies Building in Newport, the Oregon Forest Science Complex, the Arts & Education Complex, renovations to: Merryfield Hall, President''s residence, Valley Football Center, P Wayne Valley Sports Performance Center, Reser Stadium, Gill Colosseum, and the softball complex.</Desc>
</ProgSrvcAccomActy2Grp>
<ProgSrvcAccomActy3Grp>
<ExpenseAmt>17167254</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>INSTRUCTION AND RESEARCH: The OSU Foundation distributed these amounts, in accordance with donor intent, to the University, in FY20, to support teaching and research. With 150 endowed faculty positions at the University, donors to the OSU Foundation provide critically needed private funds to help recruit and retain world-class talent in the classrooms and labs. During the year, Foundation funds helped support OSU''s internationally recognized programs in marine sciences, forestry, and agricultural sciences, among others.</Desc>
</ProgSrvcAccomActy3Grp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>4888</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Accounting services</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>31223</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Advertising/Promotion</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>290774</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Books, Periodicals & Subscriptions</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>750</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Capital Outlay</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>123611</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>472080</RevenueAmt>
<Desc>Conferences, Meetings and Seminars</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>541970</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Donor Cultivation/Stewardship</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>19971</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>87480</RevenueAmt>
<Desc>Dues and Memberships</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>338351</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Equipment</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>158235</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Information Technology</Desc>
</ProgSrvcAccomActyOtherGrp>
<ProgSrvcAccomActyOtherGrp>
<ExpenseAmt>594951</ExpenseAmt>
<GrantAmt>0</GrantAmt>
<RevenueAmt>0</RevenueAmt>
<Desc>Insurance</Desc>
</ProgSrvcAccomActyOtherGrp>
</IRS990>
</ReturnData>
</Return>');
WITH XMLNAMESPACES (DEFAULT 'http://www.irs.gov/efile')
SELECT ID
, ProgSrvcAccomActyOtherGrp = c.value('(ProgSrvcAccomActyOtherGrp/text())[1]', 'BIGINT')
FROM #tbl
CROSS APPLY XMLData.nodes('/Return/ReturnData/IRS990') AS t(c);
Omitting your XML blob, take a look at this:
WITH XMLNAMESPACES (DEFAULT 'http://www.irs.gov/efile')
SELECT c.query('.')
FROM #tbl
CROSS APPLY XMLData.nodes('/Return/ReturnData/IRS990/ProgSrvcAccomActyOtherGrp') AS t(c);
That gets all of the ProgSrvcAccomActyOtherGrp nodes out of the XML. If I'm understanding what you're describing as the next step, SQL isn't really set up for that. That is, it sounds like you're describing a result set with an unknown number of columns (i.e. you want N columns per ProgSrvcAccomActyOtherGrp node, but the number of nodes is unknown a priori). Search for "dynamic pivot" and buckle up.
Changing the number of the element worked! Thank you always learning!
CREATE VIEW VanHalen6AAA
AS
WITH XMLNAMESPACES (DEFAULT 'http://www.irs.gov/efile')
SELECT ID, FilingYear, FilingPeriod, FilingType, [FileName]
, ProgSrvcAccomActy3GrpExpenseAmt1 = c2.value('(//ExpenseAmt/text())[1]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt1 = c2.value('(//GrantAmt/text())[1]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt1 = c2.value('(//RevenueAmt/text())[1]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc1 = c2.value('(//Desc/text())[1]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt2 = c2.value('(//ExpenseAmt/text())[2]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt2 = c2.value('(//GrantAmt/text())[2]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt2 = c2.value('(//RevenueAmt/text())[2]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc2 = c2.value('(//Desc/text())[2]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt3 = c2.value('(//ExpenseAmt/text())[3]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt3 = c2.value('(//GrantAmt/text())[3]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt3 = c2.value('(//RevenueAmt/text())[3]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc3 = c2.value('(//Desc/text())[3]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt4 = c2.value('(//ExpenseAmt/text())[4]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt4 = c2.value('(//GrantAmt/text())[4]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt4 = c2.value('(//RevenueAmt/text())[4]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc4 = c2.value('(//Desc/text())[4]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt5 = c2.value('(//ExpenseAmt/text())[5]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt5 = c2.value('(//GrantAmt/text())[5]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt5 = c2.value('(//RevenueAmt/text())[5]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc5 = c2.value('(//Desc/text())[5]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt6 = c2.value('(//ExpenseAmt/text())[6]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt6 = c2.value('(//GrantAmt/text())[6]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt6 = c2.value('(//RevenueAmt/text())[6]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc6 = c2.value('(//Desc/text())[6]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt7 = c2.value('(//ExpenseAmt/text())[7]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt7 = c2.value('(//GrantAmt/text())[7]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt7 = c2.value('(//RevenueAmt/text())[7]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc7 = c2.value('(//Desc/text())[7]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt8 = c2.value('(//ExpenseAmt/text())[8]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt8 = c2.value('(//GrantAmt/text())[8]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt8 = c2.value('(//RevenueAmt/text())[8]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc8 = c2.value('(//Desc/text())[8]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt9 = c2.value('(//ExpenseAmt/text())[9]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt9 = c2.value('(//GrantAmt/text())[9]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt9 = c2.value('(//RevenueAmt/text())[9]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc9 = c2.value('(//Desc/text())[9]','varchar(MAX)')
, ProgSrvcAccomActy3GrpExpenseAmt10 = c2.value('(//ExpenseAmt/text())[10]','varchar(MAX)')
, ProgSrvcAccomActy3GrpGrantAmt10 = c2.value('(//GrantAmt/text())[10]','varchar(MAX)')
, ProgSrvcAccomActy3GrpRevenueAmt10 = c2.value('(//RevenueAmt/text())[10]','varchar(MAX)')
, ProgSrvcAccomActy3GrpDesc10 = c2.value('(//Desc/text())[10]','varchar(MAX)')
FROM Form990
CROSS APPLY XMLData.nodes('/Return') AS t(c)
CROSS APPLY XMLData.nodes('//Return//ReturnData//IRS990//ProgSrvcAccomActy3Grp') AS t2(c2);

Bybit API - How do I calculate qty in USDT Perpetual with leverage

I'm using bybit-api to create a conditional order but don't know how do I calculate quantity. Is it based on leveraged amount or original?
for example
I have balance of 50 USDT and want to use 100% per trade with following conditions.
BTC at price 44,089.50 with 50x leverage.
SHIB at price 0.030810 with 50x leverage.
How do I calculate the qty parameter?
https://bybit-exchange.github.io/docs/linear/#t-placecond
I trade Bitcoin through USDT Perpetuals (BTCUSDT). I've setup my own python API and created my own function to calculate quantity for cross margin:
def order_quantity(self, price:float, currency:str='USDT', leverage:float=50.0):
margin = self.get_wallet_balance(currency)
instrument = Instrument(self.query_instrument()[0], 'bybit')
if not price: # Market orders
last_trade = self.ws_get_last_trade() # private function to get last trade
lastprice = float(last_trade[-1]['price'])
else: # Limit orders
lastprice = price
totalbtc = float(margin[currency]['available_balance']) * (1 - instrument.maker_fee * leverage)
rawbtc = totalbtc / lastprice
btc = math.floor(rawbtc / instrument.lot_size) * instrument.lot_size
return min(btc,instrument.max_lot_size)
It is based on the leverage amount.
Your quantity should be :
qty = 50 USDT * 50 (leverage) / 44089 (BTC price) = 0.0567 BTC

How to get a list of Coinbase CryptoCurrency Coins

I've been trying to figure out a way to get a list of all the Coins that Coinbase has listed (not necessarily for trade) but can't figure it out, in the early days it was easy as you could just login and see the list of 4 basic coins that were supported (and could hard code those values in a program and/or script).
But now they have a list of many coins listed, some as I understand, which are not available to actually trade but are listed for educational purposes (as stated on their site when looking at such coins).
I was wondering if anyone has figured out a way to get a list those coins (all supported and simply listed) perhaps with a tag of which are actually supported for trade.
I looked at the API and the REST API (using a simple GET request over HTTPS or using cURL for testing) has the following endpoints:
curl https://api.coinbase.com/v2/currencies - This lists all the Fiat currencies.
and:
curl https://api.pro.coinbase.com/products - This lists all the supported trading pairs (which is not what I'm looking for....)
Any ideas, short of logging in and parsing the html? (which could break since the site can be reformatted etc at any time).
Any help would be greatly appreciated!
perhaps not really what you asked, but you could also use https://api.pro.coinbase.com/currencies
import requests
import json
uri = 'https://api.pro.coinbase.com/currencies'
response = requests.get(uri).json()
for i in range(len(response)):
if response[i]['details']['type'] == 'crypto':
print(response[i]['id])
This will return the coins available for trading.
I'm not sure if I this is the response that you want or not. I first used the first URL that you have listed... The response from that looked like it didn't have the available coins. I then tried the below URL instead and the response does have a lot of curriencies listed on it. You can parse it by loading with JSON and looking for the fields that you want.
Also I didn't see a language posted with your question. I'm using python3 below. If you're a Linux person you can also just use curl GET from the command line. It doesn't matter the language... you just need to make a GET request to that URL and parse the response however you see fit.
To get 1 particular field you can use a line like response['data']['rates']['BTC'] to extract '0.00029200' out of the response/JSON string.
>>> r = requests.get("https://api.coinbase.com/v2/exchange-rates")
>>> response = json.loads(r.text)
>>> pprint.pprint(response)
{'data': {'currency': 'USD',
'rates': {'AED': '3.67',
'AFN': '75.22',
'ALL': '108.84',
'AMD': '487.59',
'ANG': '1.79',
'AOA': '311.37',
'ARS': '37.32',
'AUD': '1.38',
'AWG': '1.80',
'AZN': '1.70',
'BAM': '1.71',
'BAT': '9.00418244',
'BBD': '2.00',
'BCH': '0.00879160',
'BDT': '83.80',
'BGN': '1.71',
'BHD': '0.377',
'BIF': '1824',
'BMD': '1.00',
'BND': '1.58',
'BOB': '6.90',
'BRL': '3.65',
'BSD': '1.00',
'BTC': '0.00029200',
'BTN': '71.11',
'BWP': '10.41',
'BYN': '2.15',
'BYR': '21495',
'BZD': '2.02',
'CAD': '1.31',
'CDF': '1631.00',
'CHF': '0.99',
'CLF': '0.0242',
'CLP': '656',
'CNH': '6.71',
'CNY': '6.70',
'COP': '3174.95',
'CRC': '608.98',
'CUC': '1.00',
'CVE': '96.90',
'CZK': '22.50',
'DJF': '178',
'DKK': '6.52',
'DOP': '50.44',
'DZD': '118.30',
'EEK': '14.61',
'EGP': '17.68',
'ERN': '15.00',
'ETB': '28.52',
'ETC': '0.25542784',
'ETH': '0.00944599',
'EUR': '0.87',
'FJD': '2.10',
'FKP': '0.76',
'GBP': '0.76',
'GEL': '2.66',
'GGP': '0.76',
'GHS': '4.98',
'GIP': '0.76',
'GMD': '49.52',
'GNF': '9210',
'GTQ': '7.74',
'GYD': '208.55',
'HKD': '7.85',
'HNL': '24.49',
'HRK': '6.49',
'HTG': '78.37',
'HUF': '276',
'IDR': '13940.00',
'ILS': '3.63',
'IMP': '0.76',
'INR': '70.93',
'IQD': '1190.000',
'ISK': '120',
'JEP': '0.76',
'JMD': '132.72',
'JOD': '0.710',
'JPY': '109',
'KES': '100.60',
'KGS': '68.70',
'KHR': '4015.00',
'KMF': '429',
'KRW': '1114',
'KWD': '0.303',
'KYD': '0.83',
'KZT': '380.63',
'LAK': '8559.50',
'LBP': '1511.15',
'LKR': '178.40',
'LRD': '160.75',
'LSL': '13.53',
'LTC': '0.03208728',
'LTL': '3.22',
'LVL': '0.66',
'LYD': '1.385',
'MAD': '9.53',
'MDL': '17.05',
'MGA': '3465.0',
'MKD': '53.78',
'MMK': '1519.04',
'MNT': '2453.75',
'MOP': '8.08',
'MRO': '357.0',
'MTL': '0.68',
'MUR': '34.23',
'MVR': '15.49',
'MWK': '728.47',
'MXN': '19.14',
'MYR': '4.10',
'MZN': '61.87',
'NAD': '13.53',
'NGN': '361.50',
'NIO': '32.60',
'NOK': '8.43',
'NPR': '113.78',
'NZD': '1.45',
'OMR': '0.385',
'PAB': '1.00',
'PEN': '3.33',
'PGK': '3.36',
'PHP': '52.13',
'PKR': '139.30',
'PLN': '3.73',
'PYG': '6084',
'QAR': '3.64',
'RON': '4.14',
'RSD': '103.53',
'RUB': '65.47',
'RWF': '886',
'SAR': '3.75',
'SBD': '8.06',
'SCR': '13.67',
'SEK': '9.05',
'SGD': '1.35',
'SHP': '0.76',
'SLL': '8390.00',
'SOS': '582.00',
'SRD': '7.46',
'SSP': '130.26',
'STD': '21050.60',
'SVC': '8.75',
'SZL': '13.52',
'THB': '31.23',
'TJS': '9.43',
'TMT': '3.50',
'TND': '2.968',
'TOP': '2.26',
'TRY': '5.18',
'TTD': '6.77',
'TWD': '30.72',
'TZS': '2317.00',
'UAH': '27.70',
'UGX': '3670',
'USD': '1.00',
'USDC': '1.000000',
'UYU': '32.58',
'UZS': '8380.00',
'VEF': '248487.64',
'VND': '23287',
'VUV': '111',
'WST': '2.60',
'XAF': '573',
'XAG': '0',
'XAU': '0',
'XCD': '2.70',
'XDR': '1',
'XOF': '573',
'XPD': '0',
'XPF': '104',
'XPT': '0',
'YER': '250.30',
'ZAR': '13.27',
'ZEC': '0.02056344',
'ZMK': '5253.08',
'ZMW': '11.94',
'ZRX': '4.04721481',
'ZWL': '322.36'}}}
The following code:
import requests
uri = 'https://api.pro.coinbase.com/currencies'
response = requests.get(uri).json()
for i in range(len(response)):
if response[i]['details']['type'] == 'crypto':
print(response[i]['id'])
Will provide this output:
COTI
BTC
ETH
LTC
BCH
ZEC
XTZ
XRP
XLM
EOS
ALGO
DASH
ATOM
CGLD
FIL
ADA
ICP
SOL
DOT
DOGE
OXT
KNC
MIR
REP
COMP
NMR
ACH
BAND
ZRX
BAT
LOOM
UNI
YFI
LRC
CVC
DNT
MANA
GNT
REN
LINK
BAL
ETC
USDC
RLC
DAI
WBTC
NU
AAVE
SNX
BNT
GRT
SUSHI
MLN
ANKR
CRV
STORJ
SKL
AMP
1INCH
ENJ
NKN
OGN
FORTH
GTC
TRB
CTSI
MKR
UMA
USDT
CHZ
SHIB
BOND
LPT
QNT
KEEP
CLV
MASK
MATIC
OMG
POLY
FARM
FET
PAX
RLY
PLA
RAI
IOTX
ORN
AXS
QUICK
TRIBE
UST
REQ
TRU
WLUNA
you can use
curl -X GET https://api.exchange.coinbase.com/products
refer to
https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts

Resources